답안 #313458

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
313458 2020-10-16T04:09:48 Z qiangbao 기지국 (IOI20_stations) C++14
100 / 100
1075 ms 1264 KB
#include <iostream>
#include <vector>

#define pb push_back

using namespace std;

typedef pair<int, int> pii;

vector<int> con[1001];
vector<int> son[1001];
bool used[1001];

vector<int> ans;

void rt(int x)
{
    int i;
    
    used[x]=true;
    for(i=0;i<con[x].size();i++){
        int f=con[x][i];
        if(!used[f])
            son[x].pb(f), used[f]=true, rt(f);
    }
}

pii wk(int x, int lev, int label)
{
    pii ret={label, 1};
    int i;
    
    if(lev%2==0){
        ans[x]=label;
        for(i=0;i<son[x].size();i++){
            pii f=wk(son[x][i], lev+1, label+1);
            label+=f.second;
            ret.first=max(ret.first, f.first);
            ret.second+=f.second;
        }
    }
    if(lev%2==1){
        for(i=0;i<son[x].size();i++){
            pii f=wk(son[x][i], lev+1, label);
            label+=f.second;
            ret.first=max(ret.first, f.first);
            ret.second+=f.second;
        }
        ans[x]=label;
    }
    
    return ret;
}

vector<int> label(int n, int k, vector<int> u, vector<int> v)
{
    int i;
    for(i=0;i<=1000;i++){
        con[i].clear();
        son[i].clear();
        used[i]=false;
    }
    ans.clear();
    
    for(i=0;i<n-1;i++){
        con[u[i]].pb(v[i]);
        con[v[i]].pb(u[i]);
        ans.pb(0);
    }
    ans.pb(0);
    rt(0);
    wk(0, 1, 0);
    
    return ans;
}

int find_next_station(int s, int t, vector<int> nei)
{
    int lev=1;
    int i;
    
    if(nei[nei.size()-1]>s)
        lev=0;
    
    if(lev==1){
        bool maxi=false;
        if(t<=nei[0] || t>s)
            maxi=true;
        if(maxi)
            return nei[0];
        for(i=int(nei.size())-1;i>=0;i--)
            if(t>=nei[i])
                return nei[i];
    }
    else{
        bool mini=false;
        if(t>=nei[nei.size()-1] || t<s)
            mini=true;
        if(mini)
            return nei[nei.size()-1];
        for(i=0;i<nei.size();i++)
            if(t<=nei[i])
                return nei[i];
    }
    
    return -1;
}

//int main()
//{
//    int i;
//
//    label(13, 15, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12});
//    for(i=0;i<ans.size();i++)
//        cout << ans[i] << " ";
//    cout << endl;
//
//    cout << find_next_station(2, 6, {8, 9}) << endl;
//}

Compilation message

stations.cpp: In function 'void rt(int)':
stations.cpp:21:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for(i=0;i<con[x].size();i++){
      |             ~^~~~~~~~~~~~~~
stations.cpp: In function 'pii wk(int, int, int)':
stations.cpp:35:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         for(i=0;i<son[x].size();i++){
      |                 ~^~~~~~~~~~~~~~
stations.cpp:43:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |         for(i=0;i<son[x].size();i++){
      |                 ~^~~~~~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:101:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |         for(i=0;i<nei.size();i++)
      |                 ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 618 ms 1068 KB Output is correct
2 Correct 482 ms 1008 KB Output is correct
3 Correct 901 ms 1024 KB Output is correct
4 Correct 679 ms 896 KB Output is correct
5 Correct 621 ms 1160 KB Output is correct
6 Correct 524 ms 1076 KB Output is correct
7 Correct 508 ms 1024 KB Output is correct
8 Correct 3 ms 980 KB Output is correct
9 Correct 4 ms 896 KB Output is correct
10 Correct 2 ms 896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 501 ms 896 KB Output is correct
2 Correct 534 ms 768 KB Output is correct
3 Correct 871 ms 1244 KB Output is correct
4 Correct 681 ms 976 KB Output is correct
5 Correct 635 ms 988 KB Output is correct
6 Correct 512 ms 916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 625 ms 1060 KB Output is correct
2 Correct 450 ms 1068 KB Output is correct
3 Correct 929 ms 984 KB Output is correct
4 Correct 762 ms 984 KB Output is correct
5 Correct 743 ms 1168 KB Output is correct
6 Correct 494 ms 1024 KB Output is correct
7 Correct 487 ms 1100 KB Output is correct
8 Correct 3 ms 980 KB Output is correct
9 Correct 4 ms 992 KB Output is correct
10 Correct 2 ms 1116 KB Output is correct
11 Correct 694 ms 984 KB Output is correct
12 Correct 628 ms 1072 KB Output is correct
13 Correct 637 ms 1028 KB Output is correct
14 Correct 491 ms 1008 KB Output is correct
15 Correct 51 ms 976 KB Output is correct
16 Correct 69 ms 768 KB Output is correct
17 Correct 145 ms 900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 961 ms 976 KB Output is correct
2 Correct 751 ms 980 KB Output is correct
3 Correct 743 ms 896 KB Output is correct
4 Correct 3 ms 976 KB Output is correct
5 Correct 5 ms 896 KB Output is correct
6 Correct 2 ms 768 KB Output is correct
7 Correct 716 ms 996 KB Output is correct
8 Correct 1075 ms 1024 KB Output is correct
9 Correct 689 ms 768 KB Output is correct
10 Correct 633 ms 896 KB Output is correct
11 Correct 5 ms 984 KB Output is correct
12 Correct 8 ms 768 KB Output is correct
13 Correct 6 ms 984 KB Output is correct
14 Correct 4 ms 976 KB Output is correct
15 Correct 2 ms 896 KB Output is correct
16 Correct 492 ms 1024 KB Output is correct
17 Correct 510 ms 1176 KB Output is correct
18 Correct 545 ms 984 KB Output is correct
19 Correct 536 ms 1152 KB Output is correct
20 Correct 498 ms 896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 547 ms 1024 KB Output is correct
2 Correct 451 ms 1160 KB Output is correct
3 Correct 985 ms 980 KB Output is correct
4 Correct 677 ms 984 KB Output is correct
5 Correct 633 ms 984 KB Output is correct
6 Correct 555 ms 1072 KB Output is correct
7 Correct 463 ms 1108 KB Output is correct
8 Correct 3 ms 984 KB Output is correct
9 Correct 5 ms 768 KB Output is correct
10 Correct 2 ms 980 KB Output is correct
11 Correct 445 ms 768 KB Output is correct
12 Correct 597 ms 768 KB Output is correct
13 Correct 1053 ms 984 KB Output is correct
14 Correct 644 ms 980 KB Output is correct
15 Correct 614 ms 768 KB Output is correct
16 Correct 455 ms 916 KB Output is correct
17 Correct 680 ms 1024 KB Output is correct
18 Correct 475 ms 1024 KB Output is correct
19 Correct 480 ms 1024 KB Output is correct
20 Correct 546 ms 896 KB Output is correct
21 Correct 72 ms 896 KB Output is correct
22 Correct 72 ms 944 KB Output is correct
23 Correct 108 ms 1152 KB Output is correct
24 Correct 6 ms 976 KB Output is correct
25 Correct 6 ms 988 KB Output is correct
26 Correct 5 ms 984 KB Output is correct
27 Correct 4 ms 896 KB Output is correct
28 Correct 2 ms 988 KB Output is correct
29 Correct 524 ms 980 KB Output is correct
30 Correct 538 ms 896 KB Output is correct
31 Correct 548 ms 1160 KB Output is correct
32 Correct 638 ms 980 KB Output is correct
33 Correct 569 ms 992 KB Output is correct
34 Correct 332 ms 1088 KB Output is correct
35 Correct 435 ms 1144 KB Output is correct
36 Correct 507 ms 1024 KB Output is correct
37 Correct 492 ms 1008 KB Output is correct
38 Correct 551 ms 1136 KB Output is correct
39 Correct 458 ms 1024 KB Output is correct
40 Correct 546 ms 1264 KB Output is correct
41 Correct 532 ms 1144 KB Output is correct
42 Correct 60 ms 924 KB Output is correct
43 Correct 110 ms 1024 KB Output is correct
44 Correct 130 ms 1108 KB Output is correct
45 Correct 198 ms 1024 KB Output is correct
46 Correct 378 ms 1148 KB Output is correct
47 Correct 307 ms 1116 KB Output is correct
48 Correct 66 ms 1024 KB Output is correct
49 Correct 70 ms 1068 KB Output is correct