QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#668489#8716. 树ucup-team4479#WA 2ms9704kbC++141.8kb2024-10-23 14:38:222024-10-23 14:38:22

Judging History

你现在查看的是最新测评结果

  • [2024-10-23 14:38:22]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:9704kb
  • [2024-10-23 14:38:22]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
constexpr int N=200005;
int n,m,q;
int b[N];
vector<int>G[N];
int dfn[N],siz[N],Index;
void dfs(int u,int father)
{
    dfn[u]=++Index;
    siz[u]=1;
    for(int v:G[u])
    {
        if(v==father) continue;
        dfs(v,u);
        siz[u]+=siz[v];
    }
    return;
}
bool inside(int u,int v)
{
    return dfn[u]<=dfn[v]&&dfn[v]<=dfn[u]+siz[u]-1;
}
int relation(int u,int v)
{
    if(inside(u,v)) return 0;
    else if(inside(v,u)) return 1;
    else return 0;
}
bool check(int a,int b,int c)
{
    if(a==0||c==0) return true;
    int ll=inside(b,a),rr=inside(b,c);
    return ll==rr;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr),cout.tie(nullptr);
    cin>>n>>m>>q;
    for(int i=1;i<n;i++)
    {
        int u,v;
        cin>>u>>v;
        G[u].emplace_back(v);
        G[v].emplace_back(u);
    }
    for(int i=1;i<=m;i++)
        cin>>b[i];
    dfs(1,0);
    int ans=1;
    for(int i=1;i<m;i++)
        if(check(b[i-1],b[i],b[i+1])) ans++;
    while(q--)
    {
        int i,w;
        cin>>i>>w;
        if(i+2<=m)
        {
            if(check(b[i],b[i+1],b[i+2])) ans--;
        }
        if(i+1<=m)
        {
            if(check(b[i-1],b[i],b[i+1])) ans--;
        }
        if(i-1>=1)
        {
            if(check(b[i-2],b[i-1],b[i])) ans--;
        }
        b[i]=w;
        if(i+2<=m)
        {
            if(check(b[i],b[i+1],b[i+2])) ans++;
        }
        if(i+1<=m)
        {
            if(check(b[i-1],b[i],b[i+1])) ans++;
        }
        if(i-1>=1)
        {
            if(check(b[i-2],b[i-1],b[i])) ans++;
        }
        cout<<ans<<"\n"; 
    }
    return 0;
}
 
 
 /*
 5 5 0
2 1
3 2
1 4
5 1
3 5 3 2 3
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 9704kb

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: 8768kb

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:

180
181
181
181
181
181
181
181
182
182
183
183
182
182
182
182
181
181
181
181
180
179
179
179
179
179
179
180
180
180
180
179
178
179
179
179
179
179
179
179
179
179
178
178
178
179
178
178
178
177
178
179
179
179
179
179
179
179
179
179
179
180
179
179
179
179
179
180
180
181
181
181
181
181
180
...

result:

wrong answer 1st numbers differ - expected: '174', found: '180'