# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1004222 |
2024-06-21T06:33:08 Z |
vjudge1 |
Pastiri (COI20_pastiri) |
C++17 |
|
503 ms |
66232 KB |
#include<bits/stdc++.h>
using namespace std;
const int N = 5e5+5;
int n, k, dist[N], in[N];
vector<int> s, G[N], P[N], ans;
bool p[N], seen[N];
void bfs()
{
queue<int> Q;
for(int i = 1; i <= n; i ++) dist[i] = N + 20;
for(int i : s)
dist[i] = 0, Q.push(i), p[i] = true;
while(Q.size())
{
int u = Q.front();
Q.pop();
for(int v: G[u])
if(dist[u] + 1 <= dist[v])
{
P[v].push_back(u);
in[u]++;
if(dist[v] > dist[u] + 1)
{
dist[v] = dist[u] + 1;
Q.push(v);
}
}
}
}
void solve()
{
queue<int> Q;
for(int i = 1; i <= n; i ++)
if(in[i] == 0)
Q.push(i);
while(Q.size())
{
int u = Q.front();
Q.pop();
if(P[u].size() == 1)
{
in[P[u][0]]--;
if(in[P[u][0]] == 0)
Q.push(P[u][0]);
}
else
ans.push_back(u);
}
}
int main()
{
cin >> n >> k;
for(int i = 1; i < n; i ++)
{
int u, v;
cin >> u >> v;
G[u].push_back(v);
G[v].push_back(u);
}
s.resize(k);
for(int i = 0; i < k; i ++)
cin >> s[i];
bfs();
solve();
cout << ans.size() << endl;
for(int v : ans) cout << v << ' ';
cout << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
228 ms |
65620 KB |
Output is correct |
2 |
Incorrect |
304 ms |
66232 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
24152 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
23900 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
503 ms |
64660 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |