Submission #814816

# Submission time Handle Problem Language Result Execution time Memory
814816 2023-08-08T10:15:16 Z vjudge1 Cijanobakterije (COCI21_cijanobakterije) C++17
70 / 70
77 ms 11596 KB
#include<bits/stdc++.h>
using namespace std;
vector<int>adj[100001];
bool vis[100001]={false};
int again, maxdepth;
void dfs(int current, int past, int depth) {
    vis[current]=true;
    if(depth>maxdepth) {
        maxdepth=depth;
        again=current;
    }
    for(auto iter:adj[current]) {
        if(iter != past) {
            dfs(iter, current, depth+1);
        }
    }
}
int longest(int i) {
    maxdepth=0;
    dfs(i, -1, 1);
    maxdepth=0;
    dfs(again, -1, 1);
    return maxdepth;
}
int main() {
    int N,M,A,B;
    cin >> N >> M;
    for(int i=1; i<=M; i++) {
        cin >> A >> B;
        adj[A].push_back(B);
        adj[B].push_back(A);
    }
    int sum=0;
    for(int i=1; i<=N; i++) {
        if(vis[i]==false) {
            sum+=longest(i);
        }
    }
    cout << sum << endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 10 ms 3312 KB Output is correct
2 Correct 30 ms 4124 KB Output is correct
3 Correct 30 ms 4780 KB Output is correct
4 Correct 40 ms 5568 KB Output is correct
5 Correct 70 ms 6300 KB Output is correct
6 Correct 73 ms 7088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 11596 KB Output is correct
2 Correct 6 ms 3056 KB Output is correct
3 Correct 11 ms 3584 KB Output is correct
4 Correct 14 ms 4120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2660 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 1 ms 2656 KB Output is correct
5 Correct 7 ms 3284 KB Output is correct
6 Correct 16 ms 3924 KB Output is correct
7 Correct 17 ms 4464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2664 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2660 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 3 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2660 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 3312 KB Output is correct
2 Correct 30 ms 4124 KB Output is correct
3 Correct 30 ms 4780 KB Output is correct
4 Correct 40 ms 5568 KB Output is correct
5 Correct 70 ms 6300 KB Output is correct
6 Correct 73 ms 7088 KB Output is correct
7 Correct 54 ms 11596 KB Output is correct
8 Correct 6 ms 3056 KB Output is correct
9 Correct 11 ms 3584 KB Output is correct
10 Correct 14 ms 4120 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2660 KB Output is correct
13 Correct 1 ms 2644 KB Output is correct
14 Correct 1 ms 2656 KB Output is correct
15 Correct 7 ms 3284 KB Output is correct
16 Correct 16 ms 3924 KB Output is correct
17 Correct 17 ms 4464 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 1 ms 2664 KB Output is correct
20 Correct 1 ms 2644 KB Output is correct
21 Correct 1 ms 2644 KB Output is correct
22 Correct 2 ms 2660 KB Output is correct
23 Correct 2 ms 2644 KB Output is correct
24 Correct 3 ms 2644 KB Output is correct
25 Correct 2 ms 2644 KB Output is correct
26 Correct 2 ms 2660 KB Output is correct
27 Correct 2 ms 2644 KB Output is correct
28 Correct 2 ms 2644 KB Output is correct
29 Correct 56 ms 7100 KB Output is correct
30 Correct 12 ms 3796 KB Output is correct
31 Correct 40 ms 6584 KB Output is correct
32 Correct 20 ms 4632 KB Output is correct
33 Correct 50 ms 6836 KB Output is correct
34 Correct 31 ms 5232 KB Output is correct
35 Correct 41 ms 6692 KB Output is correct
36 Correct 44 ms 5864 KB Output is correct
37 Correct 77 ms 6912 KB Output is correct
38 Correct 52 ms 6448 KB Output is correct
39 Correct 47 ms 6672 KB Output is correct