#include "stations.h"
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
#define debug(x) {cerr<<#x<<"="<<x<<"\n";}
#define debug2(x, y) {cerr<<"{"<<#x<<", "<<#y<<"}={"<<x<<", "<<y<<"}\n";}
#define debugp(p) {cerr<<#p<<"={"<<p.first<<", "<<p.second<<"}\n";}
#define debugv(abcd) {cerr<<#abcd<<": "; for (auto dcba:abcd) cerr<<dcba<<", ";cerr<<"\n";}
#define pb push_back
#define all(x) x.begin(), x.end()
#define SZ(x) ((int)x.size())
const int inf=1000000100; // 1e9
const ll INF=10000000001000000; // 1e16
const int mod=1000000007;
const int MAXN=1010;
int n, m, k, x, y, a, b, t, ans;
int stt[MAXN], fnt[MAXN], timer;
vi G[MAXN];
void dfs(int node, int par){
stt[node]=timer++;
for (int v:G[node]) if (v!=par) dfs(v, node);
fnt[node]=timer;
}
vi label(int _n, int _k, vi U, vi V){
n=_n;
k=_k;
vi out(n);
for (int i=0; i<n; i++) G[i].clear();
for (int i=0; i<n-1; i++){
int u=U[i], v=V[i];
G[u].pb(v);
G[v].pb(u);
}
timer=0;
dfs(0, 0);
for (int i=0; i<n; i++) out[i]=stt[i]*1000+fnt[i]-1;
return out;
}
int find_next_station(int s, int t, vi adj){
// cerr<<"\n";
// debug2(s, t)
sort(all(adj));
for (int x:adj) if (x==t) return x;
int stt_s=(s)/1000, fnt_s=(s)%1000+1;
int stt_t=(t)/1000, fnt_t=(t)%1000+1;
if (stt_t<stt_s || fnt_s<=stt_t) return adj[0];
// debug2(stt_t, fnt_t)
for (int i=0; i<SZ(adj); i++){
int v=adj[i];
int stt_v=(v)/1000, fnt_v=(v)%1000+1;
if (stt_v<stt_s) continue ; // v=par[s]
// debug2(stt_v, fnt_v)
if (stt_v<=stt_t && stt_t<fnt_v) return v;
}
return -1;
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, vi)':
stations.cpp:55:22: warning: unused variable 'fnt_t' [-Wunused-variable]
55 | int stt_t=(t)/1000, fnt_t=(t)%1000+1;
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
328 KB |
Invalid labels (values out of range). scenario=0, k=1000, vertex=1, label=6009 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
312 KB |
Invalid labels (values out of range). scenario=0, k=1000, vertex=1, label=1511 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
609 ms |
672 KB |
Output is correct |
2 |
Correct |
611 ms |
508 KB |
Output is correct |
3 |
Correct |
970 ms |
400 KB |
Output is correct |
4 |
Correct |
887 ms |
492 KB |
Output is correct |
5 |
Correct |
774 ms |
400 KB |
Output is correct |
6 |
Correct |
692 ms |
540 KB |
Output is correct |
7 |
Correct |
527 ms |
528 KB |
Output is correct |
8 |
Correct |
3 ms |
420 KB |
Output is correct |
9 |
Correct |
4 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
797 ms |
404 KB |
Output is correct |
12 |
Correct |
604 ms |
736 KB |
Output is correct |
13 |
Correct |
615 ms |
716 KB |
Output is correct |
14 |
Correct |
555 ms |
512 KB |
Output is correct |
15 |
Correct |
63 ms |
596 KB |
Output is correct |
16 |
Correct |
76 ms |
528 KB |
Output is correct |
17 |
Correct |
120 ms |
656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1188 ms |
540 KB |
Output is correct |
2 |
Correct |
841 ms |
400 KB |
Output is correct |
3 |
Correct |
598 ms |
600 KB |
Output is correct |
4 |
Correct |
3 ms |
472 KB |
Output is correct |
5 |
Correct |
7 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
678 ms |
400 KB |
Output is correct |
8 |
Correct |
1126 ms |
544 KB |
Output is correct |
9 |
Correct |
700 ms |
400 KB |
Output is correct |
10 |
Correct |
630 ms |
508 KB |
Output is correct |
11 |
Correct |
9 ms |
468 KB |
Output is correct |
12 |
Correct |
7 ms |
468 KB |
Output is correct |
13 |
Correct |
6 ms |
468 KB |
Output is correct |
14 |
Correct |
5 ms |
592 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
680 ms |
512 KB |
Output is correct |
17 |
Correct |
631 ms |
656 KB |
Output is correct |
18 |
Correct |
640 ms |
528 KB |
Output is correct |
19 |
Correct |
667 ms |
400 KB |
Output is correct |
20 |
Correct |
727 ms |
532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
712 ms |
528 KB |
Partially correct |
2 |
Partially correct |
518 ms |
532 KB |
Partially correct |
3 |
Partially correct |
1125 ms |
508 KB |
Partially correct |
4 |
Partially correct |
860 ms |
552 KB |
Partially correct |
5 |
Partially correct |
691 ms |
500 KB |
Partially correct |
6 |
Partially correct |
561 ms |
528 KB |
Partially correct |
7 |
Partially correct |
619 ms |
528 KB |
Partially correct |
8 |
Partially correct |
3 ms |
464 KB |
Partially correct |
9 |
Partially correct |
6 ms |
468 KB |
Partially correct |
10 |
Partially correct |
2 ms |
468 KB |
Partially correct |
11 |
Partially correct |
608 ms |
508 KB |
Partially correct |
12 |
Partially correct |
673 ms |
516 KB |
Partially correct |
13 |
Partially correct |
1128 ms |
528 KB |
Partially correct |
14 |
Partially correct |
691 ms |
400 KB |
Partially correct |
15 |
Partially correct |
730 ms |
400 KB |
Partially correct |
16 |
Partially correct |
616 ms |
512 KB |
Partially correct |
17 |
Partially correct |
613 ms |
508 KB |
Partially correct |
18 |
Partially correct |
541 ms |
608 KB |
Partially correct |
19 |
Partially correct |
617 ms |
520 KB |
Partially correct |
20 |
Partially correct |
518 ms |
504 KB |
Partially correct |
21 |
Partially correct |
88 ms |
544 KB |
Partially correct |
22 |
Partially correct |
105 ms |
556 KB |
Partially correct |
23 |
Partially correct |
159 ms |
528 KB |
Partially correct |
24 |
Partially correct |
8 ms |
576 KB |
Partially correct |
25 |
Partially correct |
8 ms |
468 KB |
Partially correct |
26 |
Partially correct |
5 ms |
464 KB |
Partially correct |
27 |
Partially correct |
5 ms |
468 KB |
Partially correct |
28 |
Partially correct |
2 ms |
476 KB |
Partially correct |
29 |
Partially correct |
629 ms |
400 KB |
Partially correct |
30 |
Partially correct |
690 ms |
400 KB |
Partially correct |
31 |
Partially correct |
794 ms |
508 KB |
Partially correct |
32 |
Partially correct |
665 ms |
528 KB |
Partially correct |
33 |
Partially correct |
753 ms |
532 KB |
Partially correct |
34 |
Partially correct |
301 ms |
604 KB |
Partially correct |
35 |
Partially correct |
579 ms |
628 KB |
Partially correct |
36 |
Partially correct |
592 ms |
624 KB |
Partially correct |
37 |
Partially correct |
483 ms |
608 KB |
Partially correct |
38 |
Partially correct |
480 ms |
700 KB |
Partially correct |
39 |
Partially correct |
592 ms |
656 KB |
Partially correct |
40 |
Partially correct |
696 ms |
648 KB |
Partially correct |
41 |
Partially correct |
531 ms |
640 KB |
Partially correct |
42 |
Partially correct |
86 ms |
528 KB |
Partially correct |
43 |
Partially correct |
154 ms |
700 KB |
Partially correct |
44 |
Partially correct |
180 ms |
548 KB |
Partially correct |
45 |
Partially correct |
206 ms |
528 KB |
Partially correct |
46 |
Partially correct |
326 ms |
700 KB |
Partially correct |
47 |
Partially correct |
359 ms |
512 KB |
Partially correct |
48 |
Partially correct |
91 ms |
656 KB |
Partially correct |
49 |
Partially correct |
99 ms |
732 KB |
Partially correct |