답안 #960885

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
960885 2024-04-11T07:31:41 Z pcc 동기화 (JOI13_synchronization) C++17
30 / 100
209 ms 68784 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>

const int mxn = 1e5+10;
int bit[mxn];
pii eul[mxn],edges[mxn];
int N,M,Q;
int dep[mxn];
vector<int> tree[mxn];
bitset<mxn> done;
int mv[mxn*2];
int rt;
int par[mxn][20];
int pt = 0;
multiset<int> st[mxn];

void modify(int p,int v){
	for(;p<mxn;p+=p&-p)bit[p] += v;
	return;
}
int getval(int p){
	int re = 0;
	for(;p>0;p-= p&-p)re += bit[p];
	return re;
}

void dfs(int now){
	eul[now].fs = ++pt;
	for(int i = 1;i<20;i++)par[now][i] = par[par[now][i-1]][i-1];
	for(auto nxt:tree[now]){
		if(nxt == par[now][0])continue;
		par[nxt][0] = now;
		dep[nxt] = dep[now]+1;
		dfs(nxt);
	}
	eul[now].sc = pt;
	return;
}

void change(int p){
	auto [a,b] = edges[p];
	if(dep[a]>dep[b])swap(a,b);
	if(done[p]){
		done[p] = false;
		modify(eul[b].fs,-1);
		modify(eul[b].sc+1,1);
		return;
	}
	done[p] = true;
	modify(eul[b].fs,1);
	modify(eul[b].sc+1,-1);
	int up = b;
	for(int i = 19;i>=0;i--){
		if(getval(eul[b].fs)-getval(eul[par[up][i]].fs) == dep[b]-dep[par[up][i]])up = par[up][i];
	}
	if(up == b)return;
	if(st[up].size()<st[b].size())st[up].swap(st[b]);
	for(auto &i:st[b])st[up].insert(i);
	st[b].clear();
	return;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>N>>M>>Q;
	for(int i = 1;i<N;i++){
		auto &[a,b] = edges[i];
		cin>>a>>b;
		tree[a].push_back(b);
		tree[b].push_back(a);
	}
	for(int i = 1;i<=M;i++)cin>>mv[i];
	while(Q--){
		cin>>rt;
		par[rt][0] = rt;
		dfs(rt);
		done.reset();
		for(int i = 1;i<=N;i++)st[i].clear();
		for(int i = 1;i<=N;i++)st[i].insert(i);
		for(int i = 1;i<=M;i++)change(mv[i]);
		cout<<st[rt].size()<<'\n';
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10840 KB Output is correct
2 Correct 2 ms 10844 KB Output is correct
3 Correct 2 ms 10844 KB Output is correct
4 Correct 2 ms 10840 KB Output is correct
5 Correct 3 ms 10844 KB Output is correct
6 Correct 3 ms 10844 KB Output is correct
7 Correct 13 ms 11824 KB Output is correct
8 Correct 13 ms 11612 KB Output is correct
9 Correct 16 ms 11612 KB Output is correct
10 Correct 167 ms 26392 KB Output is correct
11 Correct 154 ms 28692 KB Output is correct
12 Correct 168 ms 33092 KB Output is correct
13 Correct 147 ms 28420 KB Output is correct
14 Correct 179 ms 28896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 101 ms 30292 KB Output is correct
2 Correct 88 ms 30452 KB Output is correct
3 Correct 100 ms 35132 KB Output is correct
4 Correct 91 ms 34012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10844 KB Output is correct
2 Correct 2 ms 10844 KB Output is correct
3 Correct 8 ms 10844 KB Output is correct
4 Correct 8 ms 10840 KB Output is correct
5 Correct 6 ms 10840 KB Output is correct
6 Runtime error 82 ms 22664 KB Execution killed with signal 11
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 209 ms 68784 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10840 KB Output is correct
2 Correct 2 ms 10844 KB Output is correct
3 Correct 2 ms 10844 KB Output is correct
4 Correct 10 ms 10844 KB Output is correct
5 Runtime error 88 ms 22580 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -