Submission #1004293

# Submission time Handle Problem Language Result Execution time Memory
1004293 2024-06-21T07:17:26 Z vjudge1 Pastiri (COI20_pastiri) C++17
8 / 100
308 ms 51908 KB
#include<bits/stdc++.h>

using namespace std;

const int N = 5e5+5;
int n, k, dist[N], in[N];
vector<int> s, G[N], P[N], ans;

void bfs()
{
  queue<int> Q;
  for(int i = 1; i <= n; i ++) dist[i] = N + 20;
  for(int i : s)
    dist[i] = 0, Q.push(i);

  while(Q.size())
    {
      int u = Q.front();
      Q.pop();
      for(int  v: G[u])
	if(dist[u] + 1 <= dist[v])
	  {
	    P[v].push_back(u);
	    in[u]++;
	    	    
	    if(dist[v] > dist[u] + 1)
	      {
		dist[v] = dist[u] + 1;
		Q.push(v);
	      }
	  }
    }
}

void solve()
{
  queue<int> Q;
  for(int i = 1; i <= n; i ++)
    if(in[i] == 0)
      Q.push(i);

  while(Q.size())
    {
      int u = Q.front();
      Q.pop();
      if(P[u].size() == 1)
	{
	  in[P[u][0]]--;
	  if(in[P[u][0]] == 0)
	    Q.push(P[u][0]);
	}
      else
	ans.push_back(u);
    }
}

int main()
{
  cin >> n >> k;

  for(int i = 1; i < n; i ++)
    {
      int u, v;
      cin >> u >> v;
      G[u].push_back(v);
      G[v].push_back(u);
    }
  
  s.resize(k);
  for(int i = 0; i < k; i ++)
    cin >> s[i];

  sort(s.begin(), s.end());
  int cnt = 0;
  for(int i = 0; i < s.size(); i ++)
    {
      cnt++;
      if(i + 1 < s.size() && (s[i + 1] - s[i]) % 2 == 0) {
	ans.push_back((s[i + 1] + s[i]) / 2);
	i++;
      }
      else
	ans.push_back(s[i]);
    }

  cout << cnt << endl;
  for(int i : ans) cout << i << ' ';
  cout << endl;
  return 0;
  bfs();
  solve();
  
  cout << ans.size() << endl;
  for(int v : ans) cout << v << ' ';
  cout << endl;
  
  return 0;
}

Compilation message

pastiri.cpp: In function 'int main()':
pastiri.cpp:75:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |   for(int i = 0; i < s.size(); i ++)
      |                  ~~^~~~~~~~~~
pastiri.cpp:78:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |       if(i + 1 < s.size() && (s[i + 1] - s[i]) % 2 == 0) {
      |          ~~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 185 ms 46160 KB Output is correct
2 Correct 201 ms 45952 KB Output is correct
3 Correct 212 ms 46108 KB Output is correct
4 Correct 308 ms 51908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 23900 KB Sheep 3030 not protected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 23900 KB Sheep 128 not protected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 295 ms 44112 KB Sheep 54 not protected
2 Halted 0 ms 0 KB -