Submission #1064818

# Submission time Handle Problem Language Result Execution time Memory
1064818 2024-08-18T18:11:21 Z Osplei Stations (IOI20_stations) C++17
0 / 100
766 ms 26540 KB
#include "stations.h"
#include <bits/stdc++.h>

using namespace std;

#define pb push_back

bool bfs (int nodo, int obj){
  bool visto[1000005];
  queue <int> q;

  for (int i = 0; i < 1000005; i++) visto[i] = false;

  q.push(nodo);

  while (!q.empty()){
    int act = q.front();
    if (act == obj) return true;
    q.pop();

    if (visto[act] == true) continue;

    visto[act] = true;

    if (act != 0) q.push((act - 1) / 2);
    q.push((act * 2) + 1);
    q.push((act * 2) + 2);
  }

  return false;
}

vector <int> label(int n, int k, vector <int> u, vector <int> v) {
	
  vector <int> grafo[1000005];

  for (int i = 0; i < u.size(); i++) {
    int a = u[i], b = v[i];

    grafo[a].pb(b);
    grafo[b].pb(a);
  }

  /*

  for (int i = 0; i < n; i++){
    if (grafo[i].size() == 1){
      vector <int> labels = bfs(n, i, grafo);
      //for (auto j : labels) cout << j << " ";
      return labels;
    }
  }

  */

  vector <int> labels;

  for (int i = 0; i < n; i++) labels.pb(i);

  return labels;
	
}

int find_next_station(int s, int t, vector <int> c) {

  if (c.size() == 1) return c[0];

  if (t < s) return (s - 1) / 2;
  for (auto i : c) {
    if (bfs(i, t) == true) return i;
  }

}

/*

int main(){
  label(5, 10, {0, 3, 4, 2}, {1, 4, 0, 1});
}

*/

Compilation message

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:37:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |   for (int i = 0; i < u.size(); i++) {
      |                   ~~^~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:73:1: warning: control reaches end of non-void function [-Wreturn-type]
   73 | }
      | ^
# Verdict Execution time Memory Grader output
1 Runtime error 30 ms 26232 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 32 ms 26540 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 31 ms 26540 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 628 ms 24256 KB Output is correct
2 Incorrect 766 ms 25260 KB Wrong query response.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 32 ms 26284 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -