Submission #773717

#TimeUsernameProblemLanguageResultExecution timeMemory
773717blacktulipPastiri (COI20_pastiri)C++17
0 / 100
517 ms57260 KiB
#include <bits/stdc++.h> using namespace std; typedef long long lo; #define fi first #define se second #define endl "\n" #define pb push_back #define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define FOR for(int i=1;i<=n;i++) #define mid ((start+end)/2) #define ort ((bas+son)/2) const lo inf = 1000000000; const lo li = 500005; const lo mod = 1000000007; int n,m,a[li],k,flag,t,dep[li],dist[li],git[li],cevv[li],tut[li],no[li],tut2[li]; int cev; string s; vector<int> v[li],vv; inline int in(){ int x; cin>>x; return x; } inline void dfs(int node,int ata){ dep[node]=dep[ata]+1; for(auto go:v[node]){ if(go==ata)continue; dfs(go,node); } } int main(void){ scanf("%d %d",&n,&k); for(int i=1;i<n;i++){ int x,y; scanf("%d %d",&x,&y); v[x].pb(y); v[y].pb(x); } for(int i=1;i<=k;i++){ scanf("%d",&t); a[t]=1; } dfs(1,0); priority_queue<pair<int,pair<int,pair<int,int>>>> q; FOR{ cevv[i]=1000000000; if(a[i]){q.push({0,{dep[i],{i,i}}});} dist[i]=-1; } cev=0; while(q.size()){ int node=q.top().se.se.fi; int co=-q.top().fi; int depth=q.top().se.fi; int bas=q.top().se.se.se; q.pop(); if(no[bas])continue; if(dist[node]==-1){ dist[node]=co; tut[node]=depth; tut2[node]=bas; //~ cout<<node<<" :: "<<bas<<" :: "<<co<<" :: "<<depth<<endl; if(cevv[bas]>dep[node]){ cevv[bas]=dep[node]; git[bas]=node; } for(auto go:v[node]){ if(dist[go]==-1)q.push({-co-1,{depth,{go,bas}}}); } } else if(dist[node]==co){no[bas]=1;} } FOR{ if(cevv[i]!=1000000000 && no[tut2[i]]==0)cev++; } printf("%d\n",cev); FOR{ if(cevv[i]!=1000000000 && no[tut2[i]]==0)vv.pb(git[i]); } sort(vv.begin(),vv.end()); for(int i=0;i<(int)vv.size();i++){ printf("%d ",vv[i]); } return 0; }

Compilation message (stderr)

pastiri.cpp: In function 'int main()':
pastiri.cpp:40:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |  scanf("%d %d",&n,&k);
      |  ~~~~~^~~~~~~~~~~~~~~
pastiri.cpp:43:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |   scanf("%d %d",&x,&y);
      |   ~~~~~^~~~~~~~~~~~~~~
pastiri.cpp:48:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |   scanf("%d",&t);
      |   ~~~~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...