답안 #496189

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
496189 2021-12-21T01:01:49 Z model_code Cijanobakterije (COCI21_cijanobakterije) C++17
70 / 70
51 ms 12008 KB
#include <cstdio>
#include <vector>

using namespace std;

const int MAXN = 100005;

int n,m;
int sol=0;
vector<int> graph[MAXN];
bool visited[MAXN];

pair<int, int> find_furthest(int node, int parent=-1){
    visited[node] = true;
    pair<int,int> ret(node, 1);
    for(auto i:graph[node]){
        if(i != parent){
            auto csol = find_furthest(i, node);
            csol.second++;
            if(csol.second > ret.second){
                ret = csol;
            }
        }
    }
    return ret;
}

int radius(int node){
    auto s1 = find_furthest(node);
    return find_furthest(s1.first).second;
}

int main(){
    scanf("%d%d", &n, &m);
    for(int i=0;i<m;i++){
        int a, b;
        scanf("%d%d", &a, &b);
        a--;b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    for(int i=0;i<n;i++){
        if(!visited[i]){
            sol += radius(i);
        }
    }
    printf("%d\n", sol);
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:34:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |     scanf("%d%d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~
Main.cpp:37:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         scanf("%d%d", &a, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3148 KB Output is correct
2 Correct 14 ms 3664 KB Output is correct
3 Correct 25 ms 4184 KB Output is correct
4 Correct 26 ms 4820 KB Output is correct
5 Correct 34 ms 5396 KB Output is correct
6 Correct 51 ms 5956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 12008 KB Output is correct
2 Correct 4 ms 3020 KB Output is correct
3 Correct 7 ms 3404 KB Output is correct
4 Correct 9 ms 3788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2636 KB Output is correct
2 Correct 1 ms 2508 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 3 ms 2600 KB Output is correct
5 Correct 5 ms 3148 KB Output is correct
6 Correct 8 ms 3660 KB Output is correct
7 Correct 11 ms 4200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 1 ms 2636 KB Output is correct
3 Correct 2 ms 2508 KB Output is correct
4 Correct 3 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 1 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 14 ms 3664 KB Output is correct
3 Correct 25 ms 4184 KB Output is correct
4 Correct 26 ms 4820 KB Output is correct
5 Correct 34 ms 5396 KB Output is correct
6 Correct 51 ms 5956 KB Output is correct
7 Correct 34 ms 12008 KB Output is correct
8 Correct 4 ms 3020 KB Output is correct
9 Correct 7 ms 3404 KB Output is correct
10 Correct 9 ms 3788 KB Output is correct
11 Correct 1 ms 2636 KB Output is correct
12 Correct 1 ms 2508 KB Output is correct
13 Correct 2 ms 2636 KB Output is correct
14 Correct 3 ms 2600 KB Output is correct
15 Correct 5 ms 3148 KB Output is correct
16 Correct 8 ms 3660 KB Output is correct
17 Correct 11 ms 4200 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 2508 KB Output is correct
21 Correct 3 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 1 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 43 ms 5932 KB Output is correct
30 Correct 8 ms 3532 KB Output is correct
31 Correct 29 ms 5832 KB Output is correct
32 Correct 17 ms 4236 KB Output is correct
33 Correct 33 ms 5836 KB Output is correct
34 Correct 23 ms 4600 KB Output is correct
35 Correct 29 ms 5836 KB Output is correct
36 Correct 30 ms 5008 KB Output is correct
37 Correct 47 ms 5748 KB Output is correct
38 Correct 49 ms 5440 KB Output is correct
39 Correct 30 ms 5836 KB Output is correct