Submission #1114289

# Submission time Handle Problem Language Result Execution time Memory
1114289 2024-11-18T13:28:26 Z Dan4Life Synchronization (JOI13_synchronization) C++17
0 / 100
101 ms 57940 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)5e5+10;
int n, m, q;
vector<int> adj[N];
vector<ar2> edges;
set<int> S[N];
int tim[N], dfs_timer;
int e[N], r[N];

void dfs(int s, int p){
	tim[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;
		adj[a].pb(b); adj[b].pb(a);
		edges.pb({a,b});
	}
	for(int i = 1; i <= m; i++) cin >> e[i];
	for(int i = 1; i <= q; i++) cin >> r[i];
	dfs(r[1],0);
	for(int i = 1; i <= m; i++){
		auto [a,b] = edges[e[i]-1];
		if(tim[a]<tim[b])swap(a,b);
		S[a].insert(i);
	}
	S[r[1]].insert(m+1);
	cout << dfs2(r[1],-1,*prev(end(S[r[1]]))) << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 39248 KB Output is correct
2 Correct 7 ms 39324 KB Output is correct
3 Incorrect 7 ms 39248 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 65 ms 57940 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 39300 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 101 ms 57276 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 37200 KB Output isn't correct
2 Halted 0 ms 0 KB -