This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 1000;
vector<int> edges[N];
vector<int> tin(N), tout(N);
int t1, t2;
void dfs(int x, int p) {
int y;
tin[x] = t1;
++t1;
while (!edges[x].empty()) {
y = edges[x].back();
edges[x].pop_back();
if (y != p) {
dfs(y, x);
}
}
tout[x] = t2;
++t2;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
vector<int> labels(n);
t1 = 0, t2 = 0;
// for (int i = 0; i < n; i++) {
// edges[i].clear();
// }
for (int i = 0; i < n-1; ++i) {
edges[u[i]].push_back(v[i]);
edges[v[i]].push_back(u[i]);
}
dfs(0, -1);
for (int i = 0; i < n; ++i) {
labels[i] = tin[i]*1000 + tout[i];
}
return labels;
}
int find_next_station(int s, int e, vector<int> c) {
int sin = s/1000, sout = s % 1000;
int ein = e/1000, eout = e % 1000;
// cout << sin << " " << sout << " " << ein << "\n";
if (ein < sin) {
for (int x : c) {
if ((x/1000) <= sin) {
return x;
}
}
}
for (int x : c) {
if ((x/1000) <= ein && (x%1000) >= eout) {
return x;
}
}
return c[0];
}
// int main() {
// vector<int> labels = label(5, 10, {0, 1, 1, 2}, {1, 2, 3, 4});
// // for (auto x : labels) {
// // cout << x << " ";
// // cout << "\n";
// // }
// labels = label(6, 10, {0, 1, 1, 3, 3}, {1, 2, 3, 4, 5});
// // for (auto x : labels) {
// // cout << x << " ";
// // cout << "\n";
// // }
// // cout << "\n";
// find_next_station(2001, 3000, {3000, 1003});
// cout << "DONE\n";
// // cout << find_next_station(2001, 3000, {3000, 1003}) << "\n";
// }
Compilation message (stderr)
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:46:20: warning: unused variable 'sout' [-Wunused-variable]
46 | int sin = s/1000, sout = s % 1000;
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |