# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
759060 | 2023-06-15T17:43:44 Z | Ronin13 | Pastiri (COI20_pastiri) | C++14 | 403 ms | 73228 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]; vector <vector <int> > g(nmax); vector <int> ans; void DFS(int v, int e = -1){ for(int to : g[v]){ if(to == e) continue; DFS(to, v); active[v] |= active[to]; dp[v] = max(dp[v], dp[to] - 1); } if(!active[v]) return; if(v == 1 && active[v]){ if(dp[v] >= x[v]) return; ans.pb(v); dp[v] = -1; return; } if(x[e] == x[v] + 1){ if(dp[v] >= d[v]) active[v] = false; return; } active[v] = false; if(dp[v] >= x[v]) return; dp[v] = d[v]; 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] = 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); DFS(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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 142 ms | 73064 KB | Output is correct |
2 | Incorrect | 167 ms | 73228 KB | Sheep 25 not protected |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 12244 KB | Output is correct |
2 | Correct | 7 ms | 12232 KB | Output is correct |
3 | Incorrect | 346 ms | 34824 KB | Sheep 147092 not protected |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 8 ms | 12116 KB | Sheep 12 not protected |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 403 ms | 35128 KB | Sheep 470 not protected |
2 | Halted | 0 ms | 0 KB | - |