# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
647076 | 2022-10-01T14:23:41 Z | Alma | Cijanobakterije (COCI21_cijanobakterije) | C++14 | 50 ms | 7500 KB |
#include <bits/stdc++.h> using namespace std; #define fi first #define se second using ll = long long; using ii = pair<int,int>; const int INF = 1e9; const ll LLINF = 1e18; using vi = vector<int>; using vvi = vector<vi>; void setIO (string fileName) { ios::sync_with_stdio(false); cin.tie(NULL); if (fileName != "std") { freopen((fileName + ".in").c_str(), "r", stdin); freopen((fileName + ".out").c_str(), "w", stdout); } } int treeDiameter (vvi& adj, vi& vis, int idx) { int last = idx, dist = 1; queue<ii> bfs; bfs.push({idx, -1}); while (!bfs.empty()) { int u = bfs.front().fi; int p = bfs.front().se; bfs.pop(); last = u; for (int v: adj[u]) { if (v != p) bfs.push({v, u}); } } bfs.push({last, 1}); while (!bfs.empty()) { int u = bfs.front().fi; int d = bfs.front().se; bfs.pop(); dist = d; vis[u] = true; for (int v: adj[u]) { if (!vis[v]) bfs.push({v, d+1}); } } return dist; } int main() { setIO("std"); int n, m, u, v; cin >> n >> m; vvi adj(n); vi vis(n, false); while (m--) { cin >> u >> v; u--; v--; adj[u].push_back(v); adj[v].push_back(u); } int ans = 0; for (int i = 0; i < n; i++) { if (!vis[i]) { ans += treeDiameter(adj, vis, i); } } cout << ans << '\n'; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 1492 KB | Output is correct |
2 | Correct | 15 ms | 2700 KB | Output is correct |
3 | Correct | 20 ms | 3924 KB | Output is correct |
4 | Correct | 27 ms | 5100 KB | Output is correct |
5 | Correct | 40 ms | 6348 KB | Output is correct |
6 | Correct | 38 ms | 7500 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 32 ms | 7268 KB | Output is correct |
2 | Correct | 4 ms | 1228 KB | Output is correct |
3 | Correct | 10 ms | 2172 KB | Output is correct |
4 | Correct | 11 ms | 3156 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 320 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 4 ms | 1404 KB | Output is correct |
6 | Correct | 8 ms | 2636 KB | Output is correct |
7 | Correct | 12 ms | 3836 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 320 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 320 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 1 ms | 340 KB | Output is correct |
8 | Correct | 1 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 340 KB | Output is correct |
11 | Correct | 1 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 1492 KB | Output is correct |
2 | Correct | 15 ms | 2700 KB | Output is correct |
3 | Correct | 20 ms | 3924 KB | Output is correct |
4 | Correct | 27 ms | 5100 KB | Output is correct |
5 | Correct | 40 ms | 6348 KB | Output is correct |
6 | Correct | 38 ms | 7500 KB | Output is correct |
7 | Correct | 32 ms | 7268 KB | Output is correct |
8 | Correct | 4 ms | 1228 KB | Output is correct |
9 | Correct | 10 ms | 2172 KB | Output is correct |
10 | Correct | 11 ms | 3156 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 212 KB | Output is correct |
13 | Correct | 1 ms | 320 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 4 ms | 1404 KB | Output is correct |
16 | Correct | 8 ms | 2636 KB | Output is correct |
17 | Correct | 12 ms | 3836 KB | Output is correct |
18 | Correct | 1 ms | 320 KB | Output is correct |
19 | Correct | 1 ms | 340 KB | Output is correct |
20 | Correct | 1 ms | 320 KB | Output is correct |
21 | Correct | 1 ms | 340 KB | Output is correct |
22 | Correct | 1 ms | 340 KB | Output is correct |
23 | Correct | 1 ms | 340 KB | Output is correct |
24 | Correct | 1 ms | 340 KB | Output is correct |
25 | Correct | 1 ms | 340 KB | Output is correct |
26 | Correct | 1 ms | 340 KB | Output is correct |
27 | Correct | 1 ms | 340 KB | Output is correct |
28 | Correct | 1 ms | 340 KB | Output is correct |
29 | Correct | 50 ms | 7448 KB | Output is correct |
30 | Correct | 18 ms | 4052 KB | Output is correct |
31 | Correct | 35 ms | 6932 KB | Output is correct |
32 | Correct | 26 ms | 4936 KB | Output is correct |
33 | Correct | 44 ms | 7244 KB | Output is correct |
34 | Correct | 25 ms | 5568 KB | Output is correct |
35 | Correct | 35 ms | 7048 KB | Output is correct |
36 | Correct | 37 ms | 6088 KB | Output is correct |
37 | Correct | 46 ms | 7120 KB | Output is correct |
38 | Correct | 46 ms | 6668 KB | Output is correct |
39 | Correct | 34 ms | 6988 KB | Output is correct |