#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, t2;
vector<int> res, d[nx];
map<int, pair<int, int>> mp;
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) res[u]=in[u];
else res[u]=2000+out[u];
}
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<n; i++)
{
if (res[i]>=2000) mp[res[i]-2000]={i, 1};
else mp[res[i]]={i, 0};
}
for (auto [x, y]:mp)
{
if (y.second) res[y.first]=x+t1+1000, t1++;
else res[y.first]=x+t1, 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:51:24: 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()-1; i++) if (s<=t&&t<=c[i]) return c[i]+1000;
| ~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
652 KB |
Invalid labels (values out of range). scenario=0, k=1000, vertex=1, label=1021 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
608 KB |
Invalid labels (values out of range). scenario=0, k=1000, vertex=1, label=2533 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
360 ms |
1008 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
579 ms |
684 KB |
Output is correct |
2 |
Correct |
462 ms |
684 KB |
Output is correct |
3 |
Correct |
400 ms |
684 KB |
Output is correct |
4 |
Correct |
2 ms |
764 KB |
Output is correct |
5 |
Correct |
3 ms |
768 KB |
Output is correct |
6 |
Correct |
0 ms |
768 KB |
Output is correct |
7 |
Correct |
374 ms |
940 KB |
Output is correct |
8 |
Correct |
565 ms |
684 KB |
Output is correct |
9 |
Correct |
436 ms |
684 KB |
Output is correct |
10 |
Correct |
415 ms |
684 KB |
Output is correct |
11 |
Correct |
2 ms |
768 KB |
Output is correct |
12 |
Correct |
2 ms |
768 KB |
Output is correct |
13 |
Incorrect |
3 ms |
768 KB |
Wrong query response. |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
361 ms |
1008 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |