QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#793695 | #8716. 树 | HHCY# | WA | 0ms | 8184kb | C++20 | 1.6kb | 2024-11-29 22:58:29 | 2024-11-29 22:58:31 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
const int N=2e5+5;
int n,m,qsn,ne[N],b[N],ans,la[N];
int dep[N],fa[N][22],lg;
vector<int> G[N];
void dfs(int x,int y){
dep[x]=dep[y]+1,fa[x][0]=y;
for(int i=1;dep[x]-(1<<i)>=1;++i)
fa[x][i]=fa[fa[x][i-1]][i-1];
for(auto&i:G[x])
if(i!=y)
dfs(i,x);
}
int lca(int x,int y){
if(dep[x]<dep[y])swap(x,y);
for(int i=0;dep[x]^dep[y];++i)if((dep[x]-dep[y])&(1<<i))x=fa[x][i];
if(x==y)return x;
for(int i=lg;i>=0;--i)if(fa[x][i]!=fa[y][i])x=fa[x][i],y=fa[y][i];
return fa[x][0];
}
int hs(int x,int y,int z){
int xz=lca(x,z);
if(lca(y,xz)!=xz)return 1;
if(lca(x,y)==y)return 0;
if(lca(z,y)==y)return 0;
return 1;
}
void work(int a0,int a1,int b0,int b1){
if((a0==a1)==(b0==b1))return;
if(a0==a1)--ans;
else ++ans;
}
int main()
{
//ios::sync_with_stdio(false);
//cin.tie(0);cout.tie(0);
scanf("%d%d%d",&n,&m,&qsn);
lg=log(n)/log(2)+1;
for(int i=1;i<n;++i){
int x,y;scanf("%d%d",&x,&y);
G[x].pb(y),G[y].pb(x);
}
dfs(1,0);
for(int i=1;i<=m;++i)scanf("%d",&b[i]);
ans=2;
for(int i=2;i<n;++i)ans+=hs(b[i-1],b[i],b[i+1]);
while(qsn--)
{
int p,w;scanf("%d%d",&p,&w);
if(m==1){printf("1\n");continue;}
if(p>2)
ans+=hs(b[p-2],b[p-1],w)-hs(b[p-2],b[p-1],b[p]);
if(p>1&&p<n)
ans+=hs(b[p-1],w,b[p+1])-hs(b[p-1],b[p],b[p+1]);
if(p<n-1)
ans+=hs(w,b[p+1],b[p+2])-hs(b[p],b[p+1],b[p+2]);
b[p]=w;
printf("%d\n",ans);
}
return 0;
}
/*
modify i
change ne[i],ne[i-1]
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 8184kb
input:
5 5 3 2 1 3 2 1 4 5 1 1 5 4 2 3 1 3 5 3 3 3
output:
4 4 5
result:
ok 3 number(s): "4 4 5"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 8060kb
input:
30 200 200 10 24 10 13 10 26 13 29 27 26 17 24 27 21 17 15 13 5 13 30 27 3 18 21 9 21 2 24 10 4 11 5 2 8 10 23 1 18 21 25 4 20 12 23 22 27 28 27 18 7 13 6 14 30 10 19 16 21 14 29 25 30 1 17 22 21 11 19 21 30 13 1 22 10 14 7 29 7 15 21 25 29 25 7 29 7 1 23 3 17 2 7 4 27 18 26 3 6 5 3 16 26 20 19 16 2...
output:
27 28 28 28 28 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 28 28 29 29 29 29 29 29 29 29 29 28 28 28 29 29 29 29 29 30 30 30 30 30 30 30 30 30 30 30 30 30 31 31 31 31 31 31 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 31 31 31 31 31 ...
result:
wrong answer 1st numbers differ - expected: '174', found: '27'