Submission #866918

# Submission time Handle Problem Language Result Execution time Memory
866918 2023-10-27T10:32:28 Z epicci23 Cijanobakterije (COCI21_cijanobakterije) C++17
70 / 70
35 ms 12380 KB
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define endl "\n" 
#define int long long
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

constexpr int N = 1e5 + 5;
vector<int> v[N];
int vis[N];
array<int,2> cur;

void dfs(int c,int p,int d){
  cur=max(cur,{d,c});
  vis[c]=1;
  for(int x:v[c]){
  	if(x==p) continue;
  	dfs(x,c,d+1);
  }
}

void solve(){
	int n,m;
	cin >> n >> m;
    
    for(int i=1;i<=m;i++){
    	int a,b;
    	cin >> a >> b;
    	v[a].pb(b);
    	v[b].pb(a);
    }
    
    int ans=0;

    for(int i=1;i<=n;i++){
      if(vis[i]) continue;
      ans++;
      cur={0,0};
      dfs(i,i,0);
      dfs(cur[1],cur[1],0);
      ans+=cur[0];
    }
   
    cout << ans << endl;
}

int32_t main(){

  cin.tie(0); ios::sync_with_stdio(0);
  
  int t=1;//cin >> t;
  while(t--) solve();

  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4184 KB Output is correct
2 Correct 9 ms 4956 KB Output is correct
3 Correct 15 ms 5816 KB Output is correct
4 Correct 19 ms 6748 KB Output is correct
5 Correct 22 ms 7504 KB Output is correct
6 Correct 26 ms 8284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 12380 KB Output is correct
2 Correct 3 ms 3932 KB Output is correct
3 Correct 5 ms 4444 KB Output is correct
4 Correct 7 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3664 KB Output is correct
2 Correct 1 ms 3412 KB Output is correct
3 Correct 1 ms 3164 KB Output is correct
4 Correct 1 ms 3164 KB Output is correct
5 Correct 3 ms 4188 KB Output is correct
6 Correct 5 ms 4700 KB Output is correct
7 Correct 8 ms 5456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3416 KB Output is correct
2 Correct 1 ms 3164 KB Output is correct
3 Correct 1 ms 3164 KB Output is correct
4 Correct 1 ms 3416 KB Output is correct
5 Correct 1 ms 3420 KB Output is correct
6 Correct 1 ms 3420 KB Output is correct
7 Correct 1 ms 3420 KB Output is correct
8 Correct 1 ms 3420 KB Output is correct
9 Correct 1 ms 3416 KB Output is correct
10 Correct 1 ms 3420 KB Output is correct
11 Correct 2 ms 3420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4184 KB Output is correct
2 Correct 9 ms 4956 KB Output is correct
3 Correct 15 ms 5816 KB Output is correct
4 Correct 19 ms 6748 KB Output is correct
5 Correct 22 ms 7504 KB Output is correct
6 Correct 26 ms 8284 KB Output is correct
7 Correct 23 ms 12380 KB Output is correct
8 Correct 3 ms 3932 KB Output is correct
9 Correct 5 ms 4444 KB Output is correct
10 Correct 7 ms 4956 KB Output is correct
11 Correct 1 ms 3664 KB Output is correct
12 Correct 1 ms 3412 KB Output is correct
13 Correct 1 ms 3164 KB Output is correct
14 Correct 1 ms 3164 KB Output is correct
15 Correct 3 ms 4188 KB Output is correct
16 Correct 5 ms 4700 KB Output is correct
17 Correct 8 ms 5456 KB Output is correct
18 Correct 1 ms 3416 KB Output is correct
19 Correct 1 ms 3164 KB Output is correct
20 Correct 1 ms 3164 KB Output is correct
21 Correct 1 ms 3416 KB Output is correct
22 Correct 1 ms 3420 KB Output is correct
23 Correct 1 ms 3420 KB Output is correct
24 Correct 1 ms 3420 KB Output is correct
25 Correct 1 ms 3420 KB Output is correct
26 Correct 1 ms 3416 KB Output is correct
27 Correct 1 ms 3420 KB Output is correct
28 Correct 2 ms 3420 KB Output is correct
29 Correct 35 ms 8276 KB Output is correct
30 Correct 7 ms 4440 KB Output is correct
31 Correct 17 ms 7364 KB Output is correct
32 Correct 11 ms 5468 KB Output is correct
33 Correct 22 ms 8136 KB Output is correct
34 Correct 16 ms 6236 KB Output is correct
35 Correct 19 ms 7516 KB Output is correct
36 Correct 20 ms 6832 KB Output is correct
37 Correct 22 ms 8028 KB Output is correct
38 Correct 25 ms 7512 KB Output is correct
39 Correct 21 ms 7760 KB Output is correct