#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
const int nx=1e3+5;
int in[nx], out[nx], lvl[nx], cnt, pa, t1;
vector<int> res, d[nx];
vector<pair<int, int>> mp[nx];
void dfs(int u, int p)
{
in[u]=++cnt;
lvl[u]=lvl[p]+1;
for (auto v:d[u]) if (v!=p) dfs(v, u);
out[u]=++cnt;
if (lvl[u]%2) mp[in[u]].push_back({u, 0});
else mp[out[u]].push_back({u, 1});
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
cnt=-1;
t1=0;
for (int i=0; i<n; i++) d[i].clear();
res.resize(n);
for (int i=0; i<n-1; i++) d[u[i]].push_back(v[i]), d[v[i]].push_back(u[i]);
lvl[0]=0;
dfs(0, 0);
for (int i=0; i<1000; i++)
{
if (!mp[i].empty())
{
for (auto [x, y]:mp[i]) res[x]=t1+y*1000;
t1++;
}
}
return res;
}
int find_next_station(int s, int t, std::vector<int> c) {
if (c.size()==1) return c[0];
if (t>=1000) t-=1000;
if (s<1000)
{
for (auto &x:c) x-=1000;
if (s==0) for (auto x:c) if (t<=x) return x+1000;
pa=c.back();
//cout<<"here "<<s<<' '<<pa<<' '<<t<<'\n';
for (int i=0; i<c.size()-1; i++) if (s<=t&&t<=c[i]) return c[i]+1000;
return pa+1000;
}
else
{
s-=1000;
pa=c.front();
for (int i=c.size()-1; i>0; i--) if (c[i]<=t&&t<=s) return c[i];
return pa;
}
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:49:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for (int i=0; i<c.size()-1; i++) if (s<=t&&t<=c[i]) return c[i]+1000;
| ~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
760 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
828 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
856 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
552 ms |
940 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Invalid labels (duplicates values). scenario=2, label=1002 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
856 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |