Submission #2582139
Source Code Expand
#include <bits/stdc++.h> using namespace std; #define mod 1000000007 int n; vector< vector<int> > v; vector<long long> f, g; vector<bool> used; long long dfs(int p){ g[p] = 1; f[p] = 1; used[p] = true; for (int i = 0; i < v[p].size(); i++) { if (used[v[p][i]]) continue; dfs(v[p][i]); g[p] *= f[v[p][i]]; f[p] *= g[v[p][i]]; f[p] %= mod; g[p] %= mod; } f[p] += g[p]; f[p] %= mod; return f[p]; } int main(){ cin >> n; v.resize(n+1); f.resize(n+1); g.resize(n+1); used.resize(n+1, false); for (int i = 0; i < n-1; i++) { int a, b; cin >> a >> b; v[a].push_back(b); v[b].push_back(a); } cout << dfs(1) << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - 塗り絵 |
User | potoooooooo |
Language | C++14 (GCC 5.4.1) |
Score | 100 |
Code Size | 728 Byte |
Status | AC |
Exec Time | 103 ms |
Memory | 7296 KB |
Judge Result
Set Name | All | ||
---|---|---|---|
Score / Max Score | 100 / 100 | ||
Status |
|
Set Name | Test Cases |
---|---|
All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
000.txt | AC | 1 ms | 256 KB |
001.txt | AC | 1 ms | 256 KB |
002.txt | AC | 75 ms | 5760 KB |
003.txt | AC | 103 ms | 7296 KB |
004.txt | AC | 63 ms | 4992 KB |
005.txt | AC | 95 ms | 7296 KB |
006.txt | AC | 89 ms | 6784 KB |
007.txt | AC | 92 ms | 7296 KB |
008.txt | AC | 67 ms | 5248 KB |
009.txt | AC | 92 ms | 7296 KB |
010.txt | AC | 70 ms | 5376 KB |
011.txt | AC | 95 ms | 7296 KB |
012.txt | AC | 56 ms | 4480 KB |
013.txt | AC | 96 ms | 7296 KB |
014.txt | AC | 44 ms | 3584 KB |
015.txt | AC | 97 ms | 7296 KB |
016.txt | AC | 57 ms | 4608 KB |
017.txt | AC | 97 ms | 7296 KB |
018.txt | AC | 16 ms | 1536 KB |
019.txt | AC | 96 ms | 7296 KB |
020.txt | AC | 9 ms | 896 KB |
021.txt | AC | 96 ms | 7296 KB |