# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
412056 | 2021-05-26T12:49:14 Z | 송준혁(#7508) | Pastiri (COI20_pastiri) | C++17 | 719 ms | 36164 KB |
#include <bits/stdc++.h> #define fi first #define se second #define pb push_back #define lb lower_bound #define MOD 1000000007 #define INF (1ll<<62) using namespace std; typedef long long LL; typedef pair<int,int> pii; int N, K; int A[505050], D[505050]; bool chk[505050], vis[505050]; queue<int> Q; vector<int> adj[505050], ans; void del(int u){ vis[u] = true; for (int v : adj[u]) if (A[v] == A[u]-1) del(v); } int main(){ scanf("%d %d", &N, &K); if (N==1){ puts("1\n1"); return 0; } for (int i=1; i<N; i++){ int u, v; scanf("%d %d", &u, &v); adj[u].pb(v), adj[v].pb(u); D[u]++, D[v]++; } memset(A, -1, sizeof A); for (int i=1; i<=K; i++){ int x; scanf("%d", &x); chk[x] = true, Q.push(x), A[x] = 0; } while (Q.size()){ int u = Q.front(); Q.pop(); for (int v : adj[u]){ if (A[v]>=0) continue; A[v] = A[u]+1; Q.push(v); } } for (int i=1; i<=N; i++) if (D[i] == 1) Q.push(i); while (Q.size()){ int u = Q.front(); Q.pop(); for (int v : adj[u]){ D[v]--; if (D[v] == 1) Q.push(v); } if (vis[u] || !chk[u]) continue; bool tf = true; while (tf){ tf = false; for (int v : adj[u]){ if (!vis[v] && A[v] == A[u]+1){ u = v, tf = true; break; } } } ans.pb(u); del(u); } printf("%d\n", ans.size()); for (int u : ans) printf("%d ", u); printf("\n"); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 214 ms | 36164 KB | Output is correct |
2 | Incorrect | 244 ms | 32708 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 11 ms | 14348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 11 ms | 14188 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 719 ms | 33800 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |