QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#288527 | #5651. Parmigiana With Seafood | Sorting# | WA | 1ms | 5924kb | C++20 | 1.2kb | 2023-12-22 20:40:02 | 2023-12-22 20:40:03 |
Judging History
answer
#include <iostream>
#include <vector>
#include <functional>
using namespace std;
const int N = 1e5 + 3;
vector<int> adj[N];
int n;
bool check(int mid){
int d = -1;
bool ok = true;
function<void(int, int, int)> dfs = [&](int u, int p, int depth){
if(u >= mid){
if(d == -1){
d = depth;
}
else{
if(d != depth){
ok = false;
}
}
}
for(int to: adj[u]){
if(to == p) continue;
dfs(to, u, depth ^ 1);
}
};
dfs(1, -1, 0);
return ok;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for(int i = 0; i < n - 1; ++i){
int x, y;
cin >> x >> y;
adj[x].push_back(y);
adj[y].push_back(x);
}
if(n % 2 == 0){
cout << n << "\n";
return 0;
}
int l = 1, r = n;
for(int i = 1; i <= n; ++i){
if(adj[i].size() == 1){
l = max(l, i);
}
}
while(l != r){
int mid = (l + r + 1) / 2;
if(check(mid)) l = mid;
else r = mid - 1;
}
cout << l << "\n";
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 5840kb
input:
4 1 2 1 3 1 4
output:
4
result:
ok single line: '4'
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 5924kb
input:
5 1 5 5 3 3 4 4 2
output:
5
result:
wrong answer 1st lines differ - expected: '3', found: '5'