Submission #520377

# Submission time Handle Problem Language Result Execution time Memory
520377 2022-01-29T18:08:37 Z Alex_tz307 Cijanobakterije (COCI21_cijanobakterije) C++17
70 / 70
50 ms 13128 KB
#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 time Memory Grader output
1 Correct 7 ms 3276 KB Output is correct
2 Correct 12 ms 4044 KB Output is correct
3 Correct 17 ms 4812 KB Output is correct
4 Correct 26 ms 5536 KB Output is correct
5 Correct 31 ms 6268 KB Output is correct
6 Correct 45 ms 7020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 13128 KB Output is correct
2 Correct 4 ms 3148 KB Output is correct
3 Correct 6 ms 3592 KB Output is correct
4 Correct 9 ms 4044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 5 ms 3276 KB Output is correct
6 Correct 7 ms 3824 KB Output is correct
7 Correct 10 ms 4484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 1 ms 2636 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 2 ms 2636 KB Output is correct
5 Correct 2 ms 2636 KB Output is correct
6 Correct 2 ms 2664 KB Output is correct
7 Correct 2 ms 2636 KB Output is correct
8 Correct 3 ms 2636 KB Output is correct
9 Correct 2 ms 2672 KB Output is correct
10 Correct 3 ms 2668 KB Output is correct
11 Correct 2 ms 2668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 3276 KB Output is correct
2 Correct 12 ms 4044 KB Output is correct
3 Correct 17 ms 4812 KB Output is correct
4 Correct 26 ms 5536 KB Output is correct
5 Correct 31 ms 6268 KB Output is correct
6 Correct 45 ms 7020 KB Output is correct
7 Correct 28 ms 13128 KB Output is correct
8 Correct 4 ms 3148 KB Output is correct
9 Correct 6 ms 3592 KB Output is correct
10 Correct 9 ms 4044 KB Output is correct
11 Correct 2 ms 2636 KB Output is correct
12 Correct 2 ms 2636 KB Output is correct
13 Correct 2 ms 2668 KB Output is correct
14 Correct 2 ms 2668 KB Output is correct
15 Correct 5 ms 3276 KB Output is correct
16 Correct 7 ms 3824 KB Output is correct
17 Correct 10 ms 4484 KB Output is correct
18 Correct 2 ms 2636 KB Output is correct
19 Correct 1 ms 2636 KB Output is correct
20 Correct 2 ms 2636 KB Output is correct
21 Correct 2 ms 2636 KB Output is correct
22 Correct 2 ms 2636 KB Output is correct
23 Correct 2 ms 2664 KB Output is correct
24 Correct 2 ms 2636 KB Output is correct
25 Correct 3 ms 2636 KB Output is correct
26 Correct 2 ms 2672 KB Output is correct
27 Correct 3 ms 2668 KB Output is correct
28 Correct 2 ms 2668 KB Output is correct
29 Correct 40 ms 7020 KB Output is correct
30 Correct 9 ms 3620 KB Output is correct
31 Correct 23 ms 6512 KB Output is correct
32 Correct 13 ms 4556 KB Output is correct
33 Correct 40 ms 6792 KB Output is correct
34 Correct 22 ms 5148 KB Output is correct
35 Correct 40 ms 6600 KB Output is correct
36 Correct 32 ms 5728 KB Output is correct
37 Correct 29 ms 6772 KB Output is correct
38 Correct 50 ms 6288 KB Output is correct
39 Correct 30 ms 6628 KB Output is correct