#include <bits/stdc++.h>
#include "stations.h"
#include <vector>
using namespace std;
const int maxn = 1e3+10;
static int st[maxn], en[maxn], nivel[maxn], tt;
vector<int> grafo[maxn];
void dfs(int u, int p)
{
st[u] = ++tt;
for (auto v: grafo[u])
{
if (v == p) continue;
nivel[v] = nivel[u]+1;
dfs(v, u);
}
en[u] = ++tt;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v)
{
tt = -1;
for (int i = 0; i < n; i++)
grafo[i].clear();
for (int i = 0; i < n-1; i++)
{
grafo[u[i]].push_back(v[i]);
grafo[v[i]].push_back(u[i]);
}
dfs(0, -1);
vector<int> num;
for (int i = 0; i < n; i++)
{
if (nivel[i]%2 == 0) num.push_back(st[i]);
else num.push_back(en[i]);
}
map<int, int> mp;
for (auto x: num)
mp[x] = 0;
int aux = 0;
for (auto &x: mp)
x.second = ++aux;
for (auto &x: num)
x = mp[x];
return num;
}
int find_next_station(int u, int v, vector<int> c)
{
if (c.size() == 1) return c[0];
bool flag = 0;
for (auto x: c)
if (u < x)
flag = 1;
if (!flag)
{
for (int i = 1; i < c.size()-1; i++)
{
st[i] = c[i];
en[i] = c[i+1]-1;
}
st[c.size()-1] = c[c.size()-1];
en[c.size()-1] = u;
for (int i = 1; i < c.size(); i++)
if (v >= st[i] && v <= en[i])
return c[i];
return c[0];
}
else
{
st[0] = u+1;
en[0] = c[0];
for (int i = 1; i < c.size()-1; i++)
{
en[i] = c[i];
st[i] = en[i-1]+1;
}
for (int i = 0; i < c.size()-1; i++)
if (v >= st[i] && v <= en[i])
return c[i];
return c[c.size()-1];
}
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:78:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | for (int i = 1; i < c.size()-1; i++)
| ~~^~~~~~~~~~~~
stations.cpp:87:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
87 | for (int i = 1; i < c.size(); i++)
| ~~^~~~~~~~~~
stations.cpp:98:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
98 | for (int i = 1; i < c.size()-1; i++)
| ~~^~~~~~~~~~~~
stations.cpp:104:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
104 | for (int i = 0; i < c.size()-1; i++)
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
541 ms |
1312 KB |
Output is correct |
2 |
Correct |
454 ms |
1024 KB |
Output is correct |
3 |
Correct |
894 ms |
864 KB |
Output is correct |
4 |
Correct |
663 ms |
868 KB |
Output is correct |
5 |
Correct |
589 ms |
768 KB |
Output is correct |
6 |
Correct |
476 ms |
1024 KB |
Output is correct |
7 |
Correct |
453 ms |
1124 KB |
Output is correct |
8 |
Correct |
3 ms |
768 KB |
Output is correct |
9 |
Correct |
5 ms |
868 KB |
Output is correct |
10 |
Correct |
1 ms |
896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
452 ms |
768 KB |
Output is correct |
2 |
Correct |
513 ms |
908 KB |
Output is correct |
3 |
Correct |
863 ms |
860 KB |
Output is correct |
4 |
Correct |
693 ms |
768 KB |
Output is correct |
5 |
Correct |
607 ms |
768 KB |
Output is correct |
6 |
Correct |
458 ms |
776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
527 ms |
1112 KB |
Output is correct |
2 |
Correct |
456 ms |
1008 KB |
Output is correct |
3 |
Correct |
894 ms |
872 KB |
Output is correct |
4 |
Correct |
681 ms |
864 KB |
Output is correct |
5 |
Correct |
650 ms |
1024 KB |
Output is correct |
6 |
Correct |
470 ms |
1280 KB |
Output is correct |
7 |
Correct |
462 ms |
1112 KB |
Output is correct |
8 |
Correct |
3 ms |
868 KB |
Output is correct |
9 |
Correct |
6 ms |
996 KB |
Output is correct |
10 |
Correct |
2 ms |
1000 KB |
Output is correct |
11 |
Correct |
686 ms |
864 KB |
Output is correct |
12 |
Correct |
501 ms |
1024 KB |
Output is correct |
13 |
Correct |
465 ms |
1088 KB |
Output is correct |
14 |
Correct |
461 ms |
1024 KB |
Output is correct |
15 |
Correct |
58 ms |
856 KB |
Output is correct |
16 |
Correct |
68 ms |
800 KB |
Output is correct |
17 |
Correct |
118 ms |
1140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
848 ms |
1040 KB |
Output is correct |
2 |
Correct |
672 ms |
768 KB |
Output is correct |
3 |
Correct |
571 ms |
868 KB |
Output is correct |
4 |
Correct |
2 ms |
768 KB |
Output is correct |
5 |
Correct |
5 ms |
896 KB |
Output is correct |
6 |
Correct |
1 ms |
872 KB |
Output is correct |
7 |
Correct |
597 ms |
868 KB |
Output is correct |
8 |
Correct |
893 ms |
1008 KB |
Output is correct |
9 |
Correct |
632 ms |
864 KB |
Output is correct |
10 |
Correct |
610 ms |
1040 KB |
Output is correct |
11 |
Correct |
5 ms |
768 KB |
Output is correct |
12 |
Correct |
7 ms |
768 KB |
Output is correct |
13 |
Correct |
6 ms |
896 KB |
Output is correct |
14 |
Correct |
5 ms |
864 KB |
Output is correct |
15 |
Correct |
2 ms |
768 KB |
Output is correct |
16 |
Correct |
563 ms |
1024 KB |
Output is correct |
17 |
Correct |
573 ms |
864 KB |
Output is correct |
18 |
Correct |
515 ms |
872 KB |
Output is correct |
19 |
Correct |
492 ms |
860 KB |
Output is correct |
20 |
Correct |
581 ms |
1000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
632 ms |
1024 KB |
Output is correct |
2 |
Correct |
575 ms |
1024 KB |
Output is correct |
3 |
Correct |
1093 ms |
1008 KB |
Output is correct |
4 |
Correct |
819 ms |
1024 KB |
Output is correct |
5 |
Correct |
697 ms |
864 KB |
Output is correct |
6 |
Correct |
519 ms |
1040 KB |
Output is correct |
7 |
Correct |
554 ms |
1008 KB |
Output is correct |
8 |
Correct |
3 ms |
1024 KB |
Output is correct |
9 |
Correct |
6 ms |
864 KB |
Output is correct |
10 |
Correct |
1 ms |
768 KB |
Output is correct |
11 |
Correct |
480 ms |
768 KB |
Output is correct |
12 |
Correct |
554 ms |
768 KB |
Output is correct |
13 |
Correct |
835 ms |
868 KB |
Output is correct |
14 |
Correct |
633 ms |
996 KB |
Output is correct |
15 |
Correct |
621 ms |
1024 KB |
Output is correct |
16 |
Correct |
499 ms |
768 KB |
Output is correct |
17 |
Correct |
580 ms |
864 KB |
Output is correct |
18 |
Correct |
581 ms |
1008 KB |
Output is correct |
19 |
Correct |
576 ms |
1092 KB |
Output is correct |
20 |
Correct |
496 ms |
768 KB |
Output is correct |
21 |
Correct |
55 ms |
856 KB |
Output is correct |
22 |
Correct |
80 ms |
928 KB |
Output is correct |
23 |
Correct |
100 ms |
1140 KB |
Output is correct |
24 |
Correct |
6 ms |
768 KB |
Output is correct |
25 |
Correct |
7 ms |
768 KB |
Output is correct |
26 |
Correct |
5 ms |
868 KB |
Output is correct |
27 |
Correct |
5 ms |
768 KB |
Output is correct |
28 |
Correct |
2 ms |
864 KB |
Output is correct |
29 |
Correct |
559 ms |
896 KB |
Output is correct |
30 |
Correct |
582 ms |
864 KB |
Output is correct |
31 |
Correct |
547 ms |
860 KB |
Output is correct |
32 |
Correct |
655 ms |
868 KB |
Output is correct |
33 |
Correct |
639 ms |
868 KB |
Output is correct |
34 |
Correct |
413 ms |
1124 KB |
Output is correct |
35 |
Correct |
439 ms |
1008 KB |
Output is correct |
36 |
Correct |
427 ms |
1100 KB |
Output is correct |
37 |
Correct |
499 ms |
1120 KB |
Output is correct |
38 |
Correct |
544 ms |
1112 KB |
Output is correct |
39 |
Correct |
462 ms |
1024 KB |
Output is correct |
40 |
Correct |
511 ms |
1136 KB |
Output is correct |
41 |
Correct |
518 ms |
1008 KB |
Output is correct |
42 |
Correct |
61 ms |
768 KB |
Output is correct |
43 |
Correct |
144 ms |
1024 KB |
Output is correct |
44 |
Correct |
141 ms |
1024 KB |
Output is correct |
45 |
Correct |
181 ms |
1024 KB |
Output is correct |
46 |
Correct |
388 ms |
1040 KB |
Output is correct |
47 |
Correct |
311 ms |
1140 KB |
Output is correct |
48 |
Correct |
61 ms |
1240 KB |
Output is correct |
49 |
Correct |
62 ms |
1108 KB |
Output is correct |