Submission #863221

#TimeUsernameProblemLanguageResultExecution timeMemory
863221Cyber_WolfCijanobakterije (COCI21_cijanobakterije)C++17
70 / 70
66 ms17612 KiB
#include <bits/stdc++.h> using namespace std; #define lg long long const lg N = 2e5+5; vector<lg> adj[N], path; lg dist[N], mxmnode, vis[N]; void dfs(lg src, lg par = -1, lg d = 1) { path.push_back(src); vis[src] = true; dist[src] = d; if(dist[src] > dist[mxmnode]) { mxmnode = src; } for(auto it : adj[src]) { if(it == par) continue; dfs(it, src, d+1); } return; } int main() { lg n, m; cin >> n >> m; for(int i = 0; i < m; i++) { lg u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } lg ans = 0; for(int i = 1; i <= n; i++) { if(vis[i]) continue; path.clear(); dfs(i, -1); for(auto it : path) dist[it] = 0; path.clear(); dfs(mxmnode, -1); ans += dist[mxmnode]; mxmnode = 0; } cout << ans << '\n'; }
#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...