답안 #701487

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
701487 2023-02-21T10:50:48 Z sugartheanh 동기화 (JOI13_synchronization) C++14
20 / 100
3522 ms 16424 KB
#include <bits/stdc++.h>
using namespace std;
 
#define dbg(x) cerr << #x << ": " << x << endl;
#define ii pair<int,int>
#define fi first
#define se second
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;
int n,m,q,first[N],last[N],d[N],root;
vector<ii>p[N];
bool on[N];
void dfs(int x,int u,int L,int R)
{
    for(auto v : p[u])
    {
        if(v.fi == x)
            continue;
        if(u == root)
        {
            dfs(u,v.fi,first[v.se],last[v.se]);
            d[u] += d[v.fi];
        }
        else
        {
            if(first[v.se] < R)
            {
                dfs(u,v.fi,L,R);
                d[u] += d[v.fi];
            }
        }
    }
}
int main() {
  
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n>>m>>q;
    for(int i = 1;i < n;i++)
    {
        int u,v;
        cin>>u>>v;
        p[u].push_back(ii(v,i));
        p[v].push_back(ii(u,i));
    }
    for(int i = 1;i <= n;i++)
        first[i] = 1e9;
    for(int i = 1;i <= m;i++)
    {
        int x;
        cin>>x;
        if(!on[x])
            first[x] = min(first[x], i);
        else
            last[x] = max(last[x], i);
        on[x] ^= 1;
    }
    for(int i = 1;i < n;i++)
    {
        if(first[i] > last[i])
            last[i] = 1e9;
    }
    while(q--)
    {
        cin>>root;
        for(int i = 1;i <= n;i++)
            d[i] = 1;
        dfs(0,root,0,0);
//        for(int i = 1;i <= n;i++)
//            cout<<i<<' '<<d[i]<<'\n';
        cout<<d[root]<<'\n';
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Incorrect 3 ms 4948 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 13628 KB Output is correct
2 Correct 37 ms 11788 KB Output is correct
3 Correct 36 ms 16424 KB Output is correct
4 Correct 36 ms 15416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3522 ms 9856 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Incorrect 2 ms 4948 KB Output isn't correct
3 Halted 0 ms 0 KB -