Submission #520414

# Submission time Handle Problem Language Result Execution time Memory
520414 2022-01-29T21:45:06 Z Lalic Cijanobakterije (COCI21_cijanobakterije) C++17
70 / 70
894 ms 12396 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const double pi = 3.14159265358979323846;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;

int d, aux, cmp[MAXN], mark[MAXN];
vector<int> v[MAXN];

void dfs(int x, int dist){
    cmp[x]=1;
    mark[x]=1;
    if(dist>d){
        aux=x;
        d=dist;
    }
    for(auto u : v[x]){
        if(cmp[u]==0) dfs(u, dist+1);
    }
}
 
int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    
    int ans=0, n, m; cin >> n >> m;
    for(int i=0;i<m;i++){
        int u, a; cin >> u >> a;
        v[u].pb(a);
        v[a].pb(u);
    }
    for(int i=1;i<=n;i++){
        if(mark[i]==0){
            d=-1, aux=-1;
            memset(cmp, 0, sizeof cmp);
            dfs(i, 0);
            if(d==0){
                ans++;
                continue;
            }
            d=-1;
            memset(cmp, 0, sizeof cmp);
            dfs(aux, 0);
            d++;
            ans+=d;
        }
    }
    cout << ans << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 3828 KB Output is correct
2 Correct 12 ms 4556 KB Output is correct
3 Correct 19 ms 5364 KB Output is correct
4 Correct 26 ms 6184 KB Output is correct
5 Correct 29 ms 6996 KB Output is correct
6 Correct 36 ms 7700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 12396 KB Output is correct
2 Correct 148 ms 3572 KB Output is correct
3 Correct 238 ms 4028 KB Output is correct
4 Correct 342 ms 4768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3052 KB Output is correct
2 Correct 2 ms 3020 KB Output is correct
3 Correct 2 ms 3056 KB Output is correct
4 Correct 2 ms 3020 KB Output is correct
5 Correct 36 ms 3660 KB Output is correct
6 Correct 48 ms 4344 KB Output is correct
7 Correct 72 ms 5088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3096 KB Output is correct
2 Correct 6 ms 3020 KB Output is correct
3 Correct 6 ms 3020 KB Output is correct
4 Correct 8 ms 3020 KB Output is correct
5 Correct 4 ms 3060 KB Output is correct
6 Correct 7 ms 3020 KB Output is correct
7 Correct 9 ms 3092 KB Output is correct
8 Correct 5 ms 3020 KB Output is correct
9 Correct 6 ms 3020 KB Output is correct
10 Correct 5 ms 3020 KB Output is correct
11 Correct 10 ms 3020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 3828 KB Output is correct
2 Correct 12 ms 4556 KB Output is correct
3 Correct 19 ms 5364 KB Output is correct
4 Correct 26 ms 6184 KB Output is correct
5 Correct 29 ms 6996 KB Output is correct
6 Correct 36 ms 7700 KB Output is correct
7 Correct 30 ms 12396 KB Output is correct
8 Correct 148 ms 3572 KB Output is correct
9 Correct 238 ms 4028 KB Output is correct
10 Correct 342 ms 4768 KB Output is correct
11 Correct 2 ms 3052 KB Output is correct
12 Correct 2 ms 3020 KB Output is correct
13 Correct 2 ms 3056 KB Output is correct
14 Correct 2 ms 3020 KB Output is correct
15 Correct 36 ms 3660 KB Output is correct
16 Correct 48 ms 4344 KB Output is correct
17 Correct 72 ms 5088 KB Output is correct
18 Correct 2 ms 3096 KB Output is correct
19 Correct 6 ms 3020 KB Output is correct
20 Correct 6 ms 3020 KB Output is correct
21 Correct 8 ms 3020 KB Output is correct
22 Correct 4 ms 3060 KB Output is correct
23 Correct 7 ms 3020 KB Output is correct
24 Correct 9 ms 3092 KB Output is correct
25 Correct 5 ms 3020 KB Output is correct
26 Correct 6 ms 3020 KB Output is correct
27 Correct 5 ms 3020 KB Output is correct
28 Correct 10 ms 3020 KB Output is correct
29 Correct 39 ms 7792 KB Output is correct
30 Correct 894 ms 4588 KB Output is correct
31 Correct 627 ms 7320 KB Output is correct
32 Correct 769 ms 5340 KB Output is correct
33 Correct 207 ms 7656 KB Output is correct
34 Correct 580 ms 5960 KB Output is correct
35 Correct 512 ms 7480 KB Output is correct
36 Correct 378 ms 6556 KB Output is correct
37 Correct 226 ms 7816 KB Output is correct
38 Correct 213 ms 7104 KB Output is correct
39 Correct 383 ms 7544 KB Output is correct