답안 #773696

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
773696 2023-07-05T07:52:14 Z vjudge1 Pastiri (COI20_pastiri) C++17
0 / 100
496 ms 63880 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];

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;
			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{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)printf("%d ",git[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);
      |   ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 143 ms 59672 KB Output is correct
2 Incorrect 220 ms 63880 KB Sheep 4883 not protected
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 12372 KB Sheep 3030 not protected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 12244 KB Sheep 58 not protected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 496 ms 51060 KB Sheep 54 not protected
2 Halted 0 ms 0 KB -