# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
585659 | 2022-06-29T07:52:05 Z | 반딧불(#8385) | Star Trek (CEOI20_startrek) | C++17 | 2 ms | 2644 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD = 1000000007; ll mpow(ll x, ll y){ if(!y) return 1; if(y%2) return mpow(x, y-1) * x % MOD; ll tmp = mpow(x, y/2); return tmp*tmp%MOD; } int n; ll k; vector<int> link[100002]; int depth[100002]; int DP[100002]; int DProot[100002]; ll ans; void dfs(int x, int p=-1){ for(auto y: link[x]){ if(y==p) continue; depth[y] = depth[x] + 1; dfs(y, x); if(!DP[y]) DP[x] = 1; } } void dfs2(int x, int p=-1, bool winUp = 0){ DProot[x] = (DP[x] || winUp); int cnt = 0; for(auto y: link[x]) if(y!=p) cnt += !DP[y]; for(auto y: link[x]){ if(y==p) continue; dfs2(y, x, !winUp && !(cnt-!DP[y])); } } int dfsFind(int x, int p=-1){ if(depth[x] % 2 == 0){ /// my turn int cnt = 0; for(auto y: link[x]){ if(y!=p && !DP[y]) cnt++; } if(cnt > 1) return 0; assert(cnt == 1); for(auto y: link[x]){ if(y!=p && !DP[y]) return dfsFind(y, x); } } else{ int ret = 1; for(auto y: link[x]){ if(y==p) continue; ret += dfsFind(y, x); } return ret; } } int dfsFind2(int x, int p=-1){ if(depth[x] % 2 == 0){ /// my turn int ret = 1; for(auto y: link[x]){ if(y==p) continue; ret += dfsFind2(y, x); } return ret; } else{ /// your turn int cnt = 0; for(auto y: link[x]){ if(y!=p && !DP[y]) cnt++; } if(cnt > 1) return 0; assert(cnt == 1); for(auto y: link[x]){ if(y!=p && !DP[y]) return dfsFind2(y, x); } } } int main(){ scanf("%d %lld", &n, &k); for(int i=1; i<n; i++){ int x, y; scanf("%d %d", &x, &y); link[x].push_back(y); link[y].push_back(x); } dfs(1); dfs2(1); // for(int i=1; i<=n; i++) printf("%d ", DProot[i]); if(DP[1]){ /// ���������� �̱� �� ll W = 0; /// ? -> W for(int i=1; i<=n; i++) if(DProot[i]) W++; ans += W*n; ll myturn = 0; /// my turn -> L for(int i=1; i<=n; i++) if(depth[i] % 2 == 0) myturn++; ans += myturn * (n-W); ll tmp = n - W - dfsFind(1); ans += tmp * (n-W); } else{ /// ���������� �� �� ll L = 0; for(int i=1; i<=n; i++) if(!DProot[i]) L++; ans += L * dfsFind2(1); } printf("%lld", ans%MOD); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2644 KB | Output is correct |
2 | Incorrect | 2 ms | 2644 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 2644 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2644 KB | Output is correct |
2 | Incorrect | 2 ms | 2644 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2644 KB | Output is correct |
2 | Incorrect | 2 ms | 2644 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2644 KB | Output is correct |
2 | Incorrect | 2 ms | 2644 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2644 KB | Output is correct |
2 | Incorrect | 2 ms | 2644 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2644 KB | Output is correct |
2 | Incorrect | 2 ms | 2644 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2644 KB | Output is correct |
2 | Incorrect | 2 ms | 2644 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |