Submission #745884

# Submission time Handle Problem Language Result Execution time Memory
745884 2023-05-21T09:18:55 Z Ahmed57 Cijanobakterije (COCI21_cijanobakterije) C++17
70 / 70
78 ms 8908 KB
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
vector<int> adj[100001];
int ma = 0 , dep = 0;
int vis[100001];
void dfs(int i,int dp){
    vis[i] = 1;
    if(dp>dep){
        dep = dp;
        ma = i;
    }
    for(auto j:adj[i]){
        if(vis[j])continue;
        dfs(j,dp+1);
    }
}
int main(){
    int n,m;
    cin>>n>>m;
    for(int i = 0;i<m;i++){
        int a,b;cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    vector<pair<int,int>> v(n+1);
    for(int i = 1;i<=n;i++){
        if(!vis[i]){
            dep= 0 ,ma =0;
            dfs(i,1);
            v[i].first = dep, v[i].second = ma;
        }
    }
    memset(vis,0,sizeof vis);
    long long all = 0;
    for(int i = 1;i<=n;i++){
        if(!vis[i]){
            dep= 0 ,ma =0;
            dfs(v[i].second,1);
            all+=dep;
        }
    }
    cout<<all<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 12 ms 3668 KB Output is correct
2 Correct 25 ms 4744 KB Output is correct
3 Correct 56 ms 5536 KB Output is correct
4 Correct 55 ms 6444 KB Output is correct
5 Correct 71 ms 7340 KB Output is correct
6 Correct 76 ms 8140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 8908 KB Output is correct
2 Correct 9 ms 3668 KB Output is correct
3 Correct 14 ms 4180 KB Output is correct
4 Correct 20 ms 4812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3028 KB Output is correct
2 Correct 2 ms 3028 KB Output is correct
3 Correct 2 ms 3040 KB Output is correct
4 Correct 2 ms 3028 KB Output is correct
5 Correct 10 ms 3696 KB Output is correct
6 Correct 17 ms 4476 KB Output is correct
7 Correct 23 ms 5196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3028 KB Output is correct
2 Correct 2 ms 3040 KB Output is correct
3 Correct 2 ms 3028 KB Output is correct
4 Correct 2 ms 3028 KB Output is correct
5 Correct 3 ms 3044 KB Output is correct
6 Correct 2 ms 3044 KB Output is correct
7 Correct 2 ms 3028 KB Output is correct
8 Correct 3 ms 3028 KB Output is correct
9 Correct 3 ms 3044 KB Output is correct
10 Correct 2 ms 3040 KB Output is correct
11 Correct 2 ms 3028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 3668 KB Output is correct
2 Correct 25 ms 4744 KB Output is correct
3 Correct 56 ms 5536 KB Output is correct
4 Correct 55 ms 6444 KB Output is correct
5 Correct 71 ms 7340 KB Output is correct
6 Correct 76 ms 8140 KB Output is correct
7 Correct 63 ms 8908 KB Output is correct
8 Correct 9 ms 3668 KB Output is correct
9 Correct 14 ms 4180 KB Output is correct
10 Correct 20 ms 4812 KB Output is correct
11 Correct 2 ms 3028 KB Output is correct
12 Correct 2 ms 3028 KB Output is correct
13 Correct 2 ms 3040 KB Output is correct
14 Correct 2 ms 3028 KB Output is correct
15 Correct 10 ms 3696 KB Output is correct
16 Correct 17 ms 4476 KB Output is correct
17 Correct 23 ms 5196 KB Output is correct
18 Correct 3 ms 3028 KB Output is correct
19 Correct 2 ms 3040 KB Output is correct
20 Correct 2 ms 3028 KB Output is correct
21 Correct 2 ms 3028 KB Output is correct
22 Correct 3 ms 3044 KB Output is correct
23 Correct 2 ms 3044 KB Output is correct
24 Correct 2 ms 3028 KB Output is correct
25 Correct 3 ms 3028 KB Output is correct
26 Correct 3 ms 3044 KB Output is correct
27 Correct 2 ms 3040 KB Output is correct
28 Correct 2 ms 3028 KB Output is correct
29 Correct 78 ms 8160 KB Output is correct
30 Correct 16 ms 4912 KB Output is correct
31 Correct 53 ms 7652 KB Output is correct
32 Correct 29 ms 5724 KB Output is correct
33 Correct 67 ms 7948 KB Output is correct
34 Correct 48 ms 6376 KB Output is correct
35 Correct 70 ms 7772 KB Output is correct
36 Correct 57 ms 6836 KB Output is correct
37 Correct 64 ms 7920 KB Output is correct
38 Correct 67 ms 7368 KB Output is correct
39 Correct 61 ms 7848 KB Output is correct