#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
int n , tim , st_tim[N] , fn_tim[N] , dis[N];
vector <int> adj[N];
void Dfs(int v , int p = -1)
{
st_tim[v] = tim;
tim++;
for(auto u : adj[v]) if(u != p)
{
dis[u] = (dis[v] ^ 1);
Dfs(u , v);
}
fn_tim[v] = tim;
tim++;
}
vector<int> label(int nn, int k, vector<int> u, vector<int> v) {
n = nn;
for(int i = 0 ; i < n ; i++)
{
dis[i] = 0;
adj[i].clear();
}
tim = 0;
for(int i = 0 ; i < n - 1 ; i++)
{
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
int root = -1;
for(int i = 0 ; i < n ; i++) if(adj[i].size() == 1)
root = i;
Dfs(root);
vector <int> all;
for(int i = 0 ; i < n ; i++)
{
if(dis[i] == 0)
all.push_back(st_tim[i]);
else
all.push_back(fn_tim[i]);
}
sort(all.begin() , all.end());
vector<int> labels(n);
for (int i = 0; i < n; i++)
{
if(dis[i] == 0)
labels[i] = lower_bound(all.begin() , all.end() , st_tim[i]) - all.begin();
else
labels[i] = lower_bound(all.begin() , all.end() , fn_tim[i]) - all.begin();
//cout << i << " : " << labels[i] << endl;
}
return labels;
}
int find_next_station(int s, int t, vector<int> c) {
if(c.size() == 1)
return c[0];
if(c[0] > s)
{
int par = c.back();
c.pop_back();
int mn = s , mx = c.back();
if(t < mn || t > mx)
return par;
int ans = N;
for(auto u : c) if(t <= u)
{
ans = u;
break;
}
return ans;
}
else
{
int par = c[0];
int mn = c[1] , mx = s;
if(t < mn || t > mx)
return par;
int ans = N;
for(int i = c.size() - 1 ; i > 0 ; i--) if(c[i] <= t)
{
ans = c[i];
break;
}
return ans;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
306 ms |
684 KB |
Output is correct |
2 |
Correct |
262 ms |
684 KB |
Output is correct |
3 |
Correct |
538 ms |
684 KB |
Output is correct |
4 |
Correct |
370 ms |
688 KB |
Output is correct |
5 |
Correct |
378 ms |
684 KB |
Output is correct |
6 |
Correct |
251 ms |
684 KB |
Output is correct |
7 |
Correct |
247 ms |
684 KB |
Output is correct |
8 |
Correct |
1 ms |
776 KB |
Output is correct |
9 |
Correct |
2 ms |
776 KB |
Output is correct |
10 |
Correct |
0 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
305 ms |
684 KB |
Output is correct |
2 |
Correct |
334 ms |
684 KB |
Output is correct |
3 |
Correct |
534 ms |
684 KB |
Output is correct |
4 |
Correct |
372 ms |
684 KB |
Output is correct |
5 |
Correct |
335 ms |
684 KB |
Output is correct |
6 |
Correct |
258 ms |
684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
297 ms |
684 KB |
Output is correct |
2 |
Correct |
254 ms |
684 KB |
Output is correct |
3 |
Correct |
507 ms |
684 KB |
Output is correct |
4 |
Correct |
361 ms |
684 KB |
Output is correct |
5 |
Correct |
405 ms |
684 KB |
Output is correct |
6 |
Correct |
270 ms |
684 KB |
Output is correct |
7 |
Correct |
261 ms |
684 KB |
Output is correct |
8 |
Correct |
1 ms |
776 KB |
Output is correct |
9 |
Correct |
2 ms |
768 KB |
Output is correct |
10 |
Correct |
0 ms |
772 KB |
Output is correct |
11 |
Correct |
328 ms |
684 KB |
Output is correct |
12 |
Correct |
265 ms |
932 KB |
Output is correct |
13 |
Correct |
254 ms |
940 KB |
Output is correct |
14 |
Correct |
260 ms |
684 KB |
Output is correct |
15 |
Correct |
31 ms |
768 KB |
Output is correct |
16 |
Correct |
42 ms |
768 KB |
Output is correct |
17 |
Correct |
62 ms |
684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
448 ms |
684 KB |
Output is correct |
2 |
Correct |
283 ms |
684 KB |
Output is correct |
3 |
Correct |
274 ms |
684 KB |
Output is correct |
4 |
Correct |
1 ms |
764 KB |
Output is correct |
5 |
Correct |
1 ms |
768 KB |
Output is correct |
6 |
Correct |
1 ms |
768 KB |
Output is correct |
7 |
Correct |
306 ms |
796 KB |
Output is correct |
8 |
Correct |
511 ms |
684 KB |
Output is correct |
9 |
Correct |
410 ms |
684 KB |
Output is correct |
10 |
Correct |
350 ms |
684 KB |
Output is correct |
11 |
Correct |
3 ms |
1016 KB |
Output is correct |
12 |
Correct |
1 ms |
776 KB |
Output is correct |
13 |
Correct |
2 ms |
776 KB |
Output is correct |
14 |
Correct |
1 ms |
768 KB |
Output is correct |
15 |
Correct |
0 ms |
768 KB |
Output is correct |
16 |
Correct |
277 ms |
796 KB |
Output is correct |
17 |
Correct |
283 ms |
684 KB |
Output is correct |
18 |
Correct |
279 ms |
684 KB |
Output is correct |
19 |
Correct |
301 ms |
684 KB |
Output is correct |
20 |
Correct |
278 ms |
684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
328 ms |
684 KB |
Output is correct |
2 |
Correct |
212 ms |
684 KB |
Output is correct |
3 |
Correct |
484 ms |
684 KB |
Output is correct |
4 |
Correct |
378 ms |
684 KB |
Output is correct |
5 |
Correct |
386 ms |
684 KB |
Output is correct |
6 |
Correct |
260 ms |
684 KB |
Output is correct |
7 |
Correct |
233 ms |
684 KB |
Output is correct |
8 |
Correct |
0 ms |
760 KB |
Output is correct |
9 |
Correct |
1 ms |
768 KB |
Output is correct |
10 |
Correct |
0 ms |
768 KB |
Output is correct |
11 |
Correct |
294 ms |
684 KB |
Output is correct |
12 |
Correct |
272 ms |
684 KB |
Output is correct |
13 |
Correct |
533 ms |
684 KB |
Output is correct |
14 |
Correct |
407 ms |
684 KB |
Output is correct |
15 |
Correct |
336 ms |
684 KB |
Output is correct |
16 |
Correct |
237 ms |
684 KB |
Output is correct |
17 |
Correct |
336 ms |
684 KB |
Output is correct |
18 |
Correct |
276 ms |
932 KB |
Output is correct |
19 |
Correct |
269 ms |
688 KB |
Output is correct |
20 |
Correct |
261 ms |
684 KB |
Output is correct |
21 |
Correct |
34 ms |
764 KB |
Output is correct |
22 |
Correct |
28 ms |
768 KB |
Output is correct |
23 |
Correct |
50 ms |
684 KB |
Output is correct |
24 |
Correct |
2 ms |
764 KB |
Output is correct |
25 |
Correct |
3 ms |
776 KB |
Output is correct |
26 |
Correct |
1 ms |
776 KB |
Output is correct |
27 |
Correct |
1 ms |
776 KB |
Output is correct |
28 |
Correct |
0 ms |
768 KB |
Output is correct |
29 |
Correct |
319 ms |
684 KB |
Output is correct |
30 |
Correct |
298 ms |
684 KB |
Output is correct |
31 |
Correct |
307 ms |
684 KB |
Output is correct |
32 |
Correct |
282 ms |
684 KB |
Output is correct |
33 |
Correct |
283 ms |
684 KB |
Output is correct |
34 |
Correct |
197 ms |
716 KB |
Output is correct |
35 |
Correct |
277 ms |
1200 KB |
Output is correct |
36 |
Correct |
263 ms |
684 KB |
Output is correct |
37 |
Correct |
254 ms |
792 KB |
Output is correct |
38 |
Correct |
264 ms |
684 KB |
Output is correct |
39 |
Correct |
276 ms |
1052 KB |
Output is correct |
40 |
Correct |
257 ms |
932 KB |
Output is correct |
41 |
Correct |
259 ms |
1044 KB |
Output is correct |
42 |
Correct |
31 ms |
768 KB |
Output is correct |
43 |
Correct |
45 ms |
680 KB |
Output is correct |
44 |
Correct |
67 ms |
764 KB |
Output is correct |
45 |
Correct |
65 ms |
712 KB |
Output is correct |
46 |
Correct |
165 ms |
684 KB |
Output is correct |
47 |
Correct |
167 ms |
684 KB |
Output is correct |
48 |
Correct |
24 ms |
744 KB |
Output is correct |
49 |
Correct |
24 ms |
768 KB |
Output is correct |