Submission #780900

#TimeUsernameProblemLanguageResultExecution timeMemory
780900kamelfanger83Stations (IOI20_stations)C++14
0 / 100
680 ms668 KiB
#include "stations.h"
#include <vector>

using namespace std;

vector<pair<int, int>> prepost;
vector<vector<int>> cons;
int C = 0;

void dfs(int i, int from){
    prepost[i].first = C++;
    for (int c : cons[i]){
        if (c == from) continue;
        dfs(c, i);
    }
    prepost[i].second = C;
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
    cons.clear();
    C = 0;
    vector<int> labels(n);
    cons.resize(n);
    for (int i = 0; i < n - 1; ++i) {
        cons[u[i]].push_back(v[i]);
        cons[v[i]].push_back(u[i]);
    }

    prepost.resize(n);
    dfs(0, -1);

    for (int i = 0; i < n; ++i) {
        labels[i] = prepost[i].first * 1000 + prepost[i].second;
    }

    return labels;
}

int find_next_station(int s, int t, vector<int> c) {
    int spre = s / 1000, spost = s % 1000;
    int tpre = t / 1000, tpost = t % 1000;
    bool isdes = spre < tpre && tpost <= spost;
    for (int i = 0; i < c.size(); ++i) {
        int cpre = c[i] / 1000, cpost = c[i] % 1000;
        if (!isdes) {
            if (cpre < spre && spost <= cpost) return c[i];
        }
        if (isdes){
            if (cpre <= tpre && tpost <= cpost) return c[i];
        }
    }
    //return 0;
}

Compilation message (stderr)

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:43:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     for (int i = 0; i < c.size(); ++i) {
      |                     ~~^~~~~~~~~~
stations.cpp:53:1: warning: control reaches end of non-void function [-Wreturn-type]
   53 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...