Submission #1520797
Source Code Expand
#include<iostream> #include<iomanip> #include<math.h> #include<vector> #include<algorithm> #include<set> #include<map> #include<queue> #include<stack> #include<string> #include<complex> #include<unordered_map> #define INF 1000000000ll #define MOD 1000000007ll #define EPS 1e-8 #define REP(i, m) for(long long i = 0; i < m; ++i) #define FOR(i, n, m) for(long long i = n; i < m; ++i) #define ALL(v) v.begin(), v.end() #define pb push_back using namespace std; typedef long long ll; typedef pair<ll, ll> P; typedef long double ld; vector<vector<int> > adj; vector<vector<ll> > memo; ll dfs(int pos, int c, int b) { if(memo[pos][c]!=INF*INF) return memo[pos][c]; ll res=1; REP(i,adj[pos].size()) { if(adj[pos][i]!=b) { if(c==0) res*=dfs(adj[pos][i],0,pos)+dfs(adj[pos][i],1,pos); else res*=dfs(adj[pos][i],0,pos); res%=MOD; } } return memo[pos][c]=res%MOD; } int main() { int n; cin>>n; adj.resize(n); memo.resize(n); REP(i,n) { memo[i].resize(2); REP(j,2) memo[i][j]=INF*INF; } REP(i,n-1) { int a,b; cin>>a>>b; --a; --b; adj[a].pb(b); adj[b].pb(a); } cout<<dfs(0,0,-1)+dfs(0,1,-1)<<endl; }
Submission Info
Submission Time | |
---|---|
Task | D - 塗り絵 |
User | gazelle |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1196 Byte |
Status | WA |
Exec Time | 110 ms |
Memory | 11264 KB |
Judge Result
Set Name | All | ||||
---|---|---|---|---|---|
Score / Max Score | 0 / 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 | 80 ms | 8832 KB |
003.txt | WA | 101 ms | 11264 KB |
004.txt | AC | 67 ms | 7552 KB |
005.txt | AC | 102 ms | 11264 KB |
006.txt | AC | 94 ms | 10368 KB |
007.txt | AC | 110 ms | 11264 KB |
008.txt | AC | 71 ms | 8064 KB |
009.txt | WA | 105 ms | 11264 KB |
010.txt | AC | 72 ms | 8192 KB |
011.txt | WA | 103 ms | 11264 KB |
012.txt | WA | 59 ms | 6784 KB |
013.txt | AC | 103 ms | 11264 KB |
014.txt | WA | 46 ms | 5376 KB |
015.txt | WA | 102 ms | 11264 KB |
016.txt | WA | 61 ms | 7040 KB |
017.txt | WA | 101 ms | 11264 KB |
018.txt | AC | 17 ms | 2176 KB |
019.txt | AC | 100 ms | 11264 KB |
020.txt | AC | 10 ms | 1280 KB |
021.txt | AC | 100 ms | 11264 KB |