Submission #309853

# Submission time Handle Problem Language Result Execution time Memory
309853 2020-10-04T17:35:32 Z tjdgus4384 Stations (IOI20_stations) C++14
0 / 100
979 ms 936 KB
#include<bits/stdc++.h>
#include "stations.h"
using namespace std;
bool visited[1001];
vector<int> path[1001], pathl[1001];
int num1[1001], num2[1001];

int dfs1(int x, int cnt){
    num1[x] = cnt; cnt++;
    for(int i = 0;i < path[x].size();i++){
        if(visited[path[x][i]]) continue;
        visited[path[x][i]] = true;
        cnt = dfs1(path[x][i], cnt);
    }
    return cnt;
}
int dfs2(int x){
    int ret = num1[x];
    for(int i = 0;i < path[x].size();i++){
        if(visited[path[x][i]]) continue;
        visited[path[x][i]] = true;
        ret = max(ret, dfs2(path[x][i]));
    }
    return num2[x] = ret;
}

vector<int> label(int n, int k, vector<int> u, vector<int> v){
    for(int i = 0;i < n-1;i++){
        path[u[i]].push_back(v[i]);
        path[v[i]].push_back(u[i]);
    }
    visited[0] = true;
    dfs1(0, 1);
    for(int i = 0;i < n;i++) visited[i] = false;
    visited[0] = true;
    dfs2(0);
    vector<int> ret(n);
    for(int i = 0;i < n;i++){
        ret[i] = num1[i]*1000+num2[i];
    }
    return ret;
}

int find_next_station(int s, int t, vector<int> c){
    int num2s = s%1000, num2t = t%1000;
    int num1s = (s-num2s)/1000, num1t = (t-num2t)/1000;

    for(int i = 0;i < c.size();i++){
        num2[i] = c[i]%1000; num1[i] = (c[i]-num2[i])/1000;
    }

    if(num1t > num1s && num1t <= num2s){
        int s = 0, e = c.size() - 1;
        while(s < e){
            int mid = (s+e+1)/2;
            if(num1[mid] > num1t) e = mid-1;
            else s = mid;
        }
        return c[s];
    }
    else return c[0];
}

Compilation message

stations.cpp: In function 'int dfs1(int, int)':
stations.cpp:10:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |     for(int i = 0;i < path[x].size();i++){
      |                   ~~^~~~~~~~~~~~~~~~
stations.cpp: In function 'int dfs2(int)':
stations.cpp:19:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for(int i = 0;i < path[x].size();i++){
      |                   ~~^~~~~~~~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:48:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     for(int i = 0;i < c.size();i++){
      |                   ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 544 KB Invalid labels (values out of range). scenario=0, k=1000, vertex=0, label=1010
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 540 KB Invalid labels (values out of range). scenario=0, k=1000, vertex=0, label=1996
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 376 KB Invalid labels (duplicates values). scenario=1, label=0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 979 ms 936 KB Output is correct
2 Incorrect 794 ms 896 KB Wrong query response.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 504 KB Invalid labels (duplicates values). scenario=1, label=0
2 Halted 0 ms 0 KB -