Submission #528359

#TimeUsernameProblemLanguageResultExecution timeMemory
528359CSQ31Cijanobakterije (COCI21_cijanobakterije)C++17
70 / 70
88 ms13220 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5+1; vector<int>adj[MAXN]; bool vis[MAXN]; int d = 0; int dfs(int v,int u){ vis[v] = 1; int d1 = 0,d2 = 0; for(int x:adj[v]){ if(x==u)continue; int res = dfs(x,v)+1; if(res >= d1){ d2 = d1; d1 = res; }else if(res > d2)d2 = res; } d = max(d,d1+d2); return d1; } int main() { int n,m; cin>>n>>m; for(int i=0;i<m;i++){ int a,b; cin>>a>>b; adj[a].push_back(b); adj[b].push_back(a); } int ans = 0; for(int i=1;i<=n;i++){ if(!vis[i]){ d = 0; dfs(i,0); ans+=d+1; //cout<<i<<" "<<d<<'\n'; } } cout<<ans; }
#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...