Submission #580478

#TimeUsernameProblemLanguageResultExecution timeMemory
580478yutabiShymbulak (IZhO14_shymbulak)C++14
50 / 100
1592 ms8232 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back typedef long long ll; typedef pair <ll,ll> ii; int ans; int best=-1; int n; vector <vector <int> > graph; queue <int> q; vector <int> d; vector <int> c; vector <bool> v; int main() { scanf("%d",&n); graph=vector <vector <int> > (n); for(int i=0;i<n;i++) { int a,b; scanf(" %d %d",&a,&b); a--,b--; graph[a].pb(b); graph[b].pb(a); } for(int i=0;i<n;i++) { d=vector <int> (n,-1); c=vector <int> (n,0); v=vector <bool> (n,0); d[i]=0; c[i]=1; q.push(i); while(q.size()) { int a=q.front(); q.pop(); if(v[a]==1) { continue; } v[a]=1; if(d[a]>best) { best=d[a]; ans=0; } if(d[a]==best) { ans+=c[a]; } for(int j=0;j<graph[a].size();j++) { if(v[graph[a][j]]==0) { q.push(graph[a][j]); if(d[graph[a][j]]>d[a]+1 || d[graph[a][j]]==-1) { d[graph[a][j]]=d[a]+1; c[graph[a][j]]=0;; } if(d[graph[a][j]]==d[a]+1) { c[graph[a][j]]+=c[a]; } } } } } ans/=2; printf("%d",ans); }

Compilation message (stderr)

shymbulak.cpp: In function 'int main()':
shymbulak.cpp:76:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |             for(int j=0;j<graph[a].size();j++)
      |                         ~^~~~~~~~~~~~~~~~
shymbulak.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
shymbulak.cpp:35:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |         scanf(" %d %d",&a,&b);
      |         ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...