QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#449909 | #8716. 树 | JEdward | WA | 2ms | 15412kb | C++14 | 2.8kb | 2024-06-21 19:05:58 | 2024-06-21 19:05:59 |
Judging History
answer
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0), cin.tie(0)
#define int long long
#define endl '\n'
#define lowbit(x) (x)&(-x)
#define pii pair<int,int>
#define all(s) s.begin(), s.end()
#define ls(x) (x<<1)
#define rs(x) (x<<1|1)
#define here system("pause")
using namespace std;
const int N = 2e5+5;
const int mod = 1e9+7;
const int INF = 1e15+7;
const double eps = 1e-6;
inline int pow(int a, int b, int p){ int res = 1%p; while(b){ if(b&1) res=res*a%p; a=a*a%p, b>>=1;} return res;}
inline int inv(int a, int p){ return pow(a,p-2,p)%p;}
int n, m, q;
vector<int> g[N];
int b[N], ok[N];
int f[N][20], dep[N];
inline void dfs(int u, int fa){
f[u][0] = fa;
dep[u] = dep[fa] + 1;
for(int i=1;i<20 && f[u][i-1];i++){
f[u][i] = f[f[u][i-1]][i];
}
for(auto v:g[u]){
if(v==fa) continue;
dfs(v, u);
}
}
inline int getlca(int u, int v){
if(dep[u]<dep[v]) swap(u, v);
for(int i=19;i>=0;i--){
if(dep[f[u][i]]>=dep[v]) u = f[u][i];
}
if(u==v) return u;
for(int i=19;i>=0;i--){
if(f[u][i]!=f[v][i]) u = f[u][i], v = f[v][i];
}
return f[v][0];
}
inline int check(int i){ //共链返回0
int x = b[i-1], y = b[i], z = b[i+1];
if(x==z) return 1;
if(getlca(x, y)==y || getlca(y, z)==y) return 0;
else return 1;
}
inline void sol(){
cin >> n >> m >> q;
for(int i=1;i<n;i++){
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
dfs(1, 0);
for(int i=1;i<=m;i++) cin >> b[i];
for(int i=2;i<n;i++){
ok[i] = check(i);
}
int ans = accumulate(ok+1,ok+1+n,0LL);
while(q--){
int idx, now;
cin >> idx >> now;
b[idx] = now;
if(idx==1){
int delta = ok[2];
ok[2] = check(2);
delta -= ok[2];
ans -= delta;
}else if(idx==n){
int delta = ok[n-1];
ok[n-1] = check(n-1);
delta -= ok[n-1];
ans -= delta;
}else if(idx==2){
int delta = ok[2];
ok[2] = check(2);
delta -= ok[2];
ans -= delta;
delta = ok[3];
ok[3] = check(3);
delta -= ok[3];
ans -= delta;
}else if(idx==n-1){
int delta = ok[n-1];
ok[n-1] = check(n-1);
delta -= ok[n-1];
ans -= delta;
delta = ok[n-2];
ok[n-2] = check(n-2);
delta -= ok[n-2];
ans -= delta;
}else{
int delta = ok[idx-1];
ok[idx-1] = check(idx-1);
delta -= ok[idx-1];
ans -= delta;
delta = ok[idx];
ok[idx] = check(idx);
delta -= ok[idx];
ans -= delta;
delta = ok[idx+1];
ok[idx+1] = check(idx+1);
delta -= ok[idx+1];
ans -= delta;
}
// for(int i=1;i<=n;i++){
// cerr << " " << b[i];
// }cout << endl;
// for(int i=1;i<=n;i++){
// cerr << " " << ok[i];
// }cerr << endl;
cout << ans+2 << endl;
}
}
signed main(){
IOS;
int tc = 1;
while(tc--){
sol();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 11976kb
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: 15412kb
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:
28 31 33 33 36 38 38 41 43 45 47 50 52 55 58 60 62 65 67 67 70 73 76 78 80 82 85 86 88 91 91 91 92 92 95 98 98 100 103 103 103 106 107 108 111 112 114 116 117 116 116 117 119 119 119 120 120 120 123 125 125 128 131 131 131 132 132 135 134 137 138 138 138 138 137 140 140 140 140 143 144 144 147 149 1...
result:
wrong answer 1st numbers differ - expected: '174', found: '28'