Submission #520377

#TimeUsernameProblemLanguageResultExecution timeMemory
520377Alex_tz307Cijanobakterije (COCI21_cijanobakterije)C++17
70 / 70
50 ms13128 KiB
#include <bits/stdc++.h> using namespace std; const int kN = 1e5; vector<int> g[1 + kN]; bitset<1 + kN> vis; pair<int, int> dfs(int u, int par) { vis[u] = true; pair<int, int> best{0, u}; for (int v : g[u]) { if (v != par) { best = max(best, dfs(v, u)); } } best.first += 1; return best; } void testCase() { int n, m; cin >> n >> m; for (int i = 0; i < m; ++i) { int u, v; cin >> u >> v; g[u].emplace_back(v); g[v].emplace_back(u); } int ans = 0; for (int i = 1; i <= n; ++i) { if (!vis[i]) { pair<int, int> root = dfs(i, 0); root = dfs(root.second, 0); ans += root.first; } } cout << ans << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int tests = 1; for (int tc = 0; tc < tests; ++tc) { testCase(); } 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...