답안 #348074

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
348074 2021-01-14T07:32:40 Z blue 기지국 (IOI20_stations) C++17
0 / 100
1 ms 416 KB
#include "stations.h"
#include <iostream>
#include <vector>
using namespace std;

vector<int> edge[1000];
vector<int> visit(1000, 0);
vector<int> L;

int dfs(int u, int a, bool flag) //vertex, minimum label, left/right?     return largest unused label
{
    visit[u] = 1;
    cout << "dfs " << u << ' ' << a << ' ' << flag << '\n';

    if(flag == 0)
    {
        L[u] = a;
        a++;
    }

    for(int v: edge[u])
    {
        if(visit[v]) continue;
        a = dfs(v, a, !flag);
    }

    if(flag == 1)
    {
        L[u] = a;
        a++;
    }

    return a;
}

/*
        0
      / | \
     1  2  3
    / \  \
   4   5  6
*/

vector<int> label(int n, int k, vector<int> u, vector<int> v)
{
    for(int j = 0; j < n-1; j++)
    {
        edge[u[j]].push_back(v[j]);
        edge[v[j]].push_back(u[j]);
    }

    L = vector<int>(n, -1);

    dfs(0, 0, 0);

    return L;
}

int find_next_station(int s, int t, vector<int> c)
{
    if(s < c[0]) // s is left label
    {
        if(t < s) return c.back();
        for(int i = 0; i < c.size(); i++) if(t <= c[i]) return c[i];
    }
    else // s is right label
    {
        if(t > s) return c[0];
        for(int i = c.size()-1; i >= 0; i--) if(t >= c[i]) return c[i];
    }
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:64:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |         for(int i = 0; i < c.size(); i++) if(t <= c[i]) return c[i];
      |                        ~~^~~~~~~~~~
stations.cpp:71:1: warning: control reaches end of non-void function [-Wreturn-type]
   71 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 416 KB Execution killed with signal 13 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 364 KB Execution killed with signal 13 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 384 KB Execution killed with signal 13 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 364 KB Execution killed with signal 13 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 364 KB Execution killed with signal 13 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -