Submission #1003812

# Submission time Handle Problem Language Result Execution time Memory
1003812 2024-06-20T18:18:13 Z vjudge1 Pastiri (COI20_pastiri) C++17
0 / 100
193 ms 40272 KB
#include <bits/stdc++.h>

using namespace std;

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

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

	for(int x : ans)q.push(x);
	while(!q.empty()){
		int x = q.front(); q.pop();
		for(int viz : adj[x])
			if(dist[viz] == dist[x]-1 && !marc[viz]){
				marc[viz] = 1;
				q.push(viz);
			}
	}

	for(int x : v)
		if(!marc[x])ans.push_back(x);

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

}

Compilation message

pastiri.cpp: In function 'int main()':
pastiri.cpp:62:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   62 |  for(int viz : ans)cout<<viz<<" "; cout<<"\n";
      |  ^~~
pastiri.cpp:62:36: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   62 |  for(int viz : ans)cout<<viz<<" "; cout<<"\n";
      |                                    ^~~~
# Verdict Execution time Memory Grader output
1 Correct 79 ms 31572 KB Output is correct
2 Incorrect 121 ms 40272 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 12380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 12120 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 193 ms 34388 KB Output isn't correct
2 Halted 0 ms 0 KB -