Submission #480017

# Submission time Handle Problem Language Result Execution time Memory
480017 2021-10-14T09:22:47 Z stefantaga Stations (IOI20_stations) C++14
100 / 100
1066 ms 5532 KB
#include "stations.h"
#include <bits/stdc++.h>
 
using namespace std;
 
vector <int> graf[100005];
vector <int> labels;
int in[100005];
int out[100005];
 
int tajm;
 
void dfs(int v, int depth, int par){
    in[v] = ++tajm;
    for(auto c : graf[v]){
        if(c != par){
            dfs(c, depth+1, v);
        }
    }
    out[v] = ++tajm;
    if(depth%2){
        labels[v] = out[v];
    }
    else labels[v] = in[v];
}
 
map <int, int> koji;
 
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	labels.clear();
	labels.resize(n);
	for(int i=0; i<n; i++){
        graf[i].clear();
        in[i] = 0;
        out[i] = 0;
	}
	for(int i=0; i<n-1; i++){
        graf[u[i]].push_back(v[i]);
        graf[v[i]].push_back(u[i]);
	}
	dfs(0, 0, -1);
    int tr = -1;
    vector <int> vec;
    for(auto c : labels) vec.push_back(c);
    sort(vec.begin(), vec.end());
    koji.clear();
    for(auto c : vec){
        koji[c] = ++tr;
    }
    for(int i=0; i<n; i++) labels[i] = koji[labels[i]];
	return labels;
}
 
int find_next_station(int s, int t, std::vector<int> c) {
    if(s < c[0]){
        ///in
        if(s == 0){
            for(auto g : c) if(g >= t) return g;
        }
        int aut = c[c.size()-2];
        if(s <= t && t <= aut){
            for(auto g : c) if(g >= t) return g;
        }
        return c.back();
    }
    /// out
    int iin = c[1];
    if(iin <= t && t <= s){
        for(int j=c.size()-1; j>=1; j--){
            if(c[j] <= t) return c[j];
        }
    }
    return c[0];
}
# Verdict Execution time Memory Grader output
1 Correct 548 ms 5392 KB Output is correct
2 Correct 571 ms 5384 KB Output is correct
3 Correct 1010 ms 5264 KB Output is correct
4 Correct 780 ms 5264 KB Output is correct
5 Correct 685 ms 5264 KB Output is correct
6 Correct 444 ms 5392 KB Output is correct
7 Correct 588 ms 5392 KB Output is correct
8 Correct 8 ms 5340 KB Output is correct
9 Correct 7 ms 5340 KB Output is correct
10 Correct 4 ms 5340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 498 ms 5408 KB Output is correct
2 Correct 519 ms 5404 KB Output is correct
3 Correct 1037 ms 5152 KB Output is correct
4 Correct 703 ms 5264 KB Output is correct
5 Correct 715 ms 5264 KB Output is correct
6 Correct 428 ms 5284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 561 ms 5392 KB Output is correct
2 Correct 436 ms 5400 KB Output is correct
3 Correct 1066 ms 5264 KB Output is correct
4 Correct 831 ms 5264 KB Output is correct
5 Correct 637 ms 5292 KB Output is correct
6 Correct 574 ms 5392 KB Output is correct
7 Correct 489 ms 5400 KB Output is correct
8 Correct 4 ms 5352 KB Output is correct
9 Correct 8 ms 5340 KB Output is correct
10 Correct 4 ms 5340 KB Output is correct
11 Correct 713 ms 5280 KB Output is correct
12 Correct 485 ms 5412 KB Output is correct
13 Correct 545 ms 5388 KB Output is correct
14 Correct 426 ms 5392 KB Output is correct
15 Correct 68 ms 5320 KB Output is correct
16 Correct 59 ms 5280 KB Output is correct
17 Correct 128 ms 5392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 902 ms 5264 KB Output is correct
2 Correct 742 ms 5264 KB Output is correct
3 Correct 536 ms 5276 KB Output is correct
4 Correct 7 ms 5340 KB Output is correct
5 Correct 8 ms 5340 KB Output is correct
6 Correct 4 ms 5348 KB Output is correct
7 Correct 678 ms 5392 KB Output is correct
8 Correct 875 ms 5264 KB Output is correct
9 Correct 677 ms 5264 KB Output is correct
10 Correct 642 ms 5264 KB Output is correct
11 Correct 9 ms 5340 KB Output is correct
12 Correct 11 ms 5348 KB Output is correct
13 Correct 8 ms 5340 KB Output is correct
14 Correct 7 ms 5340 KB Output is correct
15 Correct 4 ms 5348 KB Output is correct
16 Correct 589 ms 5264 KB Output is correct
17 Correct 580 ms 5280 KB Output is correct
18 Correct 605 ms 5280 KB Output is correct
19 Correct 624 ms 5264 KB Output is correct
20 Correct 547 ms 5264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 632 ms 5404 KB Output is correct
2 Correct 471 ms 5384 KB Output is correct
3 Correct 802 ms 5264 KB Output is correct
4 Correct 753 ms 5264 KB Output is correct
5 Correct 739 ms 5392 KB Output is correct
6 Correct 563 ms 5392 KB Output is correct
7 Correct 585 ms 5388 KB Output is correct
8 Correct 5 ms 5348 KB Output is correct
9 Correct 8 ms 5340 KB Output is correct
10 Correct 5 ms 5360 KB Output is correct
11 Correct 495 ms 5392 KB Output is correct
12 Correct 509 ms 5392 KB Output is correct
13 Correct 938 ms 5392 KB Output is correct
14 Correct 778 ms 5272 KB Output is correct
15 Correct 613 ms 5276 KB Output is correct
16 Correct 531 ms 5280 KB Output is correct
17 Correct 685 ms 5264 KB Output is correct
18 Correct 445 ms 5412 KB Output is correct
19 Correct 494 ms 5532 KB Output is correct
20 Correct 498 ms 5392 KB Output is correct
21 Correct 63 ms 5320 KB Output is correct
22 Correct 68 ms 5284 KB Output is correct
23 Correct 135 ms 5392 KB Output is correct
24 Correct 10 ms 5364 KB Output is correct
25 Correct 10 ms 5340 KB Output is correct
26 Correct 6 ms 5340 KB Output is correct
27 Correct 6 ms 5340 KB Output is correct
28 Correct 4 ms 5340 KB Output is correct
29 Correct 579 ms 5264 KB Output is correct
30 Correct 593 ms 5264 KB Output is correct
31 Correct 485 ms 5284 KB Output is correct
32 Correct 576 ms 5284 KB Output is correct
33 Correct 533 ms 5276 KB Output is correct
34 Correct 355 ms 5412 KB Output is correct
35 Correct 522 ms 5388 KB Output is correct
36 Correct 528 ms 5408 KB Output is correct
37 Correct 559 ms 5512 KB Output is correct
38 Correct 559 ms 5392 KB Output is correct
39 Correct 431 ms 5512 KB Output is correct
40 Correct 544 ms 5532 KB Output is correct
41 Correct 545 ms 5444 KB Output is correct
42 Correct 60 ms 5264 KB Output is correct
43 Correct 148 ms 5408 KB Output is correct
44 Correct 131 ms 5400 KB Output is correct
45 Correct 179 ms 5404 KB Output is correct
46 Correct 348 ms 5264 KB Output is correct
47 Correct 371 ms 5392 KB Output is correct
48 Correct 64 ms 5412 KB Output is correct
49 Correct 58 ms 5472 KB Output is correct