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<bits/stdc++.h>
using namespace std;
#define pb push_back
const int N = 1010;
typedef long long ll;
vector<int> g[N];
vector<int> tin, tout, depth;
int cnt=0;
void dfs(int at, int p) {
tin[at]=cnt++;
for(int to:g[at]) {
if(to != p){
depth[to]=depth[at]+1;
dfs(to, at);
}
}
tout[at]=cnt++;
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
cnt=0;
tin.clear();
tout.clear();
depth.clear();
tin.resize(n);
tout.resize(n);
depth.resize(n);
for(int i = 0;i<n-1;i++) {
g[u[i]].pb(v[i]);
g[v[i]].pb(u[i]);
}
dfs(0, 0);
depth[0]=0;
vector<int> l(n);
for(int i = 0;i<n;i++) {
if(depth[i]%2==0) {
l[i]=tin[i]/2;
}
else {
l[i]=tout[i]/2;
}
}
for(int i = 0;i<=n;i++)g[i].clear();
return l;
}
int find_next_station(int s, int t, std::vector<int> c) {
int k =0;
bool parity=1;
int tins=0; int touts=0; int mx = 0, mn = 1e9;
for(int i = 0;i<c.size();i++) {
mx=max(mx, c[i]);
mn=min(mn, c[i]);
}
int mx2 = 0;
for(int i = 0;i<c.size();i++) {
if(mx==c[i])continue;
mx2=max(mx2, c[i]);
}
if(mx >= s) {
parity=0;
}
if(!parity) {
tins=2*s;
touts=2*mx2+1;
}
else {
touts=2*s;
tins=2*mn+1;
}
if(tins <= 2*t and 2*t <= touts) {
for(int i = 0;i<c.size();i++) {
if(!parity) {
if(c[i] == mx)continue;
if(c[i] <= t) {
return c[i];
}
}
else {
if(c[i] == mn)continue;
if(c[i] >= t)return c[i];
}
}
}
else {
for(int i = 0;i<c.size();i++) {
if(tins >= 2*c[i] or 2*c[i] >= touts)return c[i];
}
}
return 0;
}
Compilation message (stderr)
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:51:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for(int i = 0;i<c.size();i++) {
| ~^~~~~~~~~
stations.cpp:56:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for(int i = 0;i<c.size();i++) {
| ~^~~~~~~~~
stations.cpp:72:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | for(int i = 0;i<c.size();i++) {
| ~^~~~~~~~~
stations.cpp:86:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
86 | for(int i = 0;i<c.size();i++) {
| ~^~~~~~~~~
stations.cpp:48:6: warning: unused variable 'k' [-Wunused-variable]
48 | int k =0;
| ^
# | 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... |