답안 #309930

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
309930 2020-10-05T02:25:05 Z tjdgus4384 기지국 (IOI20_stations) C++14
0 / 100
852 ms 1008 KB
#include<bits/stdc++.h>
#include "stations.h"
using namespace std;
vector<int> path[1001];
bool visited[1001];
int tsize[1001], lb[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) {lb[x] = s; s++;}
    else lb[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){
    for(int i = 0;i < n;i++) path[i].clear();
    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);
    vector<int> ret;
    for(int i = 0;i < n;i++) ret.push_back(lb[i]);
    return ret;
}
 
int find_next_station(int s, int t, vector<int> c){
    if(c[0] < s){
        if(t > s) return c[0];
        c.push_back(1001);
        for(int i = 0;i < c.size() - 1;i++){
            if(t >= c[i] && t < c[i+1]) return c[i];
        }
    }
    else{
        if(t < s) return c.back();
        for(int i = 0;i < c.size();i++){
            if(t <= c[i]) return c[i];
        }
        return c.back();
    }
}

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++){
      |                   ~~^~~~~~~~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:49:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |         for(int i = 0;i < c.size() - 1;i++){
      |                       ~~^~~~~~~~~~~~~~
stations.cpp:55:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         for(int i = 0;i < c.size();i++){
      |                       ~~^~~~~~~~~~
stations.cpp:60:1: warning: control reaches end of non-void function [-Wreturn-type]
   60 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 602 ms 768 KB Wrong query response.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 524 ms 816 KB Wrong query response.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 518 ms 768 KB Wrong query response.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 852 ms 1008 KB Output is correct
2 Correct 653 ms 872 KB Output is correct
3 Incorrect 565 ms 864 KB Wrong query response.
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 653 ms 768 KB Wrong query response.
2 Halted 0 ms 0 KB -