QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#84538#5651. Parmigiana With SeafoodShukuangWA 0ms5984kbC++141.0kb2023-03-06 15:45:262023-03-06 15:45:59

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:45:59]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:5984kb
  • [2023-03-06 15:45:26]
  • 提交

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], fa[N], vis[N], cnt[N];
vv<int> G[N];

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);
	for (int i = n; i >= 1; --i) {
		if (col[i] || (int)G[i].size() <= 1) {
			cout << i << '\n';
			return 0;
		}
		int u = i;
		while (!vis[u]) {
			vis[u] = 1;
			u = fa[u];
			cnt[u] ++;
		} 
		if (u != n && cnt[u] >= 2) {
			cout << i << '\n';
			return 0;
		}
		if (u == n && cnt[u] >= 3) {
			cout << i << '\n';
			return 0;
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 5800kb

input:

4
1 2
1 3
1 4

output:

4

result:

ok single line: '4'

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 5984kb

input:

5
1 5
5 3
3 4
4 2

output:

5

result:

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