Submission #1064871

# Submission time Handle Problem Language Result Execution time Memory
1064871 2024-08-18T18:47:34 Z Osplei Stations (IOI20_stations) C++17
Compilation error
0 ms 0 KB
#include "stations.h"
#include <bits/stdc++.h>
     
using namespace std;
     
#define pb push_back
     
vector <int> bfs (int n, int nodo, vector <int> grafo[1000005]){
  vector <int> aux(n);
  bool visto[1000005];
  queue <pair <int, int>> q;
     
  for (int i = 0; i < 1000005; i++) visto[i] = false;
     
  q.push({nodo, 0});
  aux[nodo] = 0;

  while (!q.empty()){
    pair <int, int> act = q.front();
    q.pop();
      
    if (visto[act.first] == true) continue;
      
    visto[act.first] = true;
      
    if (grafo[act.first].size() <= 2){
      for (auto i : grafo[act.first]) {
        if (visto[i] != true){
          q.push({i, act.second});   
          aux[i] = act.first + 1 + act.second;
        }
      }
    } else {
      int auxi = 2000;
      aux[act.first] = 1e9;

      for (auto i : grafo[act]) {
        q.push({i, auxi});
        aux[i] = act.first + 1 + auxi;
        auxi += 2000;
      }
    }
  }
     
  return aux; 
}
     
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;
    }
  }
     
  return u;
    	
}
     
int find_next_station(int s, int t, vector <int> c) {
  int maxi = 1e9;
     
  if (c.size() == 1) return c[0];
    	
  if (s != maxi){

    if (t >= s + 2000 || t <= s + 2000) return min(c[0], c[1]);
    else {
      if (t > s) return max(c[0], c[1]);
      else return min(c[0], c[1]);
    }
    
  } else {
    for (auto i : c) {
      if (i + 2000 >= t && i <= t) return i;
    }
  }
}
     
    /*
     
    int main(){
      label(5, 10, {0, 3, 4, 2}, {1, 4, 0, 1});
    }
     
    */

Compilation message

stations.cpp: In function 'std::vector<int> bfs(int, int, std::vector<int>*)':
stations.cpp:37:26: error: no match for 'operator[]' (operand types are 'std::vector<int>*' and 'std::pair<int, int>')
   37 |       for (auto i : grafo[act]) {
      |                          ^
stations.cpp:38:25: error: no matching function for call to 'std::queue<std::pair<int, int> >::push(<brace-enclosed initializer list>)'
   38 |         q.push({i, auxi});
      |                         ^
In file included from /usr/include/c++/10/queue:64,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:86,
                 from stations.cpp:2:
/usr/include/c++/10/bits/stl_queue.h:265:7: note: candidate: 'void std::queue<_Tp, _Sequence>::push(const value_type&) [with _Tp = std::pair<int, int>; _Sequence = std::deque<std::pair<int, int>, std::allocator<std::pair<int, int> > >; std::queue<_Tp, _Sequence>::value_type = std::pair<int, int>]'
  265 |       push(const value_type& __x)
      |       ^~~~
/usr/include/c++/10/bits/stl_queue.h:265:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const std::pair<int, int>&'}
  265 |       push(const value_type& __x)
      |            ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_queue.h:270:7: note: candidate: 'void std::queue<_Tp, _Sequence>::push(std::queue<_Tp, _Sequence>::value_type&&) [with _Tp = std::pair<int, int>; _Sequence = std::deque<std::pair<int, int>, std::allocator<std::pair<int, int> > >; std::queue<_Tp, _Sequence>::value_type = std::pair<int, int>]'
  270 |       push(value_type&& __x)
      |       ^~~~
/usr/include/c++/10/bits/stl_queue.h:270:25: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::queue<std::pair<int, int> >::value_type&&' {aka 'std::pair<int, int>&&'}
  270 |       push(value_type&& __x)
      |            ~~~~~~~~~~~~~^~~
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:52:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |   for (int i = 0; i < u.size(); i++) {
      |                   ~~^~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:89:1: warning: control reaches end of non-void function [-Wreturn-type]
   89 | }
      | ^