QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#84434 | #5651. Parmigiana With Seafood | Macesuted | WA | 52ms | 13192kb | C++14 | 1.4kb | 2023-03-06 14:56:25 | 2023-03-06 14:57:52 |
Judging History
answer
/**
* @file 5651.cpp
* @author Macesuted ([email protected])
* @date 2023-03-06
*
* @copyright Copyright (c) 2023
*
*/
#include <bits/stdc++.h>
using namespace std;
#ifndef LOCAL
#define endl '\n'
#endif
bool mem1;
#define maxn 100005
vector<int> graph[maxn];
int deg[maxn], f[maxn][2];
int dfs(int p, int pre = 0) {
int ans = (graph[p].size() == 1 ? p : 0);
f[p][0] = p;
vector<int> rec;
for (auto i : graph[p])
if (i != pre) {
dfs(i, p);
f[p][0] = max(f[p][0], f[i][1]), f[p][1] = max(f[p][1], f[i][0]), rec.push_back(f[i][1]);
}
if (!pre) ans = max(ans, f[p][1]);
sort(rec.begin(), rec.end(), greater<int>());
while (rec.size() < 3) rec.push_back(0);
return max(ans, min({rec[0], rec[1], !pre ? rec[2] : INT_MAX}));
}
void solve(void) {
int n;
cin >> n;
if (!(n & 1)) return cout << n << endl, void();
for (int i = 1, x, y; i < n; i++) cin >> x >> y, graph[x].push_back(y), graph[y].push_back(x), deg[x]++, deg[y]++;
cout << dfs(n) << endl;
return;
}
bool mem2;
int main() {
ios::sync_with_stdio(false), cin.tie(nullptr);
#ifdef LOCAL
cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
#endif
int _ = 1;
while (_--) solve();
#ifdef LOCAL
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
#endif
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 6848kb
input:
4 1 2 1 3 1 4
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 1ms
memory: 5768kb
input:
5 1 5 5 3 3 4 4 2
output:
3
result:
ok single line: '3'
Test #3:
score: 0
Accepted
time: 40ms
memory: 10536kb
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: -100
Wrong Answer
time: 52ms
memory: 13192kb
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:
85396
result:
wrong answer 1st lines differ - expected: '85398', found: '85396'