답안 #309931

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
309931 2020-10-05T02:27:57 Z tjdgus4384 기지국 (IOI20_stations) C++14
100 / 100
1029 ms 1040 KB
#include<bits/stdc++.h>
#include "stations.h"
using namespace std;
vector<int> path[1001];
bool visited[1001];
int tsize[1001], lb[1001];
 
int dfs(int x){
    int s = 1;
    for(int i = 0;i < path[x].size();i++){
        if(visited[path[x][i]]) continue;
        visited[path[x][i]] = true;
        s += dfs(path[x][i]);
    }
    return tsize[x] = s;
}
void dfs2(int x, int s, int e, int d){
    if(d%2 == 0) {lb[x] = s; s++;}
    else lb[x] = e;
    for(int i = 0;i < path[x].size();i++){
        if(visited[path[x][i]]) continue;
        visited[path[x][i]] = true;
        dfs2(path[x][i], s, s+tsize[path[x][i]]-1, d+1);
        s+=tsize[path[x][i]];
    }
}
 
vector<int> label(int n, int k, vector<int> u, vector<int> v){
    for(int i = 0;i < n;i++) path[i].clear();
    for(int i = 0;i < n-1;i++){
        path[u[i]].push_back(v[i]);
        path[v[i]].push_back(u[i]);
    }
    for(int i = 0;i < n;i++) visited[i] = false;
    visited[0] = true;
    dfs(0);
    for(int i = 0;i < n;i++) visited[i] = false;
    visited[0] = true;
    dfs2(0, 0, n-1, 0);
    vector<int> ret;
    for(int i = 0;i < n;i++) ret.push_back(lb[i]);
    return ret;
}
 
int find_next_station(int s, int t, vector<int> c){
    if(c[0] < s){
        if(t > s || t < c[0]) return c[0];
        c.push_back(1001);
        for(int i = 0;i < c.size() - 1;i++){
            if(t >= c[i] && t < c[i+1]) return c[i];
        }
    }
    else{
        if(t < s || t > c.back()) return c.back();
        for(int i = 0;i < c.size();i++){
            if(t <= c[i]) return c[i];
        }
    }
}

Compilation message

stations.cpp: In function 'int dfs(int)':
stations.cpp:10:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |     for(int i = 0;i < path[x].size();i++){
      |                   ~~^~~~~~~~~~~~~~~~
stations.cpp: In function 'void dfs2(int, int, int, int)':
stations.cpp:20:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for(int i = 0;i < path[x].size();i++){
      |                   ~~^~~~~~~~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:49:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |         for(int i = 0;i < c.size() - 1;i++){
      |                       ~~^~~~~~~~~~~~~~
stations.cpp:55:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         for(int i = 0;i < c.size();i++){
      |                       ~~^~~~~~~~~~
stations.cpp:59:1: warning: control reaches end of non-void function [-Wreturn-type]
   59 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 578 ms 768 KB Output is correct
2 Correct 478 ms 768 KB Output is correct
3 Correct 888 ms 868 KB Output is correct
4 Correct 753 ms 876 KB Output is correct
5 Correct 683 ms 768 KB Output is correct
6 Correct 455 ms 768 KB Output is correct
7 Correct 546 ms 1040 KB Output is correct
8 Correct 3 ms 808 KB Output is correct
9 Correct 5 ms 768 KB Output is correct
10 Correct 2 ms 872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 556 ms 808 KB Output is correct
2 Correct 589 ms 812 KB Output is correct
3 Correct 913 ms 892 KB Output is correct
4 Correct 655 ms 768 KB Output is correct
5 Correct 714 ms 768 KB Output is correct
6 Correct 543 ms 820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 605 ms 768 KB Output is correct
2 Correct 446 ms 776 KB Output is correct
3 Correct 1029 ms 1024 KB Output is correct
4 Correct 666 ms 1040 KB Output is correct
5 Correct 653 ms 868 KB Output is correct
6 Correct 560 ms 776 KB Output is correct
7 Correct 470 ms 768 KB Output is correct
8 Correct 3 ms 896 KB Output is correct
9 Correct 6 ms 768 KB Output is correct
10 Correct 1 ms 768 KB Output is correct
11 Correct 625 ms 768 KB Output is correct
12 Correct 522 ms 768 KB Output is correct
13 Correct 515 ms 1024 KB Output is correct
14 Correct 452 ms 816 KB Output is correct
15 Correct 61 ms 868 KB Output is correct
16 Correct 66 ms 768 KB Output is correct
17 Correct 130 ms 816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 891 ms 1008 KB Output is correct
2 Correct 691 ms 872 KB Output is correct
3 Correct 580 ms 872 KB Output is correct
4 Correct 3 ms 868 KB Output is correct
5 Correct 5 ms 768 KB Output is correct
6 Correct 1 ms 768 KB Output is correct
7 Correct 639 ms 1040 KB Output is correct
8 Correct 911 ms 1024 KB Output is correct
9 Correct 668 ms 876 KB Output is correct
10 Correct 597 ms 872 KB Output is correct
11 Correct 6 ms 996 KB Output is correct
12 Correct 5 ms 768 KB Output is correct
13 Correct 5 ms 876 KB Output is correct
14 Correct 3 ms 768 KB Output is correct
15 Correct 1 ms 864 KB Output is correct
16 Correct 502 ms 896 KB Output is correct
17 Correct 509 ms 1040 KB Output is correct
18 Correct 510 ms 1040 KB Output is correct
19 Correct 525 ms 1024 KB Output is correct
20 Correct 537 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 615 ms 1000 KB Output is correct
2 Correct 468 ms 784 KB Output is correct
3 Correct 888 ms 872 KB Output is correct
4 Correct 724 ms 872 KB Output is correct
5 Correct 637 ms 872 KB Output is correct
6 Correct 460 ms 896 KB Output is correct
7 Correct 470 ms 800 KB Output is correct
8 Correct 2 ms 880 KB Output is correct
9 Correct 4 ms 868 KB Output is correct
10 Correct 1 ms 868 KB Output is correct
11 Correct 499 ms 820 KB Output is correct
12 Correct 696 ms 816 KB Output is correct
13 Correct 879 ms 860 KB Output is correct
14 Correct 634 ms 872 KB Output is correct
15 Correct 596 ms 780 KB Output is correct
16 Correct 450 ms 828 KB Output is correct
17 Correct 603 ms 768 KB Output is correct
18 Correct 482 ms 788 KB Output is correct
19 Correct 493 ms 1024 KB Output is correct
20 Correct 444 ms 816 KB Output is correct
21 Correct 58 ms 896 KB Output is correct
22 Correct 69 ms 952 KB Output is correct
23 Correct 111 ms 944 KB Output is correct
24 Correct 6 ms 868 KB Output is correct
25 Correct 6 ms 864 KB Output is correct
26 Correct 4 ms 768 KB Output is correct
27 Correct 4 ms 872 KB Output is correct
28 Correct 1 ms 876 KB Output is correct
29 Correct 520 ms 1024 KB Output is correct
30 Correct 524 ms 876 KB Output is correct
31 Correct 544 ms 868 KB Output is correct
32 Correct 527 ms 880 KB Output is correct
33 Correct 612 ms 876 KB Output is correct
34 Correct 406 ms 788 KB Output is correct
35 Correct 552 ms 1024 KB Output is correct
36 Correct 488 ms 768 KB Output is correct
37 Correct 487 ms 960 KB Output is correct
38 Correct 445 ms 896 KB Output is correct
39 Correct 576 ms 1024 KB Output is correct
40 Correct 539 ms 792 KB Output is correct
41 Correct 530 ms 888 KB Output is correct
42 Correct 68 ms 896 KB Output is correct
43 Correct 113 ms 812 KB Output is correct
44 Correct 145 ms 768 KB Output is correct
45 Correct 170 ms 1008 KB Output is correct
46 Correct 415 ms 824 KB Output is correct
47 Correct 334 ms 768 KB Output is correct
48 Correct 68 ms 1024 KB Output is correct
49 Correct 64 ms 1024 KB Output is correct