답안 #496535

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
496535 2021-12-21T13:14:40 Z kappa Cijanobakterije (COCI21_cijanobakterije) C++14
70 / 70
105 ms 13892 KB
#include <bits/stdc++.h>

using namespace std;

int n, m, ans, vis[100005];

vector<int> d[100005];

pair<int, int> furthest(int ind, int parent = -1){
    vis[ind] = 1;

    pair<int, int> ret(ind, 1);

    for (int i = 0; i < d[ind].size(); i++)
    {
        if(d[ind][i] != parent){
            pair<int, int> a = furthest(d[ind][i], ind);

            a.second++;

            if(a.second > ret.second){
                ret = a;
            }
        }
    }
    
    return ret;
}

int diameter(int ind){
    pair<int, int> s1 = furthest(ind);
    
    return furthest(s1.first).second;
}

int main(){
    cin >> n >> m;

    for (int i = 0; i < m; i++)
    {
        int u, v;

        cin >> u >> v;

        d[u].push_back(v);
        d[v].push_back(u);
    }

    for (int i = 1; i <= n; i++)
    {
        if(!vis[i]){
            ans += diameter(i);
        }
    }

    cout << ans;
}

Compilation message

Main.cpp: In function 'std::pair<int, int> furthest(int, int)':
Main.cpp:14:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |     for (int i = 0; i < d[ind].size(); i++)
      |                     ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 3148 KB Output is correct
2 Correct 23 ms 3776 KB Output is correct
3 Correct 43 ms 4348 KB Output is correct
4 Correct 47 ms 5008 KB Output is correct
5 Correct 65 ms 5572 KB Output is correct
6 Correct 105 ms 6280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 13892 KB Output is correct
2 Correct 8 ms 3020 KB Output is correct
3 Correct 16 ms 3528 KB Output is correct
4 Correct 17 ms 3972 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 1 ms 2636 KB Output is correct
5 Correct 8 ms 3148 KB Output is correct
6 Correct 15 ms 3788 KB Output is correct
7 Correct 25 ms 4340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 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 2636 KB Output is correct
7 Correct 2 ms 2636 KB Output is correct
8 Correct 2 ms 2636 KB Output is correct
9 Correct 2 ms 2636 KB Output is correct
10 Correct 3 ms 2636 KB Output is correct
11 Correct 2 ms 2636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 3148 KB Output is correct
2 Correct 23 ms 3776 KB Output is correct
3 Correct 43 ms 4348 KB Output is correct
4 Correct 47 ms 5008 KB Output is correct
5 Correct 65 ms 5572 KB Output is correct
6 Correct 105 ms 6280 KB Output is correct
7 Correct 79 ms 13892 KB Output is correct
8 Correct 8 ms 3020 KB Output is correct
9 Correct 16 ms 3528 KB Output is correct
10 Correct 17 ms 3972 KB Output is correct
11 Correct 2 ms 2636 KB Output is correct
12 Correct 2 ms 2636 KB Output is correct
13 Correct 1 ms 2636 KB Output is correct
14 Correct 1 ms 2636 KB Output is correct
15 Correct 8 ms 3148 KB Output is correct
16 Correct 15 ms 3788 KB Output is correct
17 Correct 25 ms 4340 KB Output is correct
18 Correct 3 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 2636 KB Output is correct
24 Correct 2 ms 2636 KB Output is correct
25 Correct 2 ms 2636 KB Output is correct
26 Correct 2 ms 2636 KB Output is correct
27 Correct 3 ms 2636 KB Output is correct
28 Correct 2 ms 2636 KB Output is correct
29 Correct 90 ms 6332 KB Output is correct
30 Correct 20 ms 3916 KB Output is correct
31 Correct 61 ms 6020 KB Output is correct
32 Correct 38 ms 4544 KB Output is correct
33 Correct 68 ms 6132 KB Output is correct
34 Correct 38 ms 5036 KB Output is correct
35 Correct 57 ms 6212 KB Output is correct
36 Correct 59 ms 5360 KB Output is correct
37 Correct 73 ms 6160 KB Output is correct
38 Correct 103 ms 5724 KB Output is correct
39 Correct 64 ms 6024 KB Output is correct