Submission #447125

# Submission time Handle Problem Language Result Execution time Memory
447125 2021-07-24T16:16:12 Z MOUF_MAHMALAT Pastiri (COI20_pastiri) C++11
0 / 100
582 ms 59428 KB
#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];
pll op[500009];
vector<vector<ll> >v;
queue<pll>q;
vector<ll>ans;
bool b[500009];

void dfs(ll u,ll p)
{
    h[u]=h[p]+1;
    for(auto z:v[u])
        if(z!=p)
            dfs(z,u);
}
bool cmp(ll xo,ll yo)
{
    return h[xo]>h[yo];
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    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]=1e9,op[i]= {1e9,1e9};
    for(ll i=1; i<=k; i++)
        scanf("%d",&a[i]),d[a[i]]=0,q.push({a[i],a[i]});
    dfs(1,0);
    while(!q.empty())
    {
        x=q.front().first;
        y=q.front().second;
        q.pop();
        op[y]=min(op[y], {h[x],x});
        for(auto z:v[x])
        {
            if(d[z]<d[x]+1)
                continue;
            d[z]=d[x]+1;
            q.push({z,y});
        }
    }
    sort(a+1,a+k+1,cmp);
    for(ll i=1; i<=k; i++)
    {
        if(b[op[a[i]].second])
            continue;
        b[op[a[i]].second]=1;
        ans.push_back(op[a[i]].second);
    }
    cout<<ans.size()<<endl;
    for(auto z:ans)
        cout<<z<<" ";
    return 0;
}

Compilation message

pastiri.cpp: In function 'int main()':
pastiri.cpp:29:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     scanf("%d%d",&n,&k);
      |     ~~~~~^~~~~~~~~~~~~~
pastiri.cpp:33:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |         scanf("%d%d",&x,&y);
      |         ~~~~~^~~~~~~~~~~~~~
pastiri.cpp:40:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |         scanf("%d",&a[i]),d[a[i]]=0,q.push({a[i],a[i]});
      |         ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 213 ms 58956 KB Output is correct
2 Incorrect 263 ms 59428 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 716 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 582 ms 37116 KB Output isn't correct
2 Halted 0 ms 0 KB -