답안 #863228

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
863228 2023-10-19T20:24:55 Z TAhmed33 Cijanobakterije (COCI21_cijanobakterije) C++
12 / 70
56 ms 15924 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 25;
vector <int> adj[MAXN];
int dp[MAXN][2];
bool vis[MAXN];
void dfs (int pos, int par) {
	vis[pos] = 1;
	int mx1 = 0, mx2 = 0;
	for (auto j : adj[pos]) {
		if (j == par) continue;
		dfs(j, pos);
		if (1 + dp[j][1] > mx1) {
			mx2 = mx1; mx1 = dp[j][1];
		} else if (dp[j][1] > mx2) {
			mx2 = dp[j][1];
		}
	}	
	dp[pos][0] = 1 + mx1 + mx2;
	dp[pos][1] = 1 + mx1;
}
int main () {
	int mx = 0;
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= m; i++) {
		int a, b;
		cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	for (int i = 1; i <= n; i++) {
		if (!vis[i]) {
			dfs(i, -1);
			mx += dp[i][0]; 
		}
	}
	cout << mx << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 3932 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 15924 KB Output is correct
2 Correct 5 ms 3932 KB Output is correct
3 Correct 10 ms 4304 KB Output is correct
4 Correct 14 ms 4700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3420 KB Output is correct
2 Correct 1 ms 3420 KB Output is correct
3 Correct 1 ms 3420 KB Output is correct
4 Correct 1 ms 3420 KB Output is correct
5 Correct 7 ms 3932 KB Output is correct
6 Correct 11 ms 4444 KB Output is correct
7 Correct 16 ms 4956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 3420 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 3932 KB Output isn't correct
2 Halted 0 ms 0 KB -