QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#84491 | #5651. Parmigiana With Seafood | _slb | WA | 37ms | 12408kb | C++14 | 1.7kb | 2023-03-06 15:23:04 | 2023-03-06 15:24:48 |
Judging History
answer
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
namespace solve
{
const int maxn = 1e5 + 10;
vector<int> e[maxn];
inline void add(int x, int y) { e[x].push_back(y), e[y].push_back(x); }
int n;
int deg[maxn];
int col[maxn];
int mx[maxn];
int ans = 0;
void dfs(int x, int fa)
{
col[x] = col[fa] ^ 1;
for (int v : e[x])
if (v != fa)
dfs(v, x), mx[x] = max(mx[x], mx[v]);
if (col[x] == 0)
mx[x] = max(mx[x], x);
if (x == n || col[x] == 0)
return;
vector<int> a;
for (int v : e[x])
if (v != fa)
a.push_back(mx[v]);
sort(a.begin(), a.end());
if (a.size() >= 2)
ans = max(ans, a[a.size() - 2]);
}
void main()
{
cin >> n;
if (n % 2 == 0)
{
cout << n << endl;
return;
}
for (int i = 1, x, y; i < n; i++)
cin >> x >> y, add(x, y), deg[x]++, deg[y]++;
for (int i = 1; i <= n; i++)
if (deg[i] == 1)
ans = max(ans, i);
dfs(n, 0);
for (int i = 1; i <= n; i++)
if (col[i] == 0)
ans = max(ans, i);
vector<int> a;
for (int v : e[n])
if (mx[v] > 0)
a.push_back(mx[v]);
sort(a.begin(), a.end());
if (a.size() >= 3)
ans = max(ans, a[a.size() - 3]);
cout << ans << endl;
}
}
int main()
{
ios::sync_with_stdio(false), cin.tie(0);
int T = 1;
// cin >> T;
while (T--)
solve::main();
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 6792kb
input:
4 1 2 1 3 1 4
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 4ms
memory: 5628kb
input:
5 1 5 5 3 3 4 4 2
output:
3
result:
ok single line: '3'
Test #3:
score: 0
Accepted
time: 24ms
memory: 10460kb
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:
99925
result:
ok single line: '99925'
Test #4:
score: 0
Accepted
time: 37ms
memory: 12408kb
input:
99997 90325 59106 22545 8765 88871 37709 14739 95233 8778 29659 48110 57549 91258 76066 15724 65144 48244 87291 12076 94378 41946 96707 93645 12812 53817 34343 72097 94062 81212 263 78713 78150 6754 94906 20957 97539 59293 5018 77961 78090 57262 95225 79349 47902 99024 7869 10613 13728 61757 41090 4...
output:
85398
result:
ok single line: '85398'
Test #5:
score: -100
Wrong Answer
time: 24ms
memory: 10208kb
input:
97687 5206 6282 79497 65247 26426 93558 88096 86680 12934 32573 14514 39078 1619 40141 52678 92737 31478 91858 85427 62603 83477 53003 38500 72325 62910 10306 97005 13325 38472 67023 39728 18368 78232 5993 20560 1752 22173 38357 97114 10935 4680 13734 45188 13484 58025 44787 70778 20 11932 28511 416...
output:
96848
result:
wrong answer 1st lines differ - expected: '96849', found: '96848'