Submission #1089848

#TimeUsernameProblemLanguageResultExecution timeMemory
1089848toast12Cijanobakterije (COCI21_cijanobakterije)C++14
42 / 70
1047 ms7624 KiB
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; int n; vector<bool> visited; vector<vector<int>> adj; pair<int, int> diameter(int start) { vector<int> dist(n+1, INF); queue<int> q; q.push(start); vector<bool> v(n+1); dist[start] = 0; int a1 = 0, a2 = 0; while (!q.empty()) { int cur = q.front(); q.pop(); if (dist[cur] > a1) { a1 = dist[cur]; a2 = cur; } if (v[cur]) continue; visited[cur] = true; v[cur] = true; for (auto e : adj[cur]) { if (dist[cur]+1 < dist[e]) { dist[e] = dist[cur]+1; q.push(e); } } } return {a1, a2}; } int main() { int m; cin >> n >> m; adj.resize(n+1); for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } visited.resize(n+1); int ans = 0; for (int i = 1; i <= n; i++) { if (!visited[i]) { int x = diameter(i).second; ans += diameter(x).first; ans++; } } cout << ans << '\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...