답안 #530344

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
530344 2022-02-25T07:15:35 Z byunjaewoo 기지국 (IOI20_stations) C++17
100 / 100
877 ms 784 KB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;

const int Nmax=1010;
int N, K, Size[Nmax], Dep[Nmax];
vector<int> adj[Nmax], L;

void DFS_Size(int curr, int prev) {
    Size[curr]=1;
    for(int next:adj[curr]) if(next!=prev) {
        Dep[next]=Dep[curr]+1;
        DFS_Size(next, curr);
        Size[curr]+=Size[next];
    }
}

void DFS_Label(int curr, int prev, int s, int e) {
    if(Dep[curr]%2) L[curr]=s++;
    else L[curr]=e--;
    for(int next:adj[curr]) if(next!=prev) {
        DFS_Label(next, curr, s, s+Size[next]-1);
        s+=Size[next];
    }
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
    for(int i=0; i<N; i++) adj[i].clear(), Size[i]=Dep[i]=0;
    N=n, K=k;
    for(int i=0; i<N-1; i++) {
        adj[u[i]].push_back(v[i]);
        adj[v[i]].push_back(u[i]);
    }
    DFS_Size(0, -1);
    L.clear(); L.resize(N);
    DFS_Label(0, -1, 0, N-1);
    return L;
}

int find_next_station(int s, int t, vector<int> c) {
    for(int i:c) if(i==t) return i;
    if(c.size()==1) return c[0];
    if(c[0]>s) {
        if(t<s || t>c[c.size()-2]) return c.back();
        else return (*lower_bound(c.begin(), c.end(), t));
    }
    else {
        if(t<c[0] || t>s) return c[0];
        else return (*(lower_bound(c.begin(), c.end(), t)-1));
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 445 ms 532 KB Output is correct
2 Correct 470 ms 628 KB Output is correct
3 Correct 830 ms 404 KB Output is correct
4 Correct 641 ms 404 KB Output is correct
5 Correct 524 ms 404 KB Output is correct
6 Correct 410 ms 640 KB Output is correct
7 Correct 412 ms 504 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 4 ms 468 KB Output is correct
10 Correct 1 ms 476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 446 ms 528 KB Output is correct
2 Correct 434 ms 520 KB Output is correct
3 Correct 874 ms 508 KB Output is correct
4 Correct 508 ms 532 KB Output is correct
5 Correct 595 ms 556 KB Output is correct
6 Correct 407 ms 500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 531 ms 656 KB Output is correct
2 Correct 344 ms 628 KB Output is correct
3 Correct 805 ms 504 KB Output is correct
4 Correct 674 ms 400 KB Output is correct
5 Correct 505 ms 512 KB Output is correct
6 Correct 451 ms 640 KB Output is correct
7 Correct 440 ms 620 KB Output is correct
8 Correct 3 ms 452 KB Output is correct
9 Correct 3 ms 604 KB Output is correct
10 Correct 0 ms 476 KB Output is correct
11 Correct 498 ms 404 KB Output is correct
12 Correct 420 ms 736 KB Output is correct
13 Correct 460 ms 624 KB Output is correct
14 Correct 362 ms 500 KB Output is correct
15 Correct 47 ms 512 KB Output is correct
16 Correct 62 ms 532 KB Output is correct
17 Correct 92 ms 656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 877 ms 640 KB Output is correct
2 Correct 595 ms 532 KB Output is correct
3 Correct 600 ms 528 KB Output is correct
4 Correct 1 ms 476 KB Output is correct
5 Correct 4 ms 468 KB Output is correct
6 Correct 0 ms 576 KB Output is correct
7 Correct 551 ms 504 KB Output is correct
8 Correct 870 ms 520 KB Output is correct
9 Correct 642 ms 400 KB Output is correct
10 Correct 556 ms 492 KB Output is correct
11 Correct 5 ms 464 KB Output is correct
12 Correct 5 ms 576 KB Output is correct
13 Correct 4 ms 468 KB Output is correct
14 Correct 4 ms 716 KB Output is correct
15 Correct 2 ms 592 KB Output is correct
16 Correct 487 ms 512 KB Output is correct
17 Correct 531 ms 404 KB Output is correct
18 Correct 451 ms 508 KB Output is correct
19 Correct 507 ms 632 KB Output is correct
20 Correct 468 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 576 ms 636 KB Output is correct
2 Correct 427 ms 636 KB Output is correct
3 Correct 873 ms 500 KB Output is correct
4 Correct 588 ms 508 KB Output is correct
5 Correct 502 ms 512 KB Output is correct
6 Correct 464 ms 524 KB Output is correct
7 Correct 424 ms 508 KB Output is correct
8 Correct 3 ms 584 KB Output is correct
9 Correct 4 ms 468 KB Output is correct
10 Correct 2 ms 480 KB Output is correct
11 Correct 392 ms 508 KB Output is correct
12 Correct 557 ms 516 KB Output is correct
13 Correct 795 ms 400 KB Output is correct
14 Correct 593 ms 404 KB Output is correct
15 Correct 639 ms 512 KB Output is correct
16 Correct 391 ms 524 KB Output is correct
17 Correct 582 ms 492 KB Output is correct
18 Correct 511 ms 628 KB Output is correct
19 Correct 465 ms 636 KB Output is correct
20 Correct 378 ms 508 KB Output is correct
21 Correct 71 ms 528 KB Output is correct
22 Correct 54 ms 688 KB Output is correct
23 Correct 133 ms 784 KB Output is correct
24 Correct 6 ms 468 KB Output is correct
25 Correct 5 ms 468 KB Output is correct
26 Correct 4 ms 548 KB Output is correct
27 Correct 6 ms 476 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 543 ms 496 KB Output is correct
30 Correct 416 ms 516 KB Output is correct
31 Correct 491 ms 400 KB Output is correct
32 Correct 481 ms 516 KB Output is correct
33 Correct 459 ms 400 KB Output is correct
34 Correct 320 ms 620 KB Output is correct
35 Correct 448 ms 632 KB Output is correct
36 Correct 378 ms 744 KB Output is correct
37 Correct 368 ms 628 KB Output is correct
38 Correct 456 ms 524 KB Output is correct
39 Correct 347 ms 628 KB Output is correct
40 Correct 443 ms 620 KB Output is correct
41 Correct 419 ms 640 KB Output is correct
42 Correct 60 ms 528 KB Output is correct
43 Correct 107 ms 752 KB Output is correct
44 Correct 119 ms 528 KB Output is correct
45 Correct 136 ms 552 KB Output is correct
46 Correct 313 ms 508 KB Output is correct
47 Correct 289 ms 520 KB Output is correct
48 Correct 62 ms 664 KB Output is correct
49 Correct 51 ms 676 KB Output is correct