QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#413871 | #5651. Parmigiana With Seafood | thesupermarketisgoingtome# | WA | 122ms | 12068kb | C++17 | 1.9kb | 2024-05-18 10:56:28 | 2024-05-18 10:56:29 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mxn = 100005;
vector<vector<int>>adj(mxn);
vector<int>good(mxn);
void dfs(int u, int p){
for(int nxt: adj[u]){
if(nxt==p)continue;
dfs(nxt,u);
if(good[nxt])good[u] = 1;
}
}
void reset(int n){
for(int i = 1; i<=n; i++){
good[i] = 0;
}
}
signed main(){
cin.tie(nullptr)->sync_with_stdio(false);
int n;
cin >> n;
for(int i = 1; i<n; i++){
int x,y;
cin >> x >> y;
adj[x].push_back(y);
adj[y].push_back(x);
}
vector<int>dis(n+1);
vector<bool>vis(n+1);
queue<int>q;
q.push(1);
vis[1] = true;
while(q.size()){
int cur = q.front(); q.pop();
for(int nxt: adj[cur]){
if(vis[nxt])continue;
dis[nxt] = dis[cur]^1;
vis[nxt] = true;
q.push(nxt);
}
}
if(n%2==0){
cout << n << '\n';
return 0;
}
int low = 0; int high = n+1;
while(low + 1 < high){
int mid = (low+high)/2;
set<int>s;
for(int i = mid; i<=n; i++){
s.insert(dis[i]);
}
bool bad = false;
if(s.size() == 2){
bad = true;
}
for(int i = mid; i<=n; i++){
if(adj[i].size() == 1){
bad = true;
}
good[i] = 1;
}
dfs(n,0);
for(int i = mid; i<=n; i++){
int cnt = 0;
for(int nxt: adj[i]){
if(good[nxt]){
cnt++;
}
}
if(cnt>=3){
bad = true;
}
}
if(bad){
low = mid;
}
else{
high = mid;
}
reset(n);
}
cout << low << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 6172kb
input:
4 1 2 1 3 1 4
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 0ms
memory: 6020kb
input:
5 1 5 5 3 3 4 4 2
output:
3
result:
ok single line: '3'
Test #3:
score: 0
Accepted
time: 41ms
memory: 11588kb
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: 122ms
memory: 12068kb
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: 0
Accepted
time: 42ms
memory: 11604kb
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:
96849
result:
ok single line: '96849'
Test #6:
score: 0
Accepted
time: 42ms
memory: 10664kb
input:
84671 62167 4590 83269 18308 7577 37508 52720 9931 12966 65554 23617 73916 76954 20353 72074 331 3246 58164 41679 28021 41713 36414 53221 77575 53398 66400 21562 16390 11317 20458 70409 48081 43608 84144 4665 70292 65863 62926 53700 32839 82581 18581 56748 30899 75093 58023 10481 13121 60945 8777 26...
output:
84200
result:
ok single line: '84200'
Test #7:
score: 0
Accepted
time: 31ms
memory: 10240kb
input:
73167 47092 28182 66083 3885 43535 13437 54796 24969 69017 27959 4701 13449 69154 70617 71864 8320 65436 18607 63511 58647 49371 16640 57598 9646 69711 6405 44171 46975 10159 72030 72806 67302 70130 62361 61032 23019 22551 71530 15388 46131 2466 41213 7614 7234 7187 68699 69979 18867 73006 9719 7307...
output:
72317
result:
ok single line: '72317'
Test #8:
score: -100
Wrong Answer
time: 73ms
memory: 10392kb
input:
93127 82031 39720 66956 8709 23978 63403 6145 91337 85068 90000 5292 12192 75403 59013 61717 17385 31485 21675 59006 14085 89359 30804 37788 78960 3732 89293 22416 42721 82075 58210 66360 6744 52855 52426 54146 17777 36605 38752 39355 66859 9092 76915 53782 42274 3786 12113 56898 61989 41242 22010 8...
output:
91964
result:
wrong answer 1st lines differ - expected: '91965', found: '91964'