# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
759010 |
2023-06-15T16:41:38 Z |
Ronin13 |
Pastiri (COI20_pastiri) |
C++14 |
|
49 ms |
25292 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 = 200001;
int x[nmax], d[nmax];
bool active[nmax];
int dp[nmax];
vector <vector <int> > g(nmax);
void dfs(int v, int e = -1){
for(int to : g[v]){
if(to == e) continue;
dfs(to, v);
d[v] = min(d[v], d[to] + 1);
}
}
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(v == 1 && active[v]){
if(dp[v] >= d[v]) return;
ans.pb(v);
dp[v] = 0;
return;
}
if(!active[v])
return;
if(d[e] == x[e] && d[e] == d[v] + 1){
return;
}
if(dp[v] >= d[v])
return;
dp[v] = d[v];
active[v] = false;
ans.pb(v);
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
int n; cin >> n;
int k; cin >> k;
for(int i = 1; i < n; i++){
int u, v; cin >> 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; cin >> 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);
cout << ans.size() << "\n";
for(int to : ans)
cout << to << ' ';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
49 ms |
25292 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
5204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
5076 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
7 ms |
10040 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |