Submission #344665

#TimeUsernameProblemLanguageResultExecution timeMemory
344665mansurShymbulak (IZhO14_shymbulak)C++14
30 / 100
322 ms4972 KiB
#include<bits/stdc++.h> using namespace std; #define all(a) a.begin(),a.end() #define ll long long #define pb push_back #define nl '\n' #define popb pop_back() #define sz size() #define ld long double #define ull unsigned long long #define F first #define S second #define fix fixed<<setprecision #define pii pair<int,int> #define E exit (0) #define int long long const int inf=1e9; int c[501][501],cnt; vector<pii>adj[501]; map<int,bool>was; void dfs(int u,int z,int mx,int t=0) { was[u]=1; if (t>mx) { was[u]=0; return; } if (u==z) { cnt++; was[u]=0; return; } for (auto e:adj[u]) { if (was[e.F]) { continue; } dfs(e.F,z,mx,t+1); } was[u]=0; return; } signed main() { //freopen("planting.in","r",stdin); //freopen("planting.out","w",stdout); ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin>>n; for (int i=1;i<=n;i++) { for (int j=1;j<=n;j++) { c[i][j]=inf; } } for (int i=1;i<=n;i++) { c[i][i]=0; int a,b; cin>>a>>b; c[a][b]=c[b][a]=1; adj[a].pb({b,i}); adj[b].pb({a,i}); } for (int k=1;k<=n;k++) { for (int i=1;i<=n;i++) { for (int j=1;j<=n;j++) { c[i][j]=min(c[i][j],c[i][k]+c[k][j]); } } } int mx=0; vector<pii>s; for (int i=1;i<=n;i++) { for (int j=1;j<=n;j++) { if (mx==c[i][j]) { s.pb({i,j}); } if (mx<c[i][j]) { mx=c[i][j]; s.clear(); s.pb({i,j}); } } } int ans=0,i=0; for (auto e:s) { dfs(e.F,e.S,mx); ans+=cnt; for (int i=1;i<=500;i++) { was[i]=0; } cnt=0; i++; } cout<<ans/2; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...