답안 #1114311

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1114311 2024-11-18T14:00:49 Z Dan4Life 동기화 (JOI13_synchronization) C++17
0 / 100
85 ms 36184 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) begin(a),end(a)
using ar2 = array<int,2>;
const int N = (int)2e5+10;
int n, m, q;
vector<int> adj[N];
vector<ar2> edges;
set<int> S[N];
int st[N], dfs_timer;
int e[N], r[N], active[N];

void dfs(int s, int p){
	st[s] = dfs_timer++;
	for(auto u : adj[s]){
		if(u==p) continue;
		dfs(u,s);
	}
}

int dfs2(int s, int p, int curT){
	int ans = 1;
	for(auto u : adj[s]){
		if(u==p) continue;
		auto itr = S[u].upper_bound(curT);
		if(itr==begin(S[u])) continue;
		itr--; ans+=dfs2(u,s,*itr);
	}
	return ans;
}

int32_t main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n >> m >> q;
	for(int i = 1; i < n; i++){
		int a, b; cin >> a >> b;
		a--, b--;
		adj[a].pb(b); adj[b].pb(a);
		edges.pb({a,b});
	}
	for(int i = 0; i < m; i++) cin >> e[i], e[i]--;
	for(int i = 0; i < q; i++) cin >> r[i], r[i]--;
	dfs(r[0],-1); S[r[0]].insert(m*2);
	for(int i = 0; i < m; i++){
		auto [a,b] = edges[e[i]];
		if(st[a]<st[b])swap(a,b);
		active[e[i]]^=1;
		if(!active[e[i]]) S[a].insert(i-1);
		else S[a].insert(i);
	}
	for(int i = 0; i < n-1; i++){
		auto [a,b] = edges[i];
		if(st[a]<st[b]) swap(a,b);
		if(active[i]) S[a].insert(m);
	}
	cout << dfs2(r[0],-1,*prev(end(S[r[0]]))) << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 17488 KB Output is correct
2 Correct 4 ms 17488 KB Output is correct
3 Incorrect 3 ms 17488 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 36184 KB Output is correct
2 Correct 70 ms 34236 KB Output is correct
3 Incorrect 46 ms 32532 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 15608 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 85 ms 34824 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 15440 KB Output isn't correct
2 Halted 0 ms 0 KB -