# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
171016 | juggernaut | 관광지 (IZhO14_shymbulak) | C++14 | 874 ms | 1016 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Just try and the idea will come!
#include<bits/stdc++.h>
#define int long long int
using namespace std;
vector<vector<int>>g(5001);
int a[5001],n,x,y,i,j,mx,cnt,b[5001];
main(){
scanf("%lld",&n);
for(i=0;i<n;i++){
scanf("%lld%lld",&x,&y);
g[x].push_back(y);
g[y].push_back(x);
}
for(i=1;i<=n;i++){
queue<int>q;
q.push(i);
for(j=1;j<=n;j++)a[j]=1e15,b[j]=0;
b[i]=1;
a[i]=0;
while(!q.empty()){
x=q.front();
q.pop();
for(int to:g[x])
if(a[to]>a[x]+1){
b[to]+=b[x];
a[to]=a[x]+1;
q.push(to);
}else if(a[to]==a[x]+1)b[to]+=b[x];
}
for(j=1;j<=n;j++)
if(a[j]>mx){
mx=a[j];
cnt=b[j];
}else if(mx==a[j])cnt+=b[j];
}
printf("%lld",(cnt>>1));
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |