답안 #587689

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
587689 2022-07-02T08:35:28 Z MilosMilutinovic Cijanobakterije (COCI21_cijanobakterije) C++14
70 / 70
41 ms 15052 KB
/**
 *    author:  wxhtzdy
 *    created: 02.07.2022 10:32:27
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);  
  int n, m;
  cin >> n >> m;
  vector<vector<int>> g(n);
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    --u; --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }  
  vector<bool> was(n);
  vector<int> dep(n);
  int idx;
  function<void(int, int)> Dfs = [&](int v, int pr) {
    was[v] = true;
    dep[v] = dep[pr] + 1;
    if (dep[idx] < dep[v]) {
      idx = v;
    }
    for (int u : g[v]) {
      if (u != pr) {
        Dfs(u, v);
      }
    }
  };
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (!was[i]) {
      idx = i;
      Dfs(i, i);
      dep[idx] = 0;
      Dfs(idx, idx);
      ans += dep[idx];        
    }
  }
  cout << ans << '\n';                                                
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 1492 KB Output is correct
2 Correct 15 ms 2676 KB Output is correct
3 Correct 18 ms 3796 KB Output is correct
4 Correct 26 ms 5064 KB Output is correct
5 Correct 41 ms 6224 KB Output is correct
6 Correct 40 ms 7464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 15052 KB Output is correct
2 Correct 3 ms 1236 KB Output is correct
3 Correct 6 ms 2168 KB Output is correct
4 Correct 9 ms 3156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 320 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 4 ms 1364 KB Output is correct
6 Correct 7 ms 2388 KB Output is correct
7 Correct 10 ms 3456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 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 328 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 1492 KB Output is correct
2 Correct 15 ms 2676 KB Output is correct
3 Correct 18 ms 3796 KB Output is correct
4 Correct 26 ms 5064 KB Output is correct
5 Correct 41 ms 6224 KB Output is correct
6 Correct 40 ms 7464 KB Output is correct
7 Correct 35 ms 15052 KB Output is correct
8 Correct 3 ms 1236 KB Output is correct
9 Correct 6 ms 2168 KB Output is correct
10 Correct 9 ms 3156 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 320 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 4 ms 1364 KB Output is correct
16 Correct 7 ms 2388 KB Output is correct
17 Correct 10 ms 3456 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 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 328 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 40 ms 7372 KB Output is correct
30 Correct 9 ms 4052 KB Output is correct
31 Correct 25 ms 6932 KB Output is correct
32 Correct 15 ms 4900 KB Output is correct
33 Correct 33 ms 7228 KB Output is correct
34 Correct 21 ms 5548 KB Output is correct
35 Correct 28 ms 6996 KB Output is correct
36 Correct 29 ms 6108 KB Output is correct
37 Correct 32 ms 7252 KB Output is correct
38 Correct 39 ms 6692 KB Output is correct
39 Correct 30 ms 7136 KB Output is correct