답안 #1072896

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1072896 2024-08-24T06:37:47 Z Ignut 기지국 (IOI20_stations) C++17
0 / 100
1031 ms 2252 KB
// Ignut

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 1111;

vector<int> tree[N];

vector<int> euler;

int root;

void dfs(int v, int par) {
    euler.push_back(v);
    for (int to : tree[v]) {
        if (to != par) {
            dfs(to, v);
            if (v == root)
                euler.push_back(v);
        }
    }
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
    euler.clear();
    for (int i = 0; i < n; i ++) {
        tree[i].clear();
    }

    for (int i = 0; i < n - 1; i ++) {
        tree[u[i]].push_back(v[i]);
        tree[v[i]].push_back(u[i]);
    }
    root = 0;
    for (int i = 0; i < n; i ++)
        if (tree[i].size() > 2)
            root = i;
    dfs(root, -1);

    vector<int> lbl(n);
    lbl[root] = 0;
    int number = 1;
    for (int v : euler) {
        if (v == root) {
            number = (number / 1000 + 1) * 1000;
            number ++;
            continue;
        }
        lbl[v] = number ++;
    }
    for (int val : lbl) cerr << val << ' ';
    cerr << '\n';
    return lbl;
}



int find_next_station(int s, int t, vector<int> c) {
    for (int val : c) cerr << val << ' ';
    cerr << '\n';
    if (c.size() > 2) {
        for (int v : c) {
            if (v / 1000 == t / 1000)
                return v;
        }
        t /= 0;
        return t;
    }
    if (c.size() > 2)
        t /= 0;
    if (c.size() == 1)
        return c[0];

    int mn = min(c[0], c[1]);
    int mx = max(c[0], c[1]);

    if (mn == t) return t;
    if (mx == t) return t;

    if (t == 0) return mn;

    if (mx / 1000 == t / 1000) {
        if (mx % 1000 < t % 1000)
            return mx;
        return mn;
    }

    if (mx / 1000 == s / 1000)
        return mn;
    
    s /= 0;
    return mx;
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:69:11: warning: division by zero [-Wdiv-by-zero]
   69 |         t /= 0;
      |         ~~^~~~
stations.cpp:73:11: warning: division by zero [-Wdiv-by-zero]
   73 |         t /= 0;
      |         ~~^~~~
stations.cpp:94:7: warning: division by zero [-Wdiv-by-zero]
   94 |     s /= 0;
      |     ~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 600 KB Invalid labels (values out of range). scenario=0, k=1000, vertex=1, label=2005
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 21 ms 552 KB Invalid labels (values out of range). scenario=0, k=1000, vertex=0, label=1008
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 747 ms 1936 KB Wrong query response.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1031 ms 1412 KB Output is correct
2 Correct 854 ms 1396 KB Output is correct
3 Incorrect 772 ms 1972 KB Wrong query response.
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 729 ms 2252 KB Wrong query response.
2 Halted 0 ms 0 KB -