QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#84495 | #5651. Parmigiana With Seafood | Shukuang | WA | 3ms | 5656kb | C++14 | 1.0kb | 2023-03-06 15:24:00 | 2023-03-06 15:25:36 |
Judging History
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;
}
详细
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'