Submission #446840

# Submission time Handle Problem Language Result Execution time Memory
446840 2021-07-23T13:07:26 Z MOUF_MAHMALAT Pastiri (COI20_pastiri) C++14
0 / 100
507 ms 36824 KB
#include<bits/stdc++.h>
#define all(s) s.begin(),s.end()
using namespace std;
typedef int ll;
ll n,k,x,y,p[500009],d[500009];
vector<vector<ll> >v;
queue<ll>q;
bool b[500009];
vector<ll>ans;
ll gp(ll z)
{
    if(p[z]==z)
        return z;
    return p[z]=gp(p[z]);
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>k;
    v.resize(n+1);
    for(ll i=1; i<n; i++)
    {
        cin>>x>>y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    for(ll i=1; i<=n; i++)
        p[i]=i,d[i]=1e9;
    while(k--)
    {
        cin>>x;
        d[x]=0;
        q.push(x);
    }
    while(!q.empty())
    {
        x=q.front();
        q.pop();
        for(auto z:v[x])
        {
            if(d[z]<d[x]+1)
                continue;
            p[x]=z;
            if(d[z]>d[x]+1)
            {
                d[z]=d[x]+1;
                q.push(z);
            }
        }
    }
    for(ll i=1; i<=n; i++)
    {
        x=gp(i);
        if(b[x])
            continue;
        b[x]=1;
        ans.push_back(x);
    }
    sort(all(ans));
    cout<<ans.size()<<endl;
    for(auto z:ans)
        cout<<z<<" ";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 183 ms 36824 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 460 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 507 ms 34416 KB Output isn't correct
2 Halted 0 ms 0 KB -