QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#417831 | #8716. 树 | UserKei | WA | 2ms | 7704kb | C++20 | 1.6kb | 2024-05-22 23:05:17 | 2024-05-22 23:05:17 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
using i64=long long;
const int M1=998244353;
const int M2=1000000007;
const int M3=1610612741;
using ll=long long;
using PII=pair<int,int>;
const int N=2e5+10;
int n,m,q;
int a[N],b[N],f[N][31],dep[N];
vector<int>path[N];
void dfs(int u,int pr){
dep[u]=dep[pr]+1;
f[u][0]=pr;
for(int i=1;i<=__lg(dep[u]);i++)
f[u][i]=f[f[u][i-1]][i-1];
for(auto v:path[u]){
if(v==pr)continue;
dfs(v,u);
}
}
int lca(int x,int y){
if(dep[x]>dep[y])swap(x,y);
while(dep[x]!=dep[y]){
y=f[y][__lg(dep[y]-dep[x])];
}
if(x==y){
return x;
}
for(int i=__lg(dep[x]);i>=0;i--){
if(f[x][i]!=f[y][i]){
x=f[x][i],y=f[y][i];
}
}
return f[x][0];
}
int dist(int x,int y){
return dep[x]+dep[y]-2LL*dep[lca(x,y)];
}
int upd(int x){
return dist(a[x],a[x+1])+dist(a[x+1],a[x+2])!=dist(a[x],a[x+2]);
}
void kei(){
cin>>n>>m>>q;
for(int i=1;i<n;i++){
int u,v;
cin>>u>>v;
path[u].push_back(v),path[v].push_back(u);
}
dfs(1,0);
for(int i=1;i<=m;i++)cin>>a[i];
int res=2;
for(int i=1;i<=m-2;i++)res+=upd(i);
while(q--){
int p,w;
cin>>p>>w;
for(int i=p;i<=min(p,m-2);i++)res-=upd(i);
a[p]=w;
for(int i=p;i<=min(p,m-2);i++)res+=upd(i);
cout<<(m==1?1:res)<<'\n';
}
}
signed main(){
// srand(time(0));
cin.tie(nullptr)->ios::sync_with_stdio(false);
int tt=1;
// cin>>tt;
while(tt--)kei();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 7624kb
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: 2ms
memory: 7704kb
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:
174 174 174 174 174 174 174 174 174 174 175 175 175 175 175 175 175 175 175 175 175 175 175 175 175 175 175 175 175 175 175 175 175 176 176 176 176 176 176 176 176 176 176 176 176 176 175 175 175 174 174 174 174 174 174 174 174 174 174 174 174 174 174 174 174 174 174 175 175 176 176 176 176 176 175 ...
result:
wrong answer 2nd numbers differ - expected: '175', found: '174'