# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
577740 | 2022-06-15T08:29:54 Z | temporary_juggernaut | Star Trek (CEOI20_startrek) | C++14 | 3 ms | 2644 KB |
#include<bits/stdc++.h> #define fr first #define sc second using namespace std; typedef long long ll; typedef long double ld; #define USING_ORDERED_SET 0 #if USING_ORDERED_SET #include<bits/extc++.h> using namespace __gnu_pbds; template<class T>using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; #endif template<class T>void umax(T &a,T b){if(a<b)a=b;} template<class T>void umin(T &a,T b){if(b<a)a=b;} #ifdef juggernaut #define printl(args...) printf(args) #else #define printl(args...) 0 #endif int n; ll d; vector<int>g[100005]; ll dp[100005]; void dfs(int v,int p){ ll carry=0; for(int to:g[v])if(to^p){ dfs(to,v); if(dp[to]<0)dp[v]-=dp[to]; else carry-=dp[to]; } if(!dp[v])dp[v]=carry; if(!dp[v])dp[v]--; } ll mod=1e9+7; ll ans; ll losers; void go(int v,int p,bool depth){ if(depth){ if(dp[v]>0)ans+=n; else ans+=losers; }else{ if(dp[v]<0)ans+=(n-losers); } for(int to:g[v])if(to^p)go(to,v,depth^1); } int main(){ scanf("%d%lld",&n,&d); for(int i=1;i<n;i++){ int x,y; scanf("%d%d",&x,&y); g[x].push_back(y); g[y].push_back(x); } dfs(1,0); for(int i=1;i<=n;i++)if(dp[i]<0)losers++; go(1,0,1); ans%=mod; printf("%lld",ans); }
Compilation message
# | Verdict | Execution time | Memory | 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 | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 2644 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2644 KB | Output is correct |
2 | Incorrect | 3 ms | 2644 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2644 KB | Output is correct |
2 | Incorrect | 3 ms | 2644 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2644 KB | Output is correct |
2 | Incorrect | 3 ms | 2644 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2644 KB | Output is correct |
2 | Incorrect | 3 ms | 2644 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2644 KB | Output is correct |
2 | Incorrect | 3 ms | 2644 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | 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 | - |