Submission #874928

# Submission time Handle Problem Language Result Execution time Memory
874928 2023-11-18T06:23:49 Z tsumondai Cijanobakterije (COCI21_cijanobakterije) C++14
70 / 70
30 ms 13140 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);
      |         ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3420 KB Output is correct
2 Correct 10 ms 4188 KB Output is correct
3 Correct 14 ms 4956 KB Output is correct
4 Correct 20 ms 5724 KB Output is correct
5 Correct 23 ms 6420 KB Output is correct
6 Correct 28 ms 7264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 13140 KB Output is correct
2 Correct 3 ms 3164 KB Output is correct
3 Correct 5 ms 3772 KB Output is correct
4 Correct 7 ms 4188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 4 ms 3164 KB Output is correct
6 Correct 6 ms 3856 KB Output is correct
7 Correct 8 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 2 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 2 ms 2652 KB Output is correct
7 Correct 2 ms 2776 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3420 KB Output is correct
2 Correct 10 ms 4188 KB Output is correct
3 Correct 14 ms 4956 KB Output is correct
4 Correct 20 ms 5724 KB Output is correct
5 Correct 23 ms 6420 KB Output is correct
6 Correct 28 ms 7264 KB Output is correct
7 Correct 30 ms 13140 KB Output is correct
8 Correct 3 ms 3164 KB Output is correct
9 Correct 5 ms 3772 KB Output is correct
10 Correct 7 ms 4188 KB Output is correct
11 Correct 2 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 4 ms 3164 KB Output is correct
16 Correct 6 ms 3856 KB Output is correct
17 Correct 8 ms 4444 KB Output is correct
18 Correct 2 ms 2652 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
21 Correct 2 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 2 ms 2652 KB Output is correct
24 Correct 2 ms 2776 KB Output is correct
25 Correct 1 ms 2652 KB Output is correct
26 Correct 1 ms 2648 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 1 ms 2652 KB Output is correct
29 Correct 28 ms 6996 KB Output is correct
30 Correct 8 ms 3740 KB Output is correct
31 Correct 20 ms 6636 KB Output is correct
32 Correct 12 ms 4700 KB Output is correct
33 Correct 24 ms 7248 KB Output is correct
34 Correct 15 ms 5212 KB Output is correct
35 Correct 20 ms 6748 KB Output is correct
36 Correct 21 ms 5996 KB Output is correct
37 Correct 30 ms 6860 KB Output is correct
38 Correct 30 ms 6332 KB Output is correct
39 Correct 23 ms 6660 KB Output is correct