QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#140490#1139. StationsQwerty1232#Compile Error//C++201.2kb2023-08-16 00:36:012024-07-04 01:45:15

Judging History

你现在查看的是最新测评结果

  • [2024-07-04 01:45:15]
  • 评测
  • [2023-08-16 00:36:01]
  • 提交

stations

#include "stations.h"

#include <bits/stdc++.h>

#include <cassert>
#include <vector>

constexpr int N = 1e3;

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
    std::vector<std::vector<int>> gr(n);
    for (int i = 0; i < n - 1; i++) {
        gr[u[i]].push_back(v[i]);
        gr[v[i]].push_back(u[i]);
    }
    std::vector<int> res(n);
    auto dfs = [&](auto dfs, int v, int f, int d, int& e) -> void {
        for (int t : gr[v]) {
            if (t != f) {
                dfs(dfs, t, v, d + 1, e);
            }
        }
        res[v] = e++;
    };
    int e = 0;
    for (int i = 0; i < n; i++) {
        if (gr[i].size() == 1) {
            dfs(dfs, i, -1, 0, e);
            break;
        }
    }

    return res;
}

int find_next_station(int s, int dest, std::vector<int> c) {
    assert(s != dest);
    for (int to : c) {
        if (to == dest) {
            return to;
        }
    }
    if (c.size() == 1) {
        return c.front();
    }
    for (int t : c) {
        if (s <= t && t <= dest || dest <= t && t <= s) {
            return t;
        }
    }

    assert(false);
}

Details