QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#84819#5651. Parmigiana With SeafoodShukuangWA 65ms10584kbC++141.1kb2023-03-06 19:34:092023-03-06 19:34:13

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 19:34:13]
  • 评测
  • 测评结果:WA
  • 用时:65ms
  • 内存:10584kb
  • [2023-03-06 19:34:09]
  • 提交

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) {
        fa[u] = 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) continue;
		if (u != n && cnt[u] >= 2) {
			cout << i << '\n';
			return 0;
		}
		if (u == n && cnt[u] >= 3) {
			cout << i << '\n';
			return 0;
		}
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 6928kb

input:

4
1 2
1 3
1 4

output:

4

result:

ok single line: '4'

Test #2:

score: 0
Accepted
time: 3ms
memory: 5644kb

input:

5
1 5
5 3
3 4
4 2

output:

3

result:

ok single line: '3'

Test #3:

score: -100
Wrong Answer
time: 65ms
memory: 10584kb

input:

99999
81856 39633
81856 94012
99999 43062
99946 220
81856 46131
99933 36505
99939 35662
99952 70971
99999 3275
99938 58416
99976 66658
99991 87922
81856 80992
99933 6392
99951 41047
99970 54115
81856 38150
99934 73554
81856 64578
81856 18576
99951 67996
99938 84479
81856 39617
99999 18664
99946 2505...

output:

99997

result:

wrong answer 1st lines differ - expected: '99925', found: '99997'