Submission #746479

# Submission time Handle Problem Language Result Execution time Memory
746479 2023-05-22T13:39:44 Z sword060 Cijanobakterije (COCI21_cijanobakterije) C++17
70 / 70
70 ms 10428 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+5;
int x,k;
vector<int>v[N];
int dist[N][2];
bool vis[N][2];
pair<int,int>dfs(int i,bool f){
	queue<int>q;
	q.push(i);
	vis[i][f]=1;
	dist[i][f]=1;
	int mx=0,pos=i;
	while(q.size()){
		int j=q.front();q.pop();
		if(mx<dist[j][f]){
			mx=dist[j][f];
			pos=j;
		}
		for(auto c:v[j]){
			if(vis[c][f])continue;
			vis[c][f]=1;
			dist[c][f]=dist[j][f]+1;
			q.push(c);
		}
	}
	return {pos,mx};
}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);
	cin>>x>>k;
	for(int i=0;i<k;i++){
		int l,r;cin>>l>>r;
		v[l].push_back(r);
		v[r].push_back(l);
	}
	int ans=0;
	for(int i=1;i<=x;i++){
		if(vis[i][0])continue;
		int c=dfs(i,0).first;
		ans+=dfs(c,1).second;
	}
	cout<<ans;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 10 ms 5844 KB Output is correct
2 Correct 15 ms 6832 KB Output is correct
3 Correct 23 ms 7600 KB Output is correct
4 Correct 30 ms 8532 KB Output is correct
5 Correct 40 ms 9544 KB Output is correct
6 Correct 52 ms 10324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 10188 KB Output is correct
2 Correct 6 ms 5676 KB Output is correct
3 Correct 10 ms 6316 KB Output is correct
4 Correct 14 ms 6868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 5028 KB Output is correct
5 Correct 6 ms 5844 KB Output is correct
6 Correct 9 ms 6708 KB Output is correct
7 Correct 13 ms 7508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5076 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 5024 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 4 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 5 ms 5032 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 5032 KB Output is correct
11 Correct 4 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 5844 KB Output is correct
2 Correct 15 ms 6832 KB Output is correct
3 Correct 23 ms 7600 KB Output is correct
4 Correct 30 ms 8532 KB Output is correct
5 Correct 40 ms 9544 KB Output is correct
6 Correct 52 ms 10324 KB Output is correct
7 Correct 31 ms 10188 KB Output is correct
8 Correct 6 ms 5676 KB Output is correct
9 Correct 10 ms 6316 KB Output is correct
10 Correct 14 ms 6868 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 5028 KB Output is correct
15 Correct 6 ms 5844 KB Output is correct
16 Correct 9 ms 6708 KB Output is correct
17 Correct 13 ms 7508 KB Output is correct
18 Correct 3 ms 5076 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 5024 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 4 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 5 ms 5032 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 3 ms 5032 KB Output is correct
28 Correct 4 ms 4948 KB Output is correct
29 Correct 59 ms 10428 KB Output is correct
30 Correct 26 ms 6964 KB Output is correct
31 Correct 35 ms 9772 KB Output is correct
32 Correct 29 ms 7852 KB Output is correct
33 Correct 40 ms 10144 KB Output is correct
34 Correct 34 ms 8448 KB Output is correct
35 Correct 36 ms 9960 KB Output is correct
36 Correct 39 ms 9044 KB Output is correct
37 Correct 51 ms 10136 KB Output is correct
38 Correct 70 ms 9624 KB Output is correct
39 Correct 36 ms 9956 KB Output is correct