Submission #577777

#TimeUsernameProblemLanguageResultExecution timeMemory
577777juggernautStar Trek (CEOI20_startrek)C++14
0 / 100
2 ms2644 KiB
#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); } bool up[100005]; void chk(int v,int p){ if(p){ up[v]=true; if(up[p]&&dp[p]>0&&dp[p]==-dp[v])up[v]=false; if(dp[v]<0&&!up[v])losers++; }else{ if(dp[v]<0)losers++; up[v]=false; } for(int to:g[v])if(to^p)chk(to,v); } 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); chk(1,0); go(1,0,1); ans%=mod; printf("%lld",ans); }

Compilation message (stderr)

startrek.cpp: In function 'int main()':
startrek.cpp:59:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |  scanf("%d%lld",&n,&d);
      |  ~~~~~^~~~~~~~~~~~~~~~
startrek.cpp:62:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |   scanf("%d%d",&x,&y);
      |   ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...