Submission #398256

# Submission time Handle Problem Language Result Execution time Memory
398256 2021-05-04T02:35:17 Z Everule Stations (IOI20_stations) C++17
0 / 100
1041 ms 520 KB
//#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	std::vector<int> labels(n);
    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]);
    }
    vector<int> tin(n), tout(n), dep(n);
    int t = 0;
    function<void(int,int)> dfs = [&](int u,int p){
        tin[u] = t++;
        for(auto &v : adj[u]){
            if(v == p) continue;
            dep[v] = dep[u] + 1;
            dfs(v, u);
        }
        tout[u] = t++;
    };
    dfs(0, 0);

    for(int i=0;i<n;i++){
        if(dep[i] % 2 == 0){
            labels[i] = tin[i];
        }
        else{
            labels[i] = tout[i];
        }
    }
    vector<int> x = labels;
    sort(x.begin(), x.end());
    for(auto &x : labels){
        x = lower_bound(labels.begin(), labels.end(), x) - labels.begin() + 1;
    }
	return labels;
}

int find_next_station(int s, int t, std::vector<int> c) {
    if(c.size() == 1) return c[0];
    sort(c.begin(), c.end());
	if(c[0] < s){
        if(t < c[1] || t > s){
            return c[0];
        }
        for(int i=c.size()-1;i>0;--i){
            if(c[i] <= t) return c[i];
        }
    }
    else{
        reverse(c.begin(), c.end());
        if(t > c[1] || t < s){
            return c[0];
        }
        for(int i=c.size()-1;i>0;--i){
            if(c[i] >= t) return c[i];
        }
    }
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:60:1: warning: control reaches end of non-void function [-Wreturn-type]
   60 | }
      | ^
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 440 KB Invalid labels (duplicates values). scenario=0, label=6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 288 KB Invalid labels (duplicates values). scenario=0, label=48
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 416 KB Invalid labels (duplicates values). scenario=1, label=846
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1041 ms 400 KB Output is correct
2 Incorrect 1 ms 268 KB Invalid labels (duplicates values). scenario=2, label=2
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 520 KB Invalid labels (duplicates values). scenario=0, label=2
2 Halted 0 ms 0 KB -