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 <vector>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <map>
#include <cstdio>
using namespace std;
const int maxn = 1010;
vector<int> g[maxn];
vector<int> lab, siz;
int calc_siz(int x, int p) {
for (int i : g[x]) {
if (i == p)continue;
siz[x] += calc_siz(i, x);
}
return siz[x];
}
void calc_lab(int x, int p) {
int sum = 0, pl = (p < 0 ? maxn : lab[p]);
for (int i : g[x]) {
if (i == p)continue;
if (pl > lab[x]) {
lab[i] = lab[x] + siz[i] + sum;
}
else {
lab[i] = lab[x] - siz[i] - sum;
}
calc_lab(i, x);
sum += siz[i];
}
return;
}
vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
lab.assign(n, 0);
siz.assign(n, 1);
for (int i = 0; i < u.size(); i++) {
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
}
calc_siz(0, -1);
calc_lab(0, -1);
return lab;
}
int find_next_station(int s, int t, std::vector<int> c) {
if (s > c[0]) {
reverse(c.begin(), c.end());
for (int i : c) {
if (s > t && t >= i)return i;
}
return c.back();
}
else {
for (int i : c) {
if (s < t && t <= i)return i;
}
return c.back();
}
}
Compilation message (stderr)
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:40:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for (int i = 0; i < u.size(); i++) {
| ~~^~~~~~~~~~
# | 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... |