QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#84538 | #5651. Parmigiana With Seafood | Shukuang | WA | 0ms | 5984kb | C++14 | 1.0kb | 2023-03-06 15:45:26 | 2023-03-06 15:45:59 |
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], 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'