이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define all(s) s.begin(),s.end()
using namespace std;
typedef int ll;
typedef pair<ll,ll>pll;
ll n,x,y,k,d[500009],a[500009],h[500009],c;
pll op[500009];
vector<vector<ll> >v;
queue<ll>q;
vector<ll>ans;
bool b[500009];
bool cmp(const ll&xo,const ll&yo)
{
    return h[xo]>h[yo];
}
struct node
{
    ll f,s,t;
};
queue<node>dq;
int main()
{
    scanf("%d%d",&n,&k);
    v.resize(n+1);
    for(ll i=1; i<n; i++)
    {
        scanf("%d%d",&x,&y);
        v[x].push_back(y);
        v[y].push_back(x);
    }
    for(ll i=1; i<=n; i++)
        d[i]=h[i]=1e9,op[i]= {1e9,1e9};
    h[1]=1;
    q.push(1);
    while(!q.empty())
    {
        x=q.front();
        q.pop();
        for(auto z:v[x])
            if(h[z]>h[x]+1)
            {
                h[z]=h[x]+1;
                q.push(z);
            }
    }
    for(ll i=1; i<=k; i++)
        scanf("%d",&a[i]),d[a[i]]=0,q.push(a[i]);
    while(!q.empty())
    {
        x=q.front();
        q.pop();
        for(auto z:v[x])
        {
            if(d[z]<=d[x]+1)
                continue;
            d[z]=d[x]+1;
            q.push(z);
        }
    }
    dq.push({1,0,1});
    while(!dq.empty())
    {
        x=dq.front().f;
        ll p=dq.front().s;
        ll id=dq.front().t;
        dq.pop();
        if(d[x]==0)
            op[x]= {h[id],id};
        for(auto z:v[x])
        {
            if(z==p)
                continue;
            if(d[x]==d[z]+1)
                dq.push({z,x,id});
            else
                dq.push({z,x,z});
        }
    }
    sort(a+1,a+k+1,cmp);
    for(ll i=1; i<=k; i++)
    {
        if(b[a[i]])
            continue;
        ans.push_back(op[a[i]].second);
        q.push(op[a[i]].second);
        while(!q.empty())
        {
            x=q.front();
            q.pop();
            b[x]=1;
            for(auto z:v[x])
                if(d[x]==d[z]+1&&b[z]==0)
                    q.push(z);
        }
    }
    x=ans.size();
    printf("%d\n",x);
    for(auto z:ans)
        printf("%d ",z);
    return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
pastiri.cpp: In function 'int main()':
pastiri.cpp:23:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |     scanf("%d%d",&n,&k);
      |     ~~~~~^~~~~~~~~~~~~~
pastiri.cpp:27:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         scanf("%d%d",&x,&y);
      |         ~~~~~^~~~~~~~~~~~~~
pastiri.cpp:47:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |         scanf("%d",&a[i]),d[a[i]]=0,q.push(a[i]);
      |         ~~~~~^~~~~~~~~~~~| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |