Submission #528359

# Submission time Handle Problem Language Result Execution time Memory
528359 2022-02-20T07:16:46 Z CSQ31 Cijanobakterije (COCI21_cijanobakterije) C++17
70 / 70
88 ms 13220 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5+1;
vector<int>adj[MAXN];
bool vis[MAXN];
int d = 0;
int dfs(int v,int u){
	vis[v] = 1;
	int d1 = 0,d2 = 0;
	for(int x:adj[v]){
		if(x==u)continue;
		int res = dfs(x,v)+1;
		if(res >= d1){
			d2 = d1;
			d1 = res;
		}else if(res > d2)d2 = res;
	}
	d = max(d,d1+d2);
	return d1;
}
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);
	}
	int ans = 0;
	for(int i=1;i<=n;i++){
		if(!vis[i]){
			d = 0;
			dfs(i,0);
			ans+=d+1;
			//cout<<i<<" "<<d<<'\n';
		}
	}
	cout<<ans;
}

# Verdict Execution time Memory Grader output
1 Correct 11 ms 3276 KB Output is correct
2 Correct 23 ms 4096 KB Output is correct
3 Correct 34 ms 4832 KB Output is correct
4 Correct 58 ms 5632 KB Output is correct
5 Correct 64 ms 6288 KB Output is correct
6 Correct 88 ms 7016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 13220 KB Output is correct
2 Correct 10 ms 3120 KB Output is correct
3 Correct 18 ms 3660 KB Output is correct
4 Correct 24 ms 4160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 1 ms 2636 KB Output is correct
5 Correct 9 ms 3276 KB Output is correct
6 Correct 15 ms 3896 KB Output is correct
7 Correct 21 ms 4460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 2 ms 2764 KB Output is correct
4 Correct 2 ms 2656 KB Output is correct
5 Correct 3 ms 2652 KB Output is correct
6 Correct 2 ms 2636 KB Output is correct
7 Correct 2 ms 2636 KB Output is correct
8 Correct 3 ms 2652 KB Output is correct
9 Correct 2 ms 2636 KB Output is correct
10 Correct 4 ms 2652 KB Output is correct
11 Correct 2 ms 2636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 3276 KB Output is correct
2 Correct 23 ms 4096 KB Output is correct
3 Correct 34 ms 4832 KB Output is correct
4 Correct 58 ms 5632 KB Output is correct
5 Correct 64 ms 6288 KB Output is correct
6 Correct 88 ms 7016 KB Output is correct
7 Correct 67 ms 13220 KB Output is correct
8 Correct 10 ms 3120 KB Output is correct
9 Correct 18 ms 3660 KB Output is correct
10 Correct 24 ms 4160 KB Output is correct
11 Correct 1 ms 2648 KB Output is correct
12 Correct 2 ms 2636 KB Output is correct
13 Correct 2 ms 2636 KB Output is correct
14 Correct 1 ms 2636 KB Output is correct
15 Correct 9 ms 3276 KB Output is correct
16 Correct 15 ms 3896 KB Output is correct
17 Correct 21 ms 4460 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2636 KB Output is correct
20 Correct 2 ms 2764 KB Output is correct
21 Correct 2 ms 2656 KB Output is correct
22 Correct 3 ms 2652 KB Output is correct
23 Correct 2 ms 2636 KB Output is correct
24 Correct 2 ms 2636 KB Output is correct
25 Correct 3 ms 2652 KB Output is correct
26 Correct 2 ms 2636 KB Output is correct
27 Correct 4 ms 2652 KB Output is correct
28 Correct 2 ms 2636 KB Output is correct
29 Correct 69 ms 7004 KB Output is correct
30 Correct 13 ms 3808 KB Output is correct
31 Correct 48 ms 6500 KB Output is correct
32 Correct 25 ms 4560 KB Output is correct
33 Correct 81 ms 6896 KB Output is correct
34 Correct 52 ms 5264 KB Output is correct
35 Correct 80 ms 6708 KB Output is correct
36 Correct 48 ms 5820 KB Output is correct
37 Correct 69 ms 6784 KB Output is correct
38 Correct 84 ms 6292 KB Output is correct
39 Correct 61 ms 6728 KB Output is correct