답안 #626079

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
626079 2022-08-11T08:02:09 Z Trisanu_Das Cijanobakterije (COCI21_cijanobakterije) C++17
70 / 70
39 ms 13348 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ar array

const int mxN=1e5;
int n, m;
vector<int> adj[mxN];
bool vis[mxN];

ar<int, 2> dfs(int u) {
	vis[u]=1;
	ar<int, 2> d={};
	int diam=0;
	for (int v : adj[u])
		if (!vis[v]) {
			ar<int, 2> x=dfs(v);
			diam=max(diam, x[0]);
			if (x[1]+1>d[0]) {
				swap(d[0], d[1]);
				d[0]=x[1]+1;
			} else if (x[1]+1>d[1])
				d[1]=x[1]+1;
		}
	diam=max(diam, d[0]+d[1]);
	return {diam, d[0]};
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m;
	for (int i=0; i<m; ++i) {
		int u, v;
		cin >> u >> v, --u, --v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	int ans=0;
	for (int i=0; i<n; ++i)
		if (!vis[i])
			ans+=dfs(i)[0]+1;
	cout << ans;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3544 KB Output is correct
2 Correct 12 ms 4052 KB Output is correct
3 Correct 17 ms 4812 KB Output is correct
4 Correct 23 ms 5612 KB Output is correct
5 Correct 27 ms 6368 KB Output is correct
6 Correct 36 ms 7136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 13348 KB Output is correct
2 Correct 3 ms 3156 KB Output is correct
3 Correct 7 ms 3668 KB Output is correct
4 Correct 8 ms 4104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2892 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 5 ms 3204 KB Output is correct
6 Correct 6 ms 3924 KB Output is correct
7 Correct 9 ms 4564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2692 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 3 ms 2688 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2772 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3544 KB Output is correct
2 Correct 12 ms 4052 KB Output is correct
3 Correct 17 ms 4812 KB Output is correct
4 Correct 23 ms 5612 KB Output is correct
5 Correct 27 ms 6368 KB Output is correct
6 Correct 36 ms 7136 KB Output is correct
7 Correct 29 ms 13348 KB Output is correct
8 Correct 3 ms 3156 KB Output is correct
9 Correct 7 ms 3668 KB Output is correct
10 Correct 8 ms 4104 KB Output is correct
11 Correct 2 ms 2892 KB Output is correct
12 Correct 1 ms 2644 KB Output is correct
13 Correct 1 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 5 ms 3204 KB Output is correct
16 Correct 6 ms 3924 KB Output is correct
17 Correct 9 ms 4564 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 1 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 2 ms 2692 KB Output is correct
23 Correct 2 ms 2644 KB Output is correct
24 Correct 3 ms 2688 KB Output is correct
25 Correct 2 ms 2644 KB Output is correct
26 Correct 2 ms 2644 KB Output is correct
27 Correct 2 ms 2772 KB Output is correct
28 Correct 2 ms 2644 KB Output is correct
29 Correct 37 ms 7248 KB Output is correct
30 Correct 8 ms 3852 KB Output is correct
31 Correct 23 ms 6564 KB Output is correct
32 Correct 14 ms 4632 KB Output is correct
33 Correct 36 ms 6860 KB Output is correct
34 Correct 19 ms 5332 KB Output is correct
35 Correct 28 ms 6732 KB Output is correct
36 Correct 24 ms 5896 KB Output is correct
37 Correct 29 ms 6868 KB Output is correct
38 Correct 39 ms 6420 KB Output is correct
39 Correct 28 ms 6812 KB Output is correct