Submission #309928

# Submission time Handle Problem Language Result Execution time Memory
309928 2020-10-05T02:14:49 Z tjdgus4384 Stations (IOI20_stations) C++14
0 / 100
895 ms 1024 KB
#include<bits/stdc++.h>
#include "stations.h"
using namespace std;
vector<int> path[1001], ret;
bool visited[1001];
int tsize[1001];

int dfs(int x){
    int s = 1;
    for(int i = 0;i < path[x].size();i++){
        if(visited[path[x][i]]) continue;
        visited[path[x][i]] = true;
        s += dfs(path[x][i]);
    }
    return tsize[x] = s;
}
void dfs2(int x, int s, int e, int d){
    if(d%2 == 0) {ret[x] = s; s++;}
    else ret[x] = e;
    for(int i = 0;i < path[x].size();i++){
        if(visited[path[x][i]]) continue;
        visited[path[x][i]] = true;
        dfs2(path[x][i], s, s+tsize[path[x][i]]-1, d+1);
        s+=tsize[path[x][i]];
    }
}

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

int find_next_station(int s, int t, vector<int> c){
    if(c[0] < s){
        if(t > s || t < c[0]) return c[0];
        return c[(int)(upper_bound(c.begin(), c.end(), t) - c.begin())];
    }
    else{
        if(t < s || t > c.back()) return c.back();
        return c[(int)(lower_bound(c.begin(), c.end(), t) - c.begin())];
    }
}

Compilation message

stations.cpp: In function 'int dfs(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 'void dfs2(int, int, int, int)':
stations.cpp:20:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for(int i = 0;i < path[x].size();i++){
      |                   ~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 608 ms 768 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 473 ms 808 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 596 ms 1024 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 895 ms 872 KB Output is correct
2 Incorrect 656 ms 768 KB Wrong query response.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 595 ms 1024 KB Wrong query response.
2 Halted 0 ms 0 KB -