답안 #1003872

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1003872 2024-06-20T19:24:43 Z vjudge1 Pastiri (COI20_pastiri) C++17
0 / 100
163 ms 34384 KB
#include <bits/stdc++.h>

using namespace std;

#define sz(v) (int)v.size()
const int MAXN = 5*1e5+5;
vector<int> adj[MAXN];
set<int> ans;
queue<int> q;
int dist[MAXN], qtd[MAXN], l[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; qtd[x] = 0;
		q.push(x);
	}

	while(!q.empty()){
		int x = q.front(); q.pop();
		if(l[x] == 0){
			l[x] = x;
			ans.insert(x);
		}
		for(int viz : adj[x]){
			if(dist[viz] == dist[x]+1){
				qtd[viz]++;
				ans.erase(l[x]);
				if(qtd[viz] == 2){

					ans.erase(l[viz]);
					l[viz] = 0;
				}
			}

			if(dist[viz] == 0){
				dist[viz] = dist[x] + 1;
				qtd[viz] = 1;
				l[viz] = l[x];
				q.push(viz);
			}
		}
	}


	cout<<sz(ans)<<"\n";
	for(int viz : ans)cout<<viz<<" "; cout<<"\n";

}

Compilation message

pastiri.cpp: In function 'int main()':
pastiri.cpp:58:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   58 |  for(int viz : ans)cout<<viz<<" "; cout<<"\n";
      |  ^~~
pastiri.cpp:58:36: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   58 |  for(int viz : ans)cout<<viz<<" "; cout<<"\n";
      |                                    ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 93 ms 33684 KB Output is correct
2 Incorrect 119 ms 33620 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 18012 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 17756 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 163 ms 34384 KB Output isn't correct
2 Halted 0 ms 0 KB -