# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
773739 |
2023-07-05T08:04:29 Z |
vjudge1 |
Pastiri (COI20_pastiri) |
C++17 |
|
597 ms |
57644 KB |
#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(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[i]==0)cev++;
}
printf("%d\n",cev);
FOR{
if(cevv[i]!=1000000000 && no[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
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 time |
Memory |
Grader output |
1 |
Correct |
185 ms |
53104 KB |
Output is correct |
2 |
Incorrect |
265 ms |
57644 KB |
Sheep 25 not protected |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
12372 KB |
Output is correct |
2 |
Correct |
10 ms |
12452 KB |
Output is correct |
3 |
Correct |
573 ms |
46448 KB |
Output is correct |
4 |
Incorrect |
449 ms |
50896 KB |
Sheep 99854 not protected |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
12244 KB |
Sheep 12 not protected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
597 ms |
44732 KB |
Sheep 470 not protected |
2 |
Halted |
0 ms |
0 KB |
- |