# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1012377 | 2024-07-02T05:01:27 Z | simona1230 | Star Trek (CEOI20_startrek) | C++17 | 1 ms | 4444 KB |
#include <bits/stdc++.h> using namespace std; const int mod=1e9+7; int n,d; vector<int> v[100001]; void read() { cin>>n>>d; for(int i=1;i<n;i++) { int x,y; cin>>x>>y; v[x].push_back(y); v[y].push_back(x); } } int num; int l[100001],w[100001]; void dfs1(int i,int p) { for(int j=0;j<v[i].size();j++) { int nb=v[i][j]; if(nb==p)continue; dfs1(nb,i); l[i]+=w[nb]^1; } if(l[i])w[i]=1; } int c[100001],sz[100001],up[100001]; void dfs2(int i,int p) { if(i!=1&&w[p]==0||w[p]==1&&l[p]==1&&!w[i])w[i]+=2; //cout<<i<<" "<<w[i]<<endl; if(w[i]==0)num++; for(int j=0;j<v[i].size();j++) { int nb=v[i][j]; if(nb==p)continue; dfs2(nb,i); if(l[i]==1&&w[nb]!=1||l[i]==0) sz[i]+=sz[nb]; } if(w[i]%2==0)sz[i]++; //cout<<i<<" "<<sz[i]<<endl; } void dfs3(int i,int p) { int add=up[p]+sz[p]; if(l[p]==1&&w[i]!=1||i!=1&&l[p]==0) add-=sz[i]; up[i]=add; c[i]=add+sz[i]; for(int j=0;j<v[i].size();j++) { int nb=v[i][j]; if(nb==p)continue; dfs3(nb,i); } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); read(); dfs1(1,0); dfs2(1,0); dfs3(1,0); cout<<(sz[1]*num)%mod<<endl; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 4444 KB | Output is correct |
2 | Incorrect | 1 ms | 4444 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 4444 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 4444 KB | Output is correct |
2 | Incorrect | 1 ms | 4444 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 4444 KB | Output is correct |
2 | Incorrect | 1 ms | 4444 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 4444 KB | Output is correct |
2 | Incorrect | 1 ms | 4444 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 4444 KB | Output is correct |
2 | Incorrect | 1 ms | 4444 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 4444 KB | Output is correct |
2 | Incorrect | 1 ms | 4444 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 4444 KB | Output is correct |
2 | Incorrect | 1 ms | 4444 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |