# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
759065 | 2023-06-15T17:54:53 Z | Ronin13 | Pastiri (COI20_pastiri) | C++14 | 1000 ms | 76924 KB |
#include <bits/stdc++.h> #define ll long long #define ull unsigned ll #define f first #define s second #define pii pair<int,int> #define pll pair<ll,ll> #define pb push_back #define epb emplace_back using namespace std; const int nmax = 500001; int x[nmax], d[nmax]; bool active[nmax]; int dp[nmax]; int p[nmax]; vector <vector <int> > g(nmax); vector <int> ans; void DFS(int v, int e){ for(int to : g[v]){ if(to == e) continue; DFS(to, v); d[v] = max(d[v], d[to] + 1); dp[v] = max(dp[v], dp[to] - 1); } if(d[v] < 0) return; if(v == 1){ if(dp[v] >= d[v]) return; ans.pb(v); dp[v] = -1; return; } if(x[e] == d[v] + 1){ if(dp[v] >= d[v]) d[v] = -1e9; return; } if(dp[v] >= d[v]){ d[v] = -1e9; return; } dp[v] = d[v]; d[v] = -1e9; ans.pb(v); } int main(){ //ios_base::sync_with_stdio(false); cin.tie(0); int n, k; scanf("%d%d",&n, &k); for(int i = 1; i < n; i++){ int u, v; scanf("%d%d", &u, &v); g[u].pb(v); g[v].pb(u); } //int k; cin >> k; for(int i = 1; i <= n; i++){ x[i] = 1e9; d[i] = -1e9; dp[i] = -1e9; } queue <int> q; for(int i = 1; i <= k; ++i){ int y; scanf("%d", &y); q.push(y); active[y] = true; x[y] = d[y] = 0; } while(!q.empty()){ int v = q.front(); q.pop(); for(int to : g[v]){ if(x[to] <= x[v]) continue; x[to] = x[v] + 1; q.push(to); } } DFS(1, -1); printf("%d\n", ans.size()); //ans.size() << "\n"; sort(ans.begin(), ans.end()); for(int to : ans) printf("%d ", to); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 144 ms | 72652 KB | Output is correct |
2 | Correct | 186 ms | 73168 KB | Output is correct |
3 | Correct | 162 ms | 73064 KB | Output is correct |
4 | Correct | 234 ms | 76924 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 12244 KB | Output is correct |
2 | Correct | 8 ms | 12244 KB | Output is correct |
3 | Correct | 344 ms | 34448 KB | Output is correct |
4 | Correct | 339 ms | 38192 KB | Output is correct |
5 | Correct | 387 ms | 33736 KB | Output is correct |
6 | Correct | 444 ms | 37188 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 12116 KB | Output is correct |
2 | Correct | 7 ms | 12116 KB | Output is correct |
3 | Correct | 7 ms | 12128 KB | Output is correct |
4 | Correct | 7 ms | 12076 KB | Output is correct |
5 | Correct | 8 ms | 12140 KB | Output is correct |
6 | Correct | 7 ms | 12116 KB | Output is correct |
7 | Correct | 8 ms | 12160 KB | Output is correct |
8 | Correct | 6 ms | 12116 KB | Output is correct |
9 | Correct | 6 ms | 12116 KB | Output is correct |
10 | Correct | 6 ms | 12116 KB | Output is correct |
11 | Correct | 7 ms | 12244 KB | Output is correct |
12 | Correct | 6 ms | 12116 KB | Output is correct |
13 | Correct | 8 ms | 12888 KB | Output is correct |
14 | Correct | 6 ms | 12148 KB | Output is correct |
15 | Correct | 6 ms | 12116 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 382 ms | 35172 KB | Output is correct |
2 | Correct | 382 ms | 34984 KB | Output is correct |
3 | Correct | 467 ms | 36552 KB | Output is correct |
4 | Correct | 428 ms | 34076 KB | Output is correct |
5 | Execution timed out | 1069 ms | 31256 KB | Time limit exceeded |
6 | Halted | 0 ms | 0 KB | - |