# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
544362 |
2022-04-01T19:10:14 Z |
Lobo |
Stations (IOI20_stations) |
C++17 |
|
789 ms |
788 KB |
#include "stations.h"
#include<bits/stdc++.h>
using namespace std;
const long long inf = (long long) 1e18 + 10;
const int inf1 = (int) 1e9 + 10;
// #define int long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
const int maxn = 1100;
int find_next_station(int s, int t, vector<int> c) {
// cout << " " << s << " " << t << endl;
for(auto x : c) {
if(t == x) return x;
}
if(s == 0) {
for(int i = 0; i < c.size(); i++) {
if(t < c[i]) return c[i];
}
}
if(s < c[0]) {
//s é in
if(t < s) return c.back();
if(t > c.back()) return c.back();
for(int i = 0; i < c.size(); i++) {
if(t < c[i]) return c[i];
}
}
else {
if(t > s) return c[0];
if(t < c[0]) return c[0];
for(int i = c.size() -1; i >= 0; i--) {
if(t > c[i]) return c[i];
}
}
return -1;
}
vector<int> lab;
int timer = 0;
vector<int> g[maxn];
void dfs(int a, int col, int ant) {
if(col == 0) {
lab[a] = timer;
timer++;
}
for(auto b : g[a]) {
if(b == ant) continue;
dfs(b,col^1,a);
}
if(col == 1) {
lab[a] = timer;
timer++;
}
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
lab.clear();
lab.resize(n);
timer = 0;
for(int i = 0; i < n; i++) {
g[i].clear();
}
for(int i = 0; i < n-1; i++) {
g[u[i]].pb(v[i]);
g[v[i]].pb(u[i]);
}
dfs(0,0,0);
// for(int i = 0; i < n; i++) cout << i << " " << lab[i] << endl;
return lab;
}
// int32_t main() {
// ios::sync_with_stdio(false); cin.tie(0);
// freopen("in.in", "r", stdin);
// // freopen("out.out", "w", stdout);
// int tt = 1;
// cin >> tt;
// while(tt--) {
// int n, k; cin >> n >> k;
// vector<int> u,v;
// for(int i = 0; i < n-1; i++) {
// int a,b; cin >> a >> b;
// u.pb(a);
// v.pb(b);
// }
// label(n,k,u,v);
// int q; cin >> q;
// while(q--) {
// int s, t, ans;
// cin >> s >> t >> ans;
// vector<int> v;
// for(auto b : g[s]) {
// v.pb(lab[b]);
// }
// sort(all(v));
// cout << " " << lab[ans] << " =" << find_next_station(lab[s],lab[t],v) << endl;
// }
// }
// }
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:25:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for(int i = 0; i < c.size(); i++) {
| ~~^~~~~~~~~~
stations.cpp:34:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for(int i = 0; i < c.size(); i++) {
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
463 ms |
544 KB |
Output is correct |
2 |
Correct |
421 ms |
676 KB |
Output is correct |
3 |
Correct |
779 ms |
416 KB |
Output is correct |
4 |
Correct |
628 ms |
532 KB |
Output is correct |
5 |
Correct |
459 ms |
420 KB |
Output is correct |
6 |
Correct |
380 ms |
536 KB |
Output is correct |
7 |
Correct |
366 ms |
528 KB |
Output is correct |
8 |
Correct |
2 ms |
500 KB |
Output is correct |
9 |
Correct |
3 ms |
492 KB |
Output is correct |
10 |
Correct |
0 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
377 ms |
528 KB |
Output is correct |
2 |
Correct |
481 ms |
536 KB |
Output is correct |
3 |
Correct |
754 ms |
416 KB |
Output is correct |
4 |
Correct |
563 ms |
528 KB |
Output is correct |
5 |
Correct |
505 ms |
536 KB |
Output is correct |
6 |
Correct |
375 ms |
528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
479 ms |
672 KB |
Output is correct |
2 |
Correct |
372 ms |
672 KB |
Output is correct |
3 |
Correct |
737 ms |
416 KB |
Output is correct |
4 |
Correct |
551 ms |
420 KB |
Output is correct |
5 |
Correct |
502 ms |
512 KB |
Output is correct |
6 |
Correct |
350 ms |
544 KB |
Output is correct |
7 |
Correct |
374 ms |
548 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Correct |
3 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
486 ms |
540 KB |
Output is correct |
12 |
Correct |
407 ms |
780 KB |
Output is correct |
13 |
Correct |
413 ms |
652 KB |
Output is correct |
14 |
Correct |
407 ms |
676 KB |
Output is correct |
15 |
Correct |
44 ms |
572 KB |
Output is correct |
16 |
Correct |
55 ms |
556 KB |
Output is correct |
17 |
Correct |
89 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
789 ms |
416 KB |
Output is correct |
2 |
Correct |
615 ms |
416 KB |
Output is correct |
3 |
Correct |
525 ms |
416 KB |
Output is correct |
4 |
Correct |
1 ms |
500 KB |
Output is correct |
5 |
Correct |
3 ms |
500 KB |
Output is correct |
6 |
Correct |
0 ms |
536 KB |
Output is correct |
7 |
Correct |
458 ms |
532 KB |
Output is correct |
8 |
Correct |
715 ms |
416 KB |
Output is correct |
9 |
Correct |
558 ms |
420 KB |
Output is correct |
10 |
Correct |
504 ms |
416 KB |
Output is correct |
11 |
Correct |
5 ms |
500 KB |
Output is correct |
12 |
Correct |
4 ms |
492 KB |
Output is correct |
13 |
Correct |
5 ms |
500 KB |
Output is correct |
14 |
Correct |
2 ms |
492 KB |
Output is correct |
15 |
Correct |
2 ms |
492 KB |
Output is correct |
16 |
Correct |
439 ms |
532 KB |
Output is correct |
17 |
Correct |
429 ms |
540 KB |
Output is correct |
18 |
Correct |
389 ms |
416 KB |
Output is correct |
19 |
Correct |
454 ms |
416 KB |
Output is correct |
20 |
Correct |
441 ms |
416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
454 ms |
656 KB |
Output is correct |
2 |
Correct |
403 ms |
544 KB |
Output is correct |
3 |
Correct |
746 ms |
420 KB |
Output is correct |
4 |
Correct |
566 ms |
420 KB |
Output is correct |
5 |
Correct |
469 ms |
416 KB |
Output is correct |
6 |
Correct |
357 ms |
536 KB |
Output is correct |
7 |
Correct |
346 ms |
528 KB |
Output is correct |
8 |
Correct |
1 ms |
500 KB |
Output is correct |
9 |
Correct |
4 ms |
500 KB |
Output is correct |
10 |
Correct |
0 ms |
500 KB |
Output is correct |
11 |
Correct |
394 ms |
512 KB |
Output is correct |
12 |
Correct |
453 ms |
548 KB |
Output is correct |
13 |
Correct |
712 ms |
416 KB |
Output is correct |
14 |
Correct |
602 ms |
420 KB |
Output is correct |
15 |
Correct |
508 ms |
536 KB |
Output is correct |
16 |
Correct |
330 ms |
536 KB |
Output is correct |
17 |
Correct |
504 ms |
416 KB |
Output is correct |
18 |
Correct |
345 ms |
668 KB |
Output is correct |
19 |
Correct |
393 ms |
780 KB |
Output is correct |
20 |
Correct |
391 ms |
520 KB |
Output is correct |
21 |
Correct |
52 ms |
600 KB |
Output is correct |
22 |
Correct |
64 ms |
504 KB |
Output is correct |
23 |
Correct |
79 ms |
672 KB |
Output is correct |
24 |
Correct |
4 ms |
492 KB |
Output is correct |
25 |
Correct |
5 ms |
500 KB |
Output is correct |
26 |
Correct |
4 ms |
500 KB |
Output is correct |
27 |
Correct |
2 ms |
492 KB |
Output is correct |
28 |
Correct |
1 ms |
492 KB |
Output is correct |
29 |
Correct |
427 ms |
512 KB |
Output is correct |
30 |
Correct |
462 ms |
420 KB |
Output is correct |
31 |
Correct |
434 ms |
416 KB |
Output is correct |
32 |
Correct |
393 ms |
536 KB |
Output is correct |
33 |
Correct |
405 ms |
532 KB |
Output is correct |
34 |
Correct |
287 ms |
544 KB |
Output is correct |
35 |
Correct |
361 ms |
788 KB |
Output is correct |
36 |
Correct |
401 ms |
776 KB |
Output is correct |
37 |
Correct |
411 ms |
648 KB |
Output is correct |
38 |
Correct |
364 ms |
648 KB |
Output is correct |
39 |
Correct |
374 ms |
636 KB |
Output is correct |
40 |
Correct |
416 ms |
644 KB |
Output is correct |
41 |
Correct |
395 ms |
748 KB |
Output is correct |
42 |
Correct |
59 ms |
544 KB |
Output is correct |
43 |
Correct |
91 ms |
528 KB |
Output is correct |
44 |
Correct |
115 ms |
536 KB |
Output is correct |
45 |
Correct |
142 ms |
532 KB |
Output is correct |
46 |
Correct |
243 ms |
548 KB |
Output is correct |
47 |
Correct |
268 ms |
668 KB |
Output is correct |
48 |
Correct |
56 ms |
700 KB |
Output is correct |
49 |
Correct |
48 ms |
700 KB |
Output is correct |