Submission #163199

#TimeUsernameProblemLanguageResultExecution timeMemory
163199TadijaSebez전압 (JOI14_voltage)C++11
100 / 100
156 ms14072 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back const int N=100050; vector<int> E[N]; int even[N],odd[N],dep[N],all_odd; bool was[N]; void DFS(int u) { was[u]=1; int p=1; for(int v:E[u]) { if(!was[v]) { dep[v]=dep[u]+1; DFS(v); } else if(dep[u]>dep[v]) { if(dep[u]==dep[v]+1 && p) p--; else { if((dep[u]-dep[v])%2==0) odd[u]++,odd[v]--,all_odd++; else even[u]++,even[v]--; } } } } void SubTree(int u) { was[u]=1; for(int v:E[u]) { if(!was[v]) { SubTree(v); odd[u]+=odd[v]; even[u]+=even[v]; } } } int main() { int n,m; scanf("%i %i",&n,&m); for(int i=1,u,v;i<=m;i++) scanf("%i %i",&u,&v),E[u].pb(v),E[v].pb(u); for(int i=1;i<=n;i++) if(!was[i]) DFS(i); for(int i=1;i<=n;i++) was[i]=0; for(int i=1;i<=n;i++) if(!was[i]) SubTree(i); int ans=0; for(int i=1;i<=n;i++) if(dep[i]!=0 && odd[i]==all_odd && even[i]==0) ans++; if(all_odd==1) ans++; printf("%i\n",ans); return 0; }

Compilation message (stderr)

voltage.cpp: In function 'int main()':
voltage.cpp:46:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i %i",&n,&m);
  ~~~~~^~~~~~~~~~~~~~~
voltage.cpp:47:59: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1,u,v;i<=m;i++) scanf("%i %i",&u,&v),E[u].pb(v),E[v].pb(u);
                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...