답안 #398258

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
398258 2021-05-04T02:36:30 Z Everule 기지국 (IOI20_stations) C++17
100 / 100
1238 ms 776 KB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	std::vector<int> labels(n);
    vector<vector<int>> adj(n);
    for(int i=0;i<n-1;i++){
        adj[u[i]].push_back(v[i]);
        adj[v[i]].push_back(u[i]);
    }
    vector<int> tin(n), tout(n), dep(n);
    int t = 0;
    function<void(int,int)> dfs = [&](int u,int p){
        tin[u] = t++;
        for(auto &v : adj[u]){
            if(v == p) continue;
            dep[v] = dep[u] + 1;
            dfs(v, u);
        }
        tout[u] = t++;
    };
    dfs(0, 0);

    for(int i=0;i<n;i++){
        if(dep[i] % 2 == 0){
            labels[i] = tin[i];
        }
        else{
            labels[i] = tout[i];
        }
    }
    vector<int> l = labels;
    sort(l.begin(), l.end());
    for(auto &x : labels){
        x = lower_bound(l.begin(), l.end(), x) - l.begin() + 1;
    }
	return labels;
}

int find_next_station(int s, int t, std::vector<int> c) {
    if(c.size() == 1) return c[0];
    sort(c.begin(), c.end());
	if(c[0] < s){
        if(t < c[1] || t > s){
            return c[0];
        }
        for(int i=c.size()-1;i>0;--i){
            if(c[i] <= t) return c[i];
        }
    }
    else{
        reverse(c.begin(), c.end());
        if(t > c[1] || t < s){
            return c[0];
        }
        for(int i=c.size()-1;i>0;--i){
            if(c[i] >= t) return c[i];
        }
    }
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:60:1: warning: control reaches end of non-void function [-Wreturn-type]
   60 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 597 ms 624 KB Output is correct
2 Correct 616 ms 660 KB Output is correct
3 Correct 1218 ms 416 KB Output is correct
4 Correct 754 ms 492 KB Output is correct
5 Correct 711 ms 460 KB Output is correct
6 Correct 519 ms 620 KB Output is correct
7 Correct 601 ms 616 KB Output is correct
8 Correct 4 ms 548 KB Output is correct
9 Correct 5 ms 544 KB Output is correct
10 Correct 2 ms 472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 663 ms 600 KB Output is correct
2 Correct 718 ms 548 KB Output is correct
3 Correct 903 ms 488 KB Output is correct
4 Correct 807 ms 400 KB Output is correct
5 Correct 675 ms 488 KB Output is correct
6 Correct 531 ms 496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 732 ms 700 KB Output is correct
2 Correct 490 ms 716 KB Output is correct
3 Correct 1238 ms 428 KB Output is correct
4 Correct 745 ms 520 KB Output is correct
5 Correct 630 ms 620 KB Output is correct
6 Correct 573 ms 608 KB Output is correct
7 Correct 627 ms 620 KB Output is correct
8 Correct 3 ms 472 KB Output is correct
9 Correct 4 ms 472 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 675 ms 400 KB Output is correct
12 Correct 506 ms 648 KB Output is correct
13 Correct 615 ms 776 KB Output is correct
14 Correct 473 ms 532 KB Output is correct
15 Correct 70 ms 400 KB Output is correct
16 Correct 67 ms 528 KB Output is correct
17 Correct 107 ms 528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1061 ms 496 KB Output is correct
2 Correct 745 ms 400 KB Output is correct
3 Correct 714 ms 528 KB Output is correct
4 Correct 3 ms 480 KB Output is correct
5 Correct 4 ms 472 KB Output is correct
6 Correct 2 ms 472 KB Output is correct
7 Correct 787 ms 400 KB Output is correct
8 Correct 1150 ms 400 KB Output is correct
9 Correct 834 ms 400 KB Output is correct
10 Correct 716 ms 400 KB Output is correct
11 Correct 4 ms 472 KB Output is correct
12 Correct 5 ms 472 KB Output is correct
13 Correct 7 ms 472 KB Output is correct
14 Correct 4 ms 472 KB Output is correct
15 Correct 2 ms 472 KB Output is correct
16 Correct 601 ms 400 KB Output is correct
17 Correct 498 ms 400 KB Output is correct
18 Correct 560 ms 492 KB Output is correct
19 Correct 644 ms 428 KB Output is correct
20 Correct 672 ms 528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 678 ms 620 KB Output is correct
2 Correct 537 ms 624 KB Output is correct
3 Correct 1117 ms 480 KB Output is correct
4 Correct 813 ms 400 KB Output is correct
5 Correct 562 ms 400 KB Output is correct
6 Correct 526 ms 632 KB Output is correct
7 Correct 535 ms 616 KB Output is correct
8 Correct 3 ms 472 KB Output is correct
9 Correct 4 ms 472 KB Output is correct
10 Correct 2 ms 472 KB Output is correct
11 Correct 533 ms 712 KB Output is correct
12 Correct 554 ms 564 KB Output is correct
13 Correct 1037 ms 400 KB Output is correct
14 Correct 655 ms 496 KB Output is correct
15 Correct 722 ms 404 KB Output is correct
16 Correct 520 ms 496 KB Output is correct
17 Correct 762 ms 496 KB Output is correct
18 Correct 634 ms 528 KB Output is correct
19 Correct 606 ms 732 KB Output is correct
20 Correct 592 ms 528 KB Output is correct
21 Correct 81 ms 400 KB Output is correct
22 Correct 92 ms 552 KB Output is correct
23 Correct 126 ms 532 KB Output is correct
24 Correct 4 ms 472 KB Output is correct
25 Correct 6 ms 472 KB Output is correct
26 Correct 5 ms 472 KB Output is correct
27 Correct 4 ms 472 KB Output is correct
28 Correct 2 ms 480 KB Output is correct
29 Correct 639 ms 492 KB Output is correct
30 Correct 587 ms 400 KB Output is correct
31 Correct 681 ms 400 KB Output is correct
32 Correct 540 ms 488 KB Output is correct
33 Correct 552 ms 400 KB Output is correct
34 Correct 429 ms 748 KB Output is correct
35 Correct 598 ms 740 KB Output is correct
36 Correct 539 ms 648 KB Output is correct
37 Correct 630 ms 612 KB Output is correct
38 Correct 573 ms 492 KB Output is correct
39 Correct 483 ms 740 KB Output is correct
40 Correct 560 ms 608 KB Output is correct
41 Correct 580 ms 620 KB Output is correct
42 Correct 81 ms 564 KB Output is correct
43 Correct 145 ms 612 KB Output is correct
44 Correct 147 ms 528 KB Output is correct
45 Correct 187 ms 548 KB Output is correct
46 Correct 419 ms 588 KB Output is correct
47 Correct 371 ms 528 KB Output is correct
48 Correct 87 ms 528 KB Output is correct
49 Correct 71 ms 680 KB Output is correct