Submission #1003806

#TimeUsernameProblemLanguageResultExecution timeMemory
1003806vjudge1Pastiri (COI20_pastiri)C++17
0 / 100
202 ms32176 KiB
#include <bits/stdc++.h>

using namespace std;

#define sz(v) (int)v.size()
const int MAXN = 5*1e5+5;
vector<int> adj[MAXN], ans;
queue<int> q;
int dist[MAXN];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int n,k; cin>>n>>k;
	for(int i = 1; i < n; i++){
		int a,b; cin>>a>>b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}

	for(int i = 0; i < k; i++){
		int x; cin>>x;
		dist[x] = 1;
		q.push(x);
	}

	while(!q.empty()){
		int x = q.front(); q.pop();
		int b = 1;
		for(int viz : adj[x]){
			if(dist[viz] == dist[x]+1)b = 0;

			if(dist[viz] == 0){
				dist[viz] = dist[x] + 1;
				b = 0;
				q.push(viz);
			}
		}
		if(b)ans.push_back(x);
	}

	cout<<sz(ans)<<"\n";
	sort(ans.begin(),ans.end());
	for(int viz : ans)cout<<viz<<" "; cout<<"\n";

}

Compilation message (stderr)

pastiri.cpp: In function 'int main()':
pastiri.cpp:45:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   45 |  for(int viz : ans)cout<<viz<<" "; cout<<"\n";
      |  ^~~
pastiri.cpp:45:36: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   45 |  for(int viz : ans)cout<<viz<<" "; cout<<"\n";
      |                                    ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...