답안 #672640

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
672640 2022-12-17T06:16:09 Z tbzard 기지국 (IOI20_stations) C++14
100 / 100
916 ms 756 KB
#include <bits/stdc++.h>
using namespace std;

void dfs1(int u, int p, vector<int> &weight, vector<vector<int> > &g){
    weight[u] = 1;
    for(int i=0;i<g[u].size();i++){
        int v = g[u][i];
        if(v != p){
            dfs1(v, u, weight, g);
            weight[u] += weight[v];
        }
    }
}
void dfs2(int u, int p, int d, int l, int r, vector<int> &ans, vector<int> &weight, vector<vector<int> > &g){
    if(d%2 == 0){
        ans[u] = l;
        l++;
    }
    else{
        ans[u] = r;
        r--;
    }
    for(int i=0;i<g[u].size();i++){
        int v = g[u][i];
        if(v != p){
            dfs2(v, u, d+1, l, l+weight[v]-1, ans, weight, g);
            l += weight[v];
        }
    }
}

vector<int> label(int n, int k, vector<int> u, vector<int> v){
    vector<vector<int> > g(n);
    vector<int> weight(n);
    vector<int> ans(n);
    for(int i=0;i<n-1;i++){
        g[u[i]].push_back(v[i]);
        g[v[i]].push_back(u[i]);
    }
    dfs1(0, 0, weight, g);
    dfs2(0, 0, 0, 0, n-1, ans, weight, g);
    return ans;
}
int find_next_station(int s, int t, vector<int> c){
    if(c.size() == 1) return c[0];
    int d = 1;
    if(s < c[0]) d = 0;

    if(d){
        int p = c[0];
        if(t < c[0] || t > s) return p;
        for(int i=0;i<(int)c.size()-1;i++){
            if(c[i] <= t && t <= c[i+1]-1) return c[i];
        }
        return c[(int)c.size()-1];
    }
    else{
        int p = c[(int)c.size()-1];
        if(t < s || t > c[(int)c.size()-1]) return p;
        for(int i=1;i<(int)c.size();i++){
            if(c[i-1]+1 <= t && t <= c[i]) return c[i];
        }
        return c[0];
    }
}

Compilation message

stations.cpp: In function 'void dfs1(int, int, std::vector<int>&, std::vector<std::vector<int> >&)':
stations.cpp:6:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    6 |     for(int i=0;i<g[u].size();i++){
      |                 ~^~~~~~~~~~~~
stations.cpp: In function 'void dfs2(int, int, int, int, int, std::vector<int>&, std::vector<int>&, std::vector<std::vector<int> >&)':
stations.cpp:23:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     for(int i=0;i<g[u].size();i++){
      |                 ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 465 ms 672 KB Output is correct
2 Correct 418 ms 616 KB Output is correct
3 Correct 842 ms 420 KB Output is correct
4 Correct 693 ms 420 KB Output is correct
5 Correct 495 ms 420 KB Output is correct
6 Correct 434 ms 548 KB Output is correct
7 Correct 472 ms 544 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 5 ms 492 KB Output is correct
10 Correct 1 ms 500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 383 ms 592 KB Output is correct
2 Correct 500 ms 508 KB Output is correct
3 Correct 870 ms 416 KB Output is correct
4 Correct 631 ms 504 KB Output is correct
5 Correct 563 ms 420 KB Output is correct
6 Correct 407 ms 496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 484 ms 632 KB Output is correct
2 Correct 365 ms 628 KB Output is correct
3 Correct 916 ms 420 KB Output is correct
4 Correct 556 ms 416 KB Output is correct
5 Correct 618 ms 500 KB Output is correct
6 Correct 387 ms 536 KB Output is correct
7 Correct 398 ms 628 KB Output is correct
8 Correct 2 ms 492 KB Output is correct
9 Correct 3 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 484 ms 500 KB Output is correct
12 Correct 444 ms 716 KB Output is correct
13 Correct 466 ms 636 KB Output is correct
14 Correct 394 ms 500 KB Output is correct
15 Correct 44 ms 488 KB Output is correct
16 Correct 62 ms 500 KB Output is correct
17 Correct 81 ms 644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 826 ms 492 KB Output is correct
2 Correct 571 ms 500 KB Output is correct
3 Correct 387 ms 508 KB Output is correct
4 Correct 2 ms 500 KB Output is correct
5 Correct 3 ms 500 KB Output is correct
6 Correct 1 ms 500 KB Output is correct
7 Correct 589 ms 544 KB Output is correct
8 Correct 788 ms 420 KB Output is correct
9 Correct 593 ms 416 KB Output is correct
10 Correct 529 ms 420 KB Output is correct
11 Correct 4 ms 488 KB Output is correct
12 Correct 6 ms 500 KB Output is correct
13 Correct 2 ms 492 KB Output is correct
14 Correct 4 ms 500 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
16 Correct 484 ms 480 KB Output is correct
17 Correct 461 ms 508 KB Output is correct
18 Correct 472 ms 500 KB Output is correct
19 Correct 381 ms 420 KB Output is correct
20 Correct 511 ms 508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 426 ms 636 KB Output is correct
2 Correct 479 ms 648 KB Output is correct
3 Correct 858 ms 512 KB Output is correct
4 Correct 665 ms 420 KB Output is correct
5 Correct 535 ms 416 KB Output is correct
6 Correct 443 ms 676 KB Output is correct
7 Correct 408 ms 548 KB Output is correct
8 Correct 3 ms 500 KB Output is correct
9 Correct 3 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 423 ms 500 KB Output is correct
12 Correct 504 ms 560 KB Output is correct
13 Correct 750 ms 420 KB Output is correct
14 Correct 611 ms 508 KB Output is correct
15 Correct 605 ms 416 KB Output is correct
16 Correct 388 ms 544 KB Output is correct
17 Correct 577 ms 508 KB Output is correct
18 Correct 406 ms 704 KB Output is correct
19 Correct 434 ms 704 KB Output is correct
20 Correct 433 ms 496 KB Output is correct
21 Correct 57 ms 472 KB Output is correct
22 Correct 62 ms 572 KB Output is correct
23 Correct 96 ms 592 KB Output is correct
24 Correct 4 ms 492 KB Output is correct
25 Correct 6 ms 492 KB Output is correct
26 Correct 4 ms 588 KB Output is correct
27 Correct 3 ms 500 KB Output is correct
28 Correct 2 ms 492 KB Output is correct
29 Correct 514 ms 508 KB Output is correct
30 Correct 502 ms 500 KB Output is correct
31 Correct 468 ms 444 KB Output is correct
32 Correct 487 ms 444 KB Output is correct
33 Correct 476 ms 420 KB Output is correct
34 Correct 273 ms 544 KB Output is correct
35 Correct 395 ms 712 KB Output is correct
36 Correct 426 ms 756 KB Output is correct
37 Correct 432 ms 628 KB Output is correct
38 Correct 378 ms 632 KB Output is correct
39 Correct 400 ms 684 KB Output is correct
40 Correct 406 ms 628 KB Output is correct
41 Correct 459 ms 632 KB Output is correct
42 Correct 55 ms 556 KB Output is correct
43 Correct 78 ms 572 KB Output is correct
44 Correct 114 ms 504 KB Output is correct
45 Correct 162 ms 528 KB Output is correct
46 Correct 272 ms 496 KB Output is correct
47 Correct 284 ms 548 KB Output is correct
48 Correct 56 ms 656 KB Output is correct
49 Correct 51 ms 500 KB Output is correct