QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#446931 | #8716. 树 | 275307894a# | WA | 3ms | 8736kb | C++14 | 2.1kb | 2024-06-17 18:22:37 | 2024-06-17 18:22:38 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=2e5+5,M=N*4+5,K=1000+5,mod=1e9+7,Mod=mod-1;const db eps=1e-9;const ll INF=1e18+7;mt19937 rnd(time(0));
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
#ifdef LOCAL
#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
#else
#define gdb(...) void()
#endif
}using namespace Debug;
int n,m,q;vector<int> S[N];
int fa[N],d[N],siz[N],son[N],tp[N];
void dfs1(int x,int La){
fa[x]=La;siz[x]=1;d[x]=d[La]+1;
for(int i:S[x]) if(i^La) dfs1(i,x),siz[x]+=siz[i],siz[i]>siz[son[x]]&&(son[x]=i);
}
void dfs2(int x,int La){
tp[x]=La;if(son[x]) dfs2(son[x],La);
for(int i:S[x]) if(i^fa[x]&&i^son[x]) dfs2(i,i);
}
int LCA(int x,int y){
while(tp[x]^tp[y]){
if(d[tp[x]]<d[tp[y]]) swap(x,y);
x=fa[tp[x]];
}
return d[x]<d[y]?x:y;
}
int B[N];
int dist(int x,int y){return d[x]+d[y]-2*d[LCA(x,y)];}
int calc(int x){
return dist(B[x-1],B[x])+dist(B[x],B[x+1])==dist(B[x-1],B[x+1]);
}
void Solve(){
int i,j;scanf("%d%d%d",&n,&m,&q);
for(i=1;i<n;i++){
int x,y;scanf("%d%d",&x,&y);
S[x].push_back(y);S[y].push_back(x);
}
dfs1(1,0);dfs2(1,1);
for(i=1;i<=m;i++) scanf("%d",&B[i]);
int cnt=0;
for(i=2;i<n;i++) cnt+=calc(i);
while(q--){
int x,y;scanf("%d%d",&x,&y);
for(int i=x-1;i<=x+1;i++) if(1<i&&i<n) cnt-=calc(i);
B[x]=y;
for(int i=x-1;i<=x+1;i++) if(1<i&&i<n) cnt+=calc(i);
printf("%d\n",m-cnt);
}
}
int main(){
int t=1;
// scanf("%d",&t);
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 8732kb
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: 3ms
memory: 8736kb
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:
197 197 197 197 197 197 197 197 197 197 197 197 197 197 197 197 197 197 197 197 197 197 197 197 197 197 197 197 197 197 197 196 196 197 197 197 197 197 197 197 197 197 197 197 197 197 197 197 197 197 197 197 197 197 197 197 197 197 197 197 197 197 197 197 197 197 197 197 197 197 197 197 197 197 197 ...
result:
wrong answer 1st numbers differ - expected: '174', found: '197'