QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#84495#5651. Parmigiana With SeafoodShukuangWA 3ms5656kbC++141.0kb2023-03-06 15:24:002023-03-06 15:25:36

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-06 15:25:36]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:5656kb
  • [2023-03-06 15:24:00]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using pii = pair<int, int>;

#define vv vector
#define fi first
#define se second
#define eb emplace_back

const int N = 1e5 + 10;
int n;
int col[N];
vv<int> G[N], vec[2];

void dfs(int u, int fath) {
	for (auto v : G[u]) {
		if (v == fath) continue;
		col[v] = col[u] ^ 1;
		dfs(v, u);
	}
}

signed main() {
	#ifndef ONLINE_JUDGE
		freopen("test.in", "r", stdin);
		freopen("test.out", "w", stdout);
	#endif
	cin >> n;
	for (int i = 1; i < n; ++i) {
		int u, v; cin >> u >> v;
		G[u].eb(v); G[v].eb(u);
	}
	if (n % 2 == 0) {
		cout << n << '\n';
		return 0;
	}
	dfs(n, 0);
	int ans = 0;
	for (int i = n; i >= 1; --i) {
		if (col[i] || G[i].size() <= 1) ans = max(ans, i);
		vec[col[i]].eb(i);
	}
	for (int i = 0; i <= 1; ++i) {
		sort(vec[i].begin(), vec[i].end(), [&](int i, int j) -> bool {return i > j;});
		if (vec[i].size() >= 3) ans = max(ans, vec[i][2]);
	}
	if (vec[1].size()) ans = max(ans, vec[0][1]);
	cout << ans << '\n';
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 5636kb

input:

4
1 2
1 3
1 4

output:

4

result:

ok single line: '4'

Test #2:

score: -100
Wrong Answer
time: 3ms
memory: 5656kb

input:

5
1 5
5 3
3 4
4 2

output:

4

result:

wrong answer 1st lines differ - expected: '3', found: '4'