답안 #1098807

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1098807 2024-10-10T03:10:31 Z Alihan_8 동기화 (JOI13_synchronization) C++17
20 / 100
33 ms 13376 KB
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define ar array

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int n, m, q; cin >> n >> m >> q;
	
	vector <int> X(n - 1), Y(n - 1);
	
	for ( int i = 0; i < n - 1; i++ ){
		cin >> X[i] >> Y[i];
		
		--X[i], --Y[i];
	}
	
	vector <int> state(n - 1), R(n - 1, -1), L(n - 1, m + 1);
	
	for ( int i = 0; i < m; i++ ){
		int x; cin >> x;
		
		--x;
		
		if ( L[x] == m + 1 ) L[x] = i;
		 
		R[x] = i;
		state[x] ^= 1;
	}
	
	for ( int i = 0; i < n - 1; i++ ){
		if ( state[i] > 0 ) R[i] = m;
	}
	
	auto calc = [&](int rt){
		vector <vector<ar<int,2>>> adj(n);
		
		for ( int i = 0; i < n - 1; i++ ){
			adj[X[i]].pb({Y[i], i});
			adj[Y[i]].pb({X[i], i});
		}
		
		auto dfs = [&](auto dfs, int u, int p, int r) -> int{
			int ret = 1;
			
			for ( auto &[v, j]: adj[u] ){
				if ( v != p ){
					if ( r > L[j] ){
						ret += dfs(dfs, v, u, min(r, R[j]));
					}
				} 
			}
			
			return ret;
		};
		
		return dfs(dfs, rt, -1, m);
	};
	
	assert(q == 1);
	
	while ( q-- ){
		int x; cin >> x;
		
		cout << calc(x - 1) << '\n';
	}
	
	cout << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 456 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 3 ms 1372 KB Output is correct
8 Incorrect 4 ms 1356 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 12240 KB Output is correct
2 Correct 30 ms 11048 KB Output is correct
3 Correct 27 ms 13376 KB Output is correct
4 Correct 29 ms 12884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 30 ms 6748 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -