Submission #880160

#TimeUsernameProblemLanguageResultExecution timeMemory
880160JoksimKaktusCijanobakterije (COCI21_cijanobakterije)C++17
70 / 70
30 ms10440 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; void output(bool yes){yes ? cout << "Yes" << "\n" : cout << "No" << "\n";} vector <int> adj[100005]; int point = 1; int maxi = 1; vector <bool> vis(100005); void dfs(int i,int p,int cur){ vis[i]=true; if(cur > maxi){ maxi = cur; point = i; } for(int j : adj[i]){ if(j != p){ dfs(j,i,cur+1); } } } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); int n,m; cin >> n >> m; for(int i = 0;i < m;i++){ int u,v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } int res = 0; for(int i = 1;i <= n;i++){ if(!vis[i]){ point = i; dfs(i,-1,1); dfs(point,-1,1); res += maxi; maxi = 1; } } cout << res << "\n"; return 0; }
#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...