QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#123498 | #5651. Parmigiana With Seafood | zswzswzsw | WA | 66ms | 10604kb | C++14 | 1.3kb | 2023-07-12 17:45:14 | 2023-07-12 17:45:16 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=101000;
int n;
vector<int>G[N];
int dp[N],fdp[N],siz[N];
bool tg[N];
bool flg;
void DFS(int u,int f){
siz[u]=1;
for(int v:G[u]){
if(v==f)continue;
DFS(v,u);siz[u]+=siz[v];
if(dp[v]!=-1){
if(dp[u]==-1)dp[u]=dp[v];
else dp[u]^=dp[v];
}
}
if(tg[u]&&dp[u]==-1)dp[u]=(siz[u]&1);
return;
}
void DFS2(int u,int f){
int sum=0,tmp,cnt=0;
bool ff=1;
for(int v:G[u]){
if(v==f)continue;
if(dp[v]!=-1)sum^=dp[v],++cnt;
else ff=0;
}
if(fdp[u]==-1)ff=0;
for(int v:G[u]){
if(v==f)continue;
if(dp[v]!=-1)fdp[v]=sum^dp[v];
else fdp[v]=sum;
if(cnt==1)fdp[v]=-1;
if(fdp[u]!=-1)
if(fdp[v]==-1)fdp[v]=fdp[u];
else fdp[v]^=fdp[u];
if(fdp[v]==-1&&tg[u])fdp[v]=(n-siz[v])&1;
DFS2(v,u);
}
if(ff){
if(tg[u]&&dp[u]!=(siz[u]&1))flg=0;
if(sum&1)flg=0;
if(tg[f]&&fdp[u]!=((n-siz[u])&1))flg=0;
}
return;
}
bool chk(int t){
if(!(n&1))return 1;
for(int i=1;i<=n;i++)tg[i]=(i>=t);
for(int i=0;i<=n;i++)dp[i]=-1,fdp[i]=-1;
flg=1;DFS(1,0);if(!flg)return 1;
DFS2(1,0);if(!flg)return 1;
return 0;
}
int main()
{
cin>>n;
for(int i=1,x,y;i<=n-1;i++){
scanf("%d %d",&x,&y);
G[x].push_back(y);G[y].push_back(x);
}
int L=1,R=n;
while(L<R){
int mid=(L+R+1)>>1;
if(chk(mid))L=mid;
else R=mid-1;
}cout<<L;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 6324kb
input:
4 1 2 1 3 1 4
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 2ms
memory: 5956kb
input:
5 1 5 5 3 3 4 4 2
output:
3
result:
ok single line: '3'
Test #3:
score: -100
Wrong Answer
time: 66ms
memory: 10604kb
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:
99997
result:
wrong answer 1st lines differ - expected: '99925', found: '99997'