답안 #547912

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
547912 2022-04-12T02:49:36 Z Fysty 동기화 (JOI13_synchronization) C++17
0 / 100
138 ms 16700 KB
#include <bits/stdc++.h>
#include <random>
#include <chrono>
using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
//typedef pair<double,double> pdd;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

template<typename T> void _do(T x){cerr<<x<<"\n";}
template<typename T,typename ...U> void _do(T x,U ...y){cerr<<x<<", ";_do(y...);}
#define dbg(...) cerr<<#__VA_ARGS__<<" = ";_do(__VA_ARGS__);

const int MOD1=1e9+7;
const int MOD2=998244353;
const ll INF=3e18;
const ld PI=3.14159265358979323846;
ll gcd(ll a,ll b){if(b==0) return a; return gcd(b,a%b);}
ll fpow(ll a,ll b,ll m)
{
    if(!b) return 1;
    ll ans=fpow(a*a%m,b/2,m);
    return (b%2?ans*a%m:ans);
}
ll inv(ll a,ll m) {return fpow(a,m-2,m);}

#define MottoHayaku ios::sync_with_stdio(false);cin.tie(0);
//#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repk(i,m,n) for(int i=m;i<n;i++)
#define F first
#define S second
#define pb push_back
#define uni(c) c.resize(distance(c.begin(),unique(c.begin(),c.end())))
#define unisort(c) sort(c.begin(),c.end()),uni(c)
const int N=2e5+5;
vector<int> ed[N];
vector<pii> e;
int n,m,q,bit[N],tin[N],tout[N],an[N][20],ti=1;
int a[N],last[N];
bool state[N];
void upd(int x,int val)
{
    for(;x<=n;x+=x&-x) bit[x]+=val;
}
int qry(int x)
{
    int ret=0;
    for(;x;x-=x&-x) ret+=bit[x];
    return ret;
}
void dfs(int u,int p)
{
    tin[u]=ti++;
    an[0][u]=(p==0?u:p);
    for(int v:ed[u]) if(v!=p) dfs(v,u);
    tout[u]=ti;
}
int croot(int x)
{
    int r=x,tot=qry(tin[x]);
    for(int i=18;i>=0;i--)
    {
        if(qry(tin[an[i][r]])==tot) r=an[i][r];
    }
    return r;
}
signed main()
{
    MottoHayaku
    cin>>n>>m>>q;
    rep(i,n-1)
    {
        int u,v;
        cin>>u>>v;
        ed[u].pb(v);
        ed[v].pb(u);
        e.pb({u,v});
    }
    dfs(1,0);
    rep1(i,18) rep1(j,n) an[i][j]=an[i-1][an[i-1][j]];
    rep1(i,n)
    {
        a[i]=1;
        upd(tin[i],-1);
        upd(tout[i],1);
    }
    rep(i,m)
    {
        int id;
        cin>>id;
        id--;
        int u=e[id].F,v=e[id].S;
        if(an[0][u]==v) swap(u,v);
        if(state[id])
        {
            a[v]=last[v]=a[croot(u)];
            upd(tin[v],-1);
            upd(tout[v],1);
        }
        else
        {
            a[croot(u)]+=a[v]-last[v];
            upd(tin[v],1);
            upd(tout[v],-1);
        }
        state[id]=!state[id];
    }
    while(q--)
    {
        int u;
        cin>>u;
        cout<<a[croot(u)]<<"\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 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 5036 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 88 ms 14068 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Incorrect 3 ms 4948 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 138 ms 16700 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Incorrect 3 ms 4948 KB Output isn't correct
5 Halted 0 ms 0 KB -