Submission #309424

# Submission time Handle Problem Language Result Execution time Memory
309424 2020-10-03T13:46:34 Z georgerapeanu Stations (IOI20_stations) C++17
100 / 100
1085 ms 1280 KB
#include "stations.h"
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

vector<int> graph[1005];

int lst;
void dfs(int nod,int tata,int lvl,vector<int> &labels){
    lst++;
    if(lvl == 0){
        labels[nod] = lst;
    }
    for(auto it:graph[nod]){
        if(it == tata){
            continue;
        }
        dfs(it,nod,lvl ^ 1,labels);
    }
    if(lvl == 1){
        labels[nod] = lst;
    }
    lst++;
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
    for(int i = 0;i < n;i++){
        graph[i].clear();
    }
	vector<int> labels(n);
	for (int i = 0; i < n - 1; i++) {
		graph[u[i]].push_back(v[i]);
		graph[v[i]].push_back(u[i]);
	}

    dfs(0,-1,0,labels);
    
    map<int,int> to_norm;

    for(auto it:labels){
        to_norm[it] = 0;
    }

    int lst = 0;

    for(auto &it:to_norm){
        it.second = ++lst;
    }

    for(auto &it:labels){
        it = to_norm[it];
    }

	return labels;
}

int find_next_station(int s, int t, vector<int> c) {
    sort(c.begin(),c.end());
    if(s < c[0]){
        int father = c.back();
        c.pop_back();
        if(t < s){
            return father;
        }
        for(int i = 0;i < (int)c.size();i++){
            if(c[i] >= t){
                return c[i];
            }
        }
        return father;
    }
    else{
        reverse(c.begin(),c.end());
        int father = c.back();
        c.pop_back();
        reverse(c.begin(),c.end());
        if(t > s){
            return father;
        }
        for(int i = (int)c.size() - 1;i >= 0;i--){
            if(c[i] <= t){
                return c[i];
            }
        }
        return father;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 692 ms 1024 KB Output is correct
2 Correct 548 ms 1008 KB Output is correct
3 Correct 1014 ms 764 KB Output is correct
4 Correct 709 ms 892 KB Output is correct
5 Correct 636 ms 892 KB Output is correct
6 Correct 523 ms 1024 KB Output is correct
7 Correct 483 ms 1024 KB Output is correct
8 Correct 3 ms 888 KB Output is correct
9 Correct 5 ms 768 KB Output is correct
10 Correct 1 ms 888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 552 ms 796 KB Output is correct
2 Correct 597 ms 768 KB Output is correct
3 Correct 1049 ms 768 KB Output is correct
4 Correct 731 ms 760 KB Output is correct
5 Correct 672 ms 892 KB Output is correct
6 Correct 521 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 589 ms 1008 KB Output is correct
2 Correct 515 ms 1024 KB Output is correct
3 Correct 1085 ms 760 KB Output is correct
4 Correct 872 ms 892 KB Output is correct
5 Correct 699 ms 772 KB Output is correct
6 Correct 538 ms 1024 KB Output is correct
7 Correct 474 ms 1024 KB Output is correct
8 Correct 3 ms 768 KB Output is correct
9 Correct 5 ms 768 KB Output is correct
10 Correct 1 ms 768 KB Output is correct
11 Correct 693 ms 776 KB Output is correct
12 Correct 491 ms 1000 KB Output is correct
13 Correct 520 ms 1032 KB Output is correct
14 Correct 499 ms 760 KB Output is correct
15 Correct 67 ms 768 KB Output is correct
16 Correct 76 ms 768 KB Output is correct
17 Correct 118 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 972 ms 760 KB Output is correct
2 Correct 753 ms 768 KB Output is correct
3 Correct 679 ms 888 KB Output is correct
4 Correct 3 ms 768 KB Output is correct
5 Correct 4 ms 888 KB Output is correct
6 Correct 2 ms 892 KB Output is correct
7 Correct 692 ms 904 KB Output is correct
8 Correct 915 ms 776 KB Output is correct
9 Correct 706 ms 892 KB Output is correct
10 Correct 620 ms 784 KB Output is correct
11 Correct 5 ms 768 KB Output is correct
12 Correct 7 ms 768 KB Output is correct
13 Correct 4 ms 900 KB Output is correct
14 Correct 3 ms 640 KB Output is correct
15 Correct 2 ms 768 KB Output is correct
16 Correct 510 ms 888 KB Output is correct
17 Correct 516 ms 768 KB Output is correct
18 Correct 537 ms 1016 KB Output is correct
19 Correct 485 ms 768 KB Output is correct
20 Correct 529 ms 884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 545 ms 1024 KB Output is correct
2 Correct 470 ms 1280 KB Output is correct
3 Correct 858 ms 768 KB Output is correct
4 Correct 628 ms 888 KB Output is correct
5 Correct 603 ms 1024 KB Output is correct
6 Correct 431 ms 1024 KB Output is correct
7 Correct 469 ms 1264 KB Output is correct
8 Correct 2 ms 892 KB Output is correct
9 Correct 4 ms 888 KB Output is correct
10 Correct 1 ms 768 KB Output is correct
11 Correct 448 ms 792 KB Output is correct
12 Correct 552 ms 792 KB Output is correct
13 Correct 889 ms 880 KB Output is correct
14 Correct 700 ms 768 KB Output is correct
15 Correct 590 ms 892 KB Output is correct
16 Correct 436 ms 1024 KB Output is correct
17 Correct 576 ms 884 KB Output is correct
18 Correct 470 ms 1024 KB Output is correct
19 Correct 474 ms 1092 KB Output is correct
20 Correct 451 ms 1024 KB Output is correct
21 Correct 59 ms 888 KB Output is correct
22 Correct 72 ms 828 KB Output is correct
23 Correct 113 ms 768 KB Output is correct
24 Correct 7 ms 888 KB Output is correct
25 Correct 6 ms 768 KB Output is correct
26 Correct 5 ms 768 KB Output is correct
27 Correct 4 ms 884 KB Output is correct
28 Correct 2 ms 768 KB Output is correct
29 Correct 516 ms 892 KB Output is correct
30 Correct 512 ms 900 KB Output is correct
31 Correct 511 ms 888 KB Output is correct
32 Correct 532 ms 768 KB Output is correct
33 Correct 527 ms 892 KB Output is correct
34 Correct 323 ms 1024 KB Output is correct
35 Correct 472 ms 1024 KB Output is correct
36 Correct 489 ms 1024 KB Output is correct
37 Correct 499 ms 1008 KB Output is correct
38 Correct 466 ms 1116 KB Output is correct
39 Correct 457 ms 1024 KB Output is correct
40 Correct 502 ms 1024 KB Output is correct
41 Correct 489 ms 1024 KB Output is correct
42 Correct 74 ms 816 KB Output is correct
43 Correct 115 ms 784 KB Output is correct
44 Correct 128 ms 780 KB Output is correct
45 Correct 210 ms 768 KB Output is correct
46 Correct 335 ms 800 KB Output is correct
47 Correct 389 ms 1024 KB Output is correct
48 Correct 72 ms 972 KB Output is correct
49 Correct 76 ms 1024 KB Output is correct