Submission #305292

# Submission time Handle Problem Language Result Execution time Memory
305292 2020-09-22T22:33:12 Z abeker Stations (IOI20_stations) C++17
0 / 100
1057 ms 1088 KB
#include <bits/stdc++.h>
#include "stations.h"
using namespace std;

typedef pair <int, int> pii;

vector <int> label(int N, int K, vector <int> u, vector <int> v) {
  vector <vector <int>> adj(N);
  for (int i = 0; i < N - 1; i++) {
    adj[u[i]].push_back(v[i]);
    adj[v[i]].push_back(u[i]);
  }
  int timer = 0;
  vector <pii> sorted;
  vector <int> labels(N);
  function <void(int, int, int)> dfs = [&](int x, int p, int d) {
    int disc = timer++;
    for (auto it : adj[x])
      if (it != p)
        dfs(it, x, d ^ 1);
    int fin = timer++;
    sorted.push_back({d ? fin : disc, x});
  };   
  dfs(0, -1, 0);
  sort(sorted.begin(), sorted.end());
  for (int i = 0; i < N; i++)
    labels[sorted[i].second] = i;
  return labels;
}

int find_next_station(int start, int dest, vector <int> neigh) { 
  if (start && start < neigh[0]) {
    int parent = neigh.back();
    neigh.insert(neigh.begin(), start);
    neigh.pop_back();
    for (int i = 1; i < neigh.size(); i++)
      if (dest > neigh[i - 1] && dest <= neigh[i])
        return neigh[i];
    return parent;
  }
  else {
    int parent = neigh[0];
    if (start) {  
      neigh.erase(neigh.begin());
      neigh.push_back(start);
    }
    for (int i = 1; i < neigh.size(); i++)
      if (dest >= neigh[i - 1] && dest < neigh[i])
        return neigh[i - 1];
    return parent;
  }	
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:36:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for (int i = 1; i < neigh.size(); i++)
      |                     ~~^~~~~~~~~~~~~~
stations.cpp:47:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     for (int i = 1; i < neigh.size(); i++)
      |                     ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 648 ms 1024 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 605 ms 768 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 579 ms 1024 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1057 ms 640 KB Output is correct
2 Incorrect 810 ms 640 KB Wrong query response.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 538 ms 1088 KB Wrong query response.
2 Halted 0 ms 0 KB -