QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#124894#5651. Parmigiana With SeafoodHongzy#WA 6ms10152kbC++141.4kb2023-07-15 17:51:132023-07-15 17:51:14

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-15 17:51:14]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:10152kb
  • [2023-07-15 17:51:13]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
int gi() {
	int res = 0, w = 1;
	char ch = getchar();
	while (ch != '-' && !isdigit(ch)) ch = getchar();
	if (ch == '-') w = -1, ch = getchar();
	while (isdigit(ch)) res = res * 10 + ch - '0', ch = getchar();
	return res * w;
}
#define fi first
#define se second
#define pii pair<int, int>
using LL = long long;
using db = long double;
const int Mod = 998244353;
const int MAX_N = 1e5 + 5;
vector<int> G[MAX_N];
int N, ans, fa[MAX_N], dep[MAX_N];
void dfs(int x) {
	dep[x] = dep[fa[x]] ^ 1;
	for (int v : G[x])
		if (v != fa[x]) fa[v] = x, dfs(v);
}
int vis[MAX_N];
void solve() {
	N = gi();
	if (N % 2 == 0) return (void)printf("%d\n", N);
	for (int i = 1; i < N; i++) {
		int u = gi(), v = gi();
		G[u].push_back(v), G[v].push_back(u);
	}
	for (int i = 1; i <= N; i++)
		if (G[i].size() == 1) ans = max(ans, i);
	dfs(N);
	for (int i = 1; i <= N; i++)
		if (dep[i] == 0) ans = max(ans, i);
	for (int i = N - 1; i >= 1; i--) {
		if (!dep[i]) continue;
		int o = i;
		while (!vis[o] && o != N) {
			if (o == i) vis[o] += 1;
			else vis[o] += 2;
			o = fa[o];
		}
		vis[o] += 1;
		if (dep[o] == 0 || vis[o] > 2) {
			ans = max(ans, i);
			break;
		}
	}
	printf("%d\n", ans);
}
int main () {
#ifndef ONLINE_JUDGE
    freopen("cpp.in", "r", stdin);
	//freopen("cpp.out", "w", stdout);
#endif
	int T = 1; //T = gi();
	while (T--) {
		solve();
	}
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 5964kb

input:

4
1 2
1 3
1 4

output:

4

result:

ok single line: '4'

Test #2:

score: 0
Accepted
time: 2ms
memory: 6876kb

input:

5
1 5
5 3
3 4
4 2

output:

3

result:

ok single line: '3'

Test #3:

score: -100
Wrong Answer
time: 6ms
memory: 10152kb

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'