답안 #309358

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
309358 2020-10-03T09:58:56 Z xt0r3 기지국 (IOI20_stations) C++14
100 / 100
1249 ms 1280 KB
#include<bits/stdc++.h>
using namespace std;

int timer;
vector<bool> f;
vector<int> l, d;
vector<vector<int> > g;

void dfs(int id, bool flag = 1){
    d[id] = timer++;
    f[id] = flag;
    for(int v : g[id]) if(d[v] == -1) dfs(v, !flag);
    l[id] = timer++;
}

vector<int> label(int n, int k, vector<int> u, vector<int> v){
    f.resize(n);
    l.assign(n, -1);
    d.assign(n, -1);
    g.assign(n, {});
    for(int i = 0; i < n - 1; i++){
        g[u[i]].push_back(v[i]);
        g[v[i]].push_back(u[i]);
    }
    timer = 0;
    dfs(0);
    vector<int> ret(n);
    for(int i = 0; i < n; i++){
        ret[i] = (f[i] ? d[i] / 2 : l[i] / 2);
    }
    return ret;
}

int find_next_station(int s, int t, vector<int> c){
    if(s < c[0]){
        //c has leaving times
        if(t < s || t > c.back()) return c.back();
        return c[(int)(lower_bound(c.begin(), c.end(), t) - c.begin())];
    }
    else{
        //c has discovery times
        if(t < c.front() || t > s) return c.front();
        return c[(int)(upper_bound(c.begin(), c.end(), t) - c.begin()) - 1];
    }
}
/*
void test(vector<int> ll, vector<int> u, vector<int> v, int id, int t){
    vector<int> c;
    int n = v.size() + 1;
    for(int i = 0; i < n - 1; i++){
        if(u[i] == id) c.push_back(ll[v[i]]);
        if(v[i] == id) c.push_back(ll[u[i]]);
    }
    int got = find_next_station(ll[id], ll[t], c);
    sort(c.begin(), c.end());
    cout << "got: " << got << endl;
    cout << (int)(find(ll.begin(), ll.end(), got) - ll.begin()) << endl;
}

int main(){
    vector<int> v = {0, 0, 0, 1, 1, 4}, u = {1, 4, 6, 2, 3, 5};
    vector<int> labels = label(7, 10, u, v);
    test(labels, u, v, 0, 5);
}
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 516 ms 780 KB Output is correct
2 Correct 446 ms 1280 KB Output is correct
3 Correct 845 ms 640 KB Output is correct
4 Correct 642 ms 644 KB Output is correct
5 Correct 620 ms 640 KB Output is correct
6 Correct 482 ms 772 KB Output is correct
7 Correct 545 ms 776 KB Output is correct
8 Correct 3 ms 640 KB Output is correct
9 Correct 5 ms 640 KB Output is correct
10 Correct 2 ms 836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 557 ms 1012 KB Output is correct
2 Correct 535 ms 768 KB Output is correct
3 Correct 980 ms 648 KB Output is correct
4 Correct 772 ms 640 KB Output is correct
5 Correct 697 ms 804 KB Output is correct
6 Correct 470 ms 772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 555 ms 1024 KB Output is correct
2 Correct 463 ms 1016 KB Output is correct
3 Correct 975 ms 648 KB Output is correct
4 Correct 689 ms 772 KB Output is correct
5 Correct 606 ms 644 KB Output is correct
6 Correct 483 ms 768 KB Output is correct
7 Correct 508 ms 788 KB Output is correct
8 Correct 3 ms 648 KB Output is correct
9 Correct 6 ms 640 KB Output is correct
10 Correct 1 ms 640 KB Output is correct
11 Correct 644 ms 644 KB Output is correct
12 Correct 477 ms 768 KB Output is correct
13 Correct 475 ms 776 KB Output is correct
14 Correct 447 ms 820 KB Output is correct
15 Correct 59 ms 768 KB Output is correct
16 Correct 66 ms 768 KB Output is correct
17 Correct 102 ms 804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1117 ms 648 KB Output is correct
2 Correct 783 ms 892 KB Output is correct
3 Correct 737 ms 640 KB Output is correct
4 Correct 3 ms 640 KB Output is correct
5 Correct 6 ms 640 KB Output is correct
6 Correct 1 ms 640 KB Output is correct
7 Correct 721 ms 640 KB Output is correct
8 Correct 1008 ms 648 KB Output is correct
9 Correct 703 ms 644 KB Output is correct
10 Correct 793 ms 640 KB Output is correct
11 Correct 6 ms 656 KB Output is correct
12 Correct 6 ms 640 KB Output is correct
13 Correct 5 ms 640 KB Output is correct
14 Correct 5 ms 772 KB Output is correct
15 Correct 2 ms 640 KB Output is correct
16 Correct 566 ms 640 KB Output is correct
17 Correct 659 ms 640 KB Output is correct
18 Correct 603 ms 640 KB Output is correct
19 Correct 516 ms 640 KB Output is correct
20 Correct 503 ms 644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 549 ms 1024 KB Output is correct
2 Correct 759 ms 1008 KB Output is correct
3 Correct 1249 ms 640 KB Output is correct
4 Correct 720 ms 644 KB Output is correct
5 Correct 796 ms 640 KB Output is correct
6 Correct 625 ms 1024 KB Output is correct
7 Correct 591 ms 796 KB Output is correct
8 Correct 3 ms 640 KB Output is correct
9 Correct 4 ms 644 KB Output is correct
10 Correct 2 ms 644 KB Output is correct
11 Correct 570 ms 768 KB Output is correct
12 Correct 647 ms 768 KB Output is correct
13 Correct 1136 ms 652 KB Output is correct
14 Correct 855 ms 644 KB Output is correct
15 Correct 646 ms 640 KB Output is correct
16 Correct 568 ms 768 KB Output is correct
17 Correct 834 ms 652 KB Output is correct
18 Correct 654 ms 784 KB Output is correct
19 Correct 589 ms 768 KB Output is correct
20 Correct 602 ms 768 KB Output is correct
21 Correct 59 ms 892 KB Output is correct
22 Correct 71 ms 768 KB Output is correct
23 Correct 111 ms 768 KB Output is correct
24 Correct 5 ms 640 KB Output is correct
25 Correct 6 ms 640 KB Output is correct
26 Correct 5 ms 652 KB Output is correct
27 Correct 4 ms 644 KB Output is correct
28 Correct 2 ms 644 KB Output is correct
29 Correct 619 ms 640 KB Output is correct
30 Correct 653 ms 640 KB Output is correct
31 Correct 633 ms 640 KB Output is correct
32 Correct 622 ms 640 KB Output is correct
33 Correct 542 ms 648 KB Output is correct
34 Correct 327 ms 1008 KB Output is correct
35 Correct 600 ms 1024 KB Output is correct
36 Correct 458 ms 1024 KB Output is correct
37 Correct 467 ms 1024 KB Output is correct
38 Correct 469 ms 1024 KB Output is correct
39 Correct 461 ms 1024 KB Output is correct
40 Correct 566 ms 1024 KB Output is correct
41 Correct 610 ms 784 KB Output is correct
42 Correct 77 ms 828 KB Output is correct
43 Correct 122 ms 784 KB Output is correct
44 Correct 157 ms 768 KB Output is correct
45 Correct 164 ms 784 KB Output is correct
46 Correct 375 ms 768 KB Output is correct
47 Correct 376 ms 768 KB Output is correct
48 Correct 80 ms 768 KB Output is correct
49 Correct 63 ms 1024 KB Output is correct