Task PastiriTask Pastiri#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);
dq.push({op[a[i]].second,h[a[i]]-op[a[i]].first,0});
while(!dq.empty())
{
x=dq.front().f;
c=dq.front().s;
ll p=dq.front().t;
dq.pop();
b[x]=1;
if(c==0)
continue;
for(auto z:v[x])
if(z!=p)
dq.push({z,c-1,x});
}
}
cout<<ans.size()<<endl;
for(auto z:ans)
cout<<z<<" ";
return 0;
}
Compilation message
pastiri.cpp:1:25: error: stray '#' in program
1 | Task PastiriTask Pastiri#include<bits/stdc++.h>
| ^
pastiri.cpp:1:1: error: 'Task' does not name a type
1 | Task PastiriTask Pastiri#include<bits/stdc++.h>
| ^~~~
pastiri.cpp:5:9: error: 'pair' does not name a type
5 | typedef pair<ll,ll>pll;
| ^~~~
pastiri.cpp:7:1: error: 'pll' does not name a type; did you mean 'll'?
7 | pll op[500009];
| ^~~
| ll
pastiri.cpp:8:1: error: 'vector' does not name a type
8 | vector<vector<ll> >v;
| ^~~~~~
pastiri.cpp:9:1: error: 'queue' does not name a type
9 | queue<ll>q;
| ^~~~~
pastiri.cpp:10:1: error: 'vector' does not name a type
10 | vector<ll>ans;
| ^~~~~~
pastiri.cpp:20:1: error: 'queue' does not name a type
20 | queue<node>dq;
| ^~~~~
pastiri.cpp: In function 'int main()':
pastiri.cpp:23:5: error: 'scanf' was not declared in this scope
23 | scanf("%d%d",&n,&k);
| ^~~~~
pastiri.cpp:24:5: error: 'v' was not declared in this scope
24 | v.resize(n+1);
| ^
pastiri.cpp:32:23: error: 'op' was not declared in this scope
32 | d[i]=h[i]=1e9,op[i]= {1e9,1e9};
| ^~
pastiri.cpp:34:5: error: 'q' was not declared in this scope
34 | q.push(1);
| ^
pastiri.cpp:60:5: error: 'dq' was not declared in this scope; did you mean 'd'?
60 | dq.push({1,0,1});
| ^~
| d
pastiri.cpp:68:13: error: 'op' was not declared in this scope; did you mean 'p'?
68 | op[x]= {h[id],id};
| ^~
| p
pastiri.cpp:79:5: error: 'sort' was not declared in this scope; did you mean 'short'?
79 | sort(a+1,a+k+1,cmp);
| ^~~~
| short
pastiri.cpp:84:9: error: 'ans' was not declared in this scope
84 | ans.push_back(op[a[i]].second);
| ^~~
pastiri.cpp:84:23: error: 'op' was not declared in this scope
84 | ans.push_back(op[a[i]].second);
| ^~
pastiri.cpp:100:5: error: 'cout' was not declared in this scope
100 | cout<<ans.size()<<endl;
| ^~~~
pastiri.cpp:100:11: error: 'ans' was not declared in this scope
100 | cout<<ans.size()<<endl;
| ^~~
pastiri.cpp:100:23: error: 'endl' was not declared in this scope
100 | cout<<ans.size()<<endl;
| ^~~~