답안 #530931

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
530931 2022-02-27T06:51:35 Z ivls Cijanobakterije (COCI21_cijanobakterije) C++14
70 / 70
38 ms 10560 KB
#include <bits/stdc++.h>

using namespace std;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

using ll = long long;

const int inf = 2e9;

int n, m, mx, nm;
vector<int> g[100100];
bool used[100100];

void dfs(int v, int p, int de)
{
    used[v] = 1;
    if (de >= mx) { mx = de; nm = v; }
    for (auto u : g[v])
        if (u != p) dfs(u, v, de + 1);
}

int diam(int v)
{
    mx = 0;
    dfs(v, -1, 0);
    mx = 0;
    dfs(nm, -1, 0);
    return mx + 1;
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= m; i++)
    {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++)
        if (!used[i]) ans += diam(i);
    cout << ans << '\n';
}

# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3148 KB Output is correct
2 Correct 12 ms 3664 KB Output is correct
3 Correct 17 ms 4304 KB Output is correct
4 Correct 26 ms 4820 KB Output is correct
5 Correct 32 ms 5524 KB Output is correct
6 Correct 38 ms 5984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 10560 KB Output is correct
2 Correct 4 ms 3020 KB Output is correct
3 Correct 6 ms 3404 KB Output is correct
4 Correct 8 ms 3892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2636 KB Output is correct
2 Correct 2 ms 2572 KB Output is correct
3 Correct 1 ms 2636 KB Output is correct
4 Correct 1 ms 2636 KB Output is correct
5 Correct 4 ms 3148 KB Output is correct
6 Correct 7 ms 3660 KB Output is correct
7 Correct 10 ms 4192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 1 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 2636 KB Output is correct
7 Correct 1 ms 2632 KB Output is correct
8 Correct 2 ms 2636 KB Output is correct
9 Correct 3 ms 2636 KB Output is correct
10 Correct 2 ms 2636 KB Output is correct
11 Correct 1 ms 2636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3148 KB Output is correct
2 Correct 12 ms 3664 KB Output is correct
3 Correct 17 ms 4304 KB Output is correct
4 Correct 26 ms 4820 KB Output is correct
5 Correct 32 ms 5524 KB Output is correct
6 Correct 38 ms 5984 KB Output is correct
7 Correct 28 ms 10560 KB Output is correct
8 Correct 4 ms 3020 KB Output is correct
9 Correct 6 ms 3404 KB Output is correct
10 Correct 8 ms 3892 KB Output is correct
11 Correct 1 ms 2636 KB Output is correct
12 Correct 2 ms 2572 KB Output is correct
13 Correct 1 ms 2636 KB Output is correct
14 Correct 1 ms 2636 KB Output is correct
15 Correct 4 ms 3148 KB Output is correct
16 Correct 7 ms 3660 KB Output is correct
17 Correct 10 ms 4192 KB Output is correct
18 Correct 2 ms 2636 KB Output is correct
19 Correct 2 ms 2636 KB Output is correct
20 Correct 1 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 2636 KB Output is correct
24 Correct 1 ms 2632 KB Output is correct
25 Correct 2 ms 2636 KB Output is correct
26 Correct 3 ms 2636 KB Output is correct
27 Correct 2 ms 2636 KB Output is correct
28 Correct 1 ms 2636 KB Output is correct
29 Correct 38 ms 5976 KB Output is correct
30 Correct 8 ms 3532 KB Output is correct
31 Correct 22 ms 5836 KB Output is correct
32 Correct 13 ms 4184 KB Output is correct
33 Correct 28 ms 5924 KB Output is correct
34 Correct 18 ms 4648 KB Output is correct
35 Correct 28 ms 5800 KB Output is correct
36 Correct 25 ms 5084 KB Output is correct
37 Correct 29 ms 5872 KB Output is correct
38 Correct 32 ms 5452 KB Output is correct
39 Correct 26 ms 5836 KB Output is correct