답안 #672616

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
672616 2022-12-17T02:04:06 Z tbzard 슈퍼트리 잇기 (IOI20_supertrees) C++14
100 / 100
202 ms 24076 KB
#include <bits/stdc++.h>
using namespace std;

void build(vector<vector<int> > b);

bool vis[1002], use[1002];
int construct(vector<vector<int> > p){
    int n = (int)p.size();
    vector<vector<int> > ans(n);
    for(int i=0;i<n;i++) ans[i].resize(n);
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(p[i][j] == 3) return 0;
        }
    }
    for(int i=0;i<n;i++){
        if(vis[i]) continue;
        memset(use, 0, sizeof(use));
        vis[i] = 1;

        vector<int> x;
        vector<vector<int> > y;
        queue<int> q;
        q.push(i);
        while(!q.empty()){
            int u = q.front();
            q.pop();
            vis[u] = 1;
            bool use = 0;
            x.push_back(u);
            vector<int> z;
            for(int v=0;v<n;v++){
                if(vis[v] || p[u][v] == 0) continue;
                if(p[u][v] == 1){
                    ans[u][v] = 1;
                    ans[v][u] = 1;
                    vis[v] = 1;
                    z.push_back(v);
                }
                else if(!use){
                    use = 1;
                    q.push(v);
                }
            }
            y.push_back(z);
        }
        for(int i=0;i<y.size();i++){
            for(int j=0;j<y[i].size();j++){
                for(int k=j+1;k<y[i].size();k++){
                    if(p[y[i][j]][y[i][k]] != 1) return 0;
                }
            }
            for(int j=0;j<x.size();j++){
                if(i == j) continue;
                for(int k=0;k<y[i].size();k++){
                    if(p[x[j]][y[i][k]] != 2) return 0;
                }
            }
            for(int j=0;j<y.size();j++){
                if(i == j) continue;
                for(int a=0;a<y[i].size();a++){
                    for(int b=0;b<y[j].size();b++){
                        if(p[y[i][a]][y[j][b]] != 2) return 0;
                    }
                }
            }
        }
        for(int i=0;i<x.size();i++){
            for(int j=i+1;j<x.size();j++){
                if(p[x[i]][x[j]] != 2) return 0;
            }
        }

        vector<int> X;
        for(int i=0;i<x.size();i++){
            X.push_back(x[i]);
            use[x[i]] = 1;
            for(int j=0;j<y[i].size();j++){
                X.push_back(y[i][j]);
                use[y[i][j]] = 1;
            }
        }

        for(int i=0;i<X.size();i++){
            for(int j=0;j<n;j++){
                if(use[j]) continue;
                if(p[X[i]][j] != 0) return 0;
            }
        }

        if((int)x.size() == 2) return 0;
        else if((int)x.size() > 2){
            for(int i=0;i<(int)x.size()-1;i++){
                ans[x[i]][x[i+1]] = 1;
                ans[x[i+1]][x[i]] = 1;
            }
            ans[x[0]][x[(int)x.size()-1]] = 1;
            ans[x[(int)x.size()-1]][x[0]] = 1;
        }
    }

    build(ans);
    return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:47:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         for(int i=0;i<y.size();i++){
      |                     ~^~~~~~~~~
supertrees.cpp:48:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |             for(int j=0;j<y[i].size();j++){
      |                         ~^~~~~~~~~~~~
supertrees.cpp:49:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |                 for(int k=j+1;k<y[i].size();k++){
      |                               ~^~~~~~~~~~~~
supertrees.cpp:53:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |             for(int j=0;j<x.size();j++){
      |                         ~^~~~~~~~~
supertrees.cpp:55:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |                 for(int k=0;k<y[i].size();k++){
      |                             ~^~~~~~~~~~~~
supertrees.cpp:59:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |             for(int j=0;j<y.size();j++){
      |                         ~^~~~~~~~~
supertrees.cpp:61:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |                 for(int a=0;a<y[i].size();a++){
      |                             ~^~~~~~~~~~~~
supertrees.cpp:62:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |                     for(int b=0;b<y[j].size();b++){
      |                                 ~^~~~~~~~~~~~
supertrees.cpp:68:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |         for(int i=0;i<x.size();i++){
      |                     ~^~~~~~~~~
supertrees.cpp:69:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |             for(int j=i+1;j<x.size();j++){
      |                           ~^~~~~~~~~
supertrees.cpp:75:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |         for(int i=0;i<x.size();i++){
      |                     ~^~~~~~~~~
supertrees.cpp:78:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |             for(int j=0;j<y[i].size();j++){
      |                         ~^~~~~~~~~~~~
supertrees.cpp:84:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |         for(int i=0;i<X.size();i++){
      |                     ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1140 KB Output is correct
7 Correct 166 ms 22024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1140 KB Output is correct
7 Correct 166 ms 22024 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 8 ms 1108 KB Output is correct
13 Correct 163 ms 22020 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 75 ms 12036 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 43 ms 5756 KB Output is correct
21 Correct 161 ms 22040 KB Output is correct
22 Correct 159 ms 22036 KB Output is correct
23 Correct 169 ms 21948 KB Output is correct
24 Correct 170 ms 22052 KB Output is correct
25 Correct 74 ms 12048 KB Output is correct
26 Correct 63 ms 12048 KB Output is correct
27 Correct 179 ms 22024 KB Output is correct
28 Correct 160 ms 21964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 7 ms 1108 KB Output is correct
9 Correct 186 ms 22032 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1172 KB Output is correct
13 Correct 172 ms 22032 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 83 ms 12180 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 42 ms 5764 KB Output is correct
22 Correct 166 ms 22040 KB Output is correct
23 Correct 173 ms 21972 KB Output is correct
24 Correct 178 ms 21988 KB Output is correct
25 Correct 66 ms 12040 KB Output is correct
26 Correct 66 ms 12036 KB Output is correct
27 Correct 161 ms 21964 KB Output is correct
28 Correct 182 ms 22008 KB Output is correct
29 Correct 65 ms 12036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 41 ms 5776 KB Output is correct
5 Correct 161 ms 22020 KB Output is correct
6 Correct 160 ms 22020 KB Output is correct
7 Correct 202 ms 21964 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 42 ms 5720 KB Output is correct
10 Correct 163 ms 22028 KB Output is correct
11 Correct 162 ms 21948 KB Output is correct
12 Correct 170 ms 22040 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 42 ms 5728 KB Output is correct
17 Correct 164 ms 23932 KB Output is correct
18 Correct 174 ms 23940 KB Output is correct
19 Correct 161 ms 23932 KB Output is correct
20 Correct 160 ms 24076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1140 KB Output is correct
7 Correct 166 ms 22024 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 8 ms 1108 KB Output is correct
13 Correct 163 ms 22020 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 75 ms 12036 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 43 ms 5756 KB Output is correct
21 Correct 161 ms 22040 KB Output is correct
22 Correct 159 ms 22036 KB Output is correct
23 Correct 169 ms 21948 KB Output is correct
24 Correct 170 ms 22052 KB Output is correct
25 Correct 74 ms 12048 KB Output is correct
26 Correct 63 ms 12048 KB Output is correct
27 Correct 179 ms 22024 KB Output is correct
28 Correct 160 ms 21964 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 7 ms 1108 KB Output is correct
37 Correct 186 ms 22032 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 7 ms 1172 KB Output is correct
41 Correct 172 ms 22032 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 4 ms 724 KB Output is correct
45 Correct 83 ms 12180 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 42 ms 5764 KB Output is correct
50 Correct 166 ms 22040 KB Output is correct
51 Correct 173 ms 21972 KB Output is correct
52 Correct 178 ms 21988 KB Output is correct
53 Correct 66 ms 12040 KB Output is correct
54 Correct 66 ms 12036 KB Output is correct
55 Correct 161 ms 21964 KB Output is correct
56 Correct 182 ms 22008 KB Output is correct
57 Correct 65 ms 12036 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 3 ms 724 KB Output is correct
61 Correct 75 ms 12040 KB Output is correct
62 Correct 0 ms 212 KB Output is correct
63 Correct 0 ms 212 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Correct 47 ms 5748 KB Output is correct
66 Correct 72 ms 14028 KB Output is correct
67 Correct 69 ms 14076 KB Output is correct
68 Correct 74 ms 14080 KB Output is correct
69 Correct 65 ms 13996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1140 KB Output is correct
7 Correct 166 ms 22024 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 8 ms 1108 KB Output is correct
13 Correct 163 ms 22020 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 75 ms 12036 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 43 ms 5756 KB Output is correct
21 Correct 161 ms 22040 KB Output is correct
22 Correct 159 ms 22036 KB Output is correct
23 Correct 169 ms 21948 KB Output is correct
24 Correct 170 ms 22052 KB Output is correct
25 Correct 74 ms 12048 KB Output is correct
26 Correct 63 ms 12048 KB Output is correct
27 Correct 179 ms 22024 KB Output is correct
28 Correct 160 ms 21964 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 7 ms 1108 KB Output is correct
37 Correct 186 ms 22032 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 7 ms 1172 KB Output is correct
41 Correct 172 ms 22032 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 4 ms 724 KB Output is correct
45 Correct 83 ms 12180 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 42 ms 5764 KB Output is correct
50 Correct 166 ms 22040 KB Output is correct
51 Correct 173 ms 21972 KB Output is correct
52 Correct 178 ms 21988 KB Output is correct
53 Correct 66 ms 12040 KB Output is correct
54 Correct 66 ms 12036 KB Output is correct
55 Correct 161 ms 21964 KB Output is correct
56 Correct 182 ms 22008 KB Output is correct
57 Correct 65 ms 12036 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 41 ms 5776 KB Output is correct
62 Correct 161 ms 22020 KB Output is correct
63 Correct 160 ms 22020 KB Output is correct
64 Correct 202 ms 21964 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 42 ms 5720 KB Output is correct
67 Correct 163 ms 22028 KB Output is correct
68 Correct 162 ms 21948 KB Output is correct
69 Correct 170 ms 22040 KB Output is correct
70 Correct 0 ms 212 KB Output is correct
71 Correct 0 ms 212 KB Output is correct
72 Correct 0 ms 212 KB Output is correct
73 Correct 42 ms 5728 KB Output is correct
74 Correct 164 ms 23932 KB Output is correct
75 Correct 174 ms 23940 KB Output is correct
76 Correct 161 ms 23932 KB Output is correct
77 Correct 160 ms 24076 KB Output is correct
78 Correct 0 ms 212 KB Output is correct
79 Correct 0 ms 212 KB Output is correct
80 Correct 3 ms 724 KB Output is correct
81 Correct 75 ms 12040 KB Output is correct
82 Correct 0 ms 212 KB Output is correct
83 Correct 0 ms 212 KB Output is correct
84 Correct 0 ms 212 KB Output is correct
85 Correct 47 ms 5748 KB Output is correct
86 Correct 72 ms 14028 KB Output is correct
87 Correct 69 ms 14076 KB Output is correct
88 Correct 74 ms 14080 KB Output is correct
89 Correct 65 ms 13996 KB Output is correct
90 Correct 1 ms 296 KB Output is correct
91 Correct 0 ms 212 KB Output is correct
92 Correct 4 ms 852 KB Output is correct
93 Correct 69 ms 14072 KB Output is correct
94 Correct 1 ms 212 KB Output is correct
95 Correct 0 ms 308 KB Output is correct
96 Correct 0 ms 300 KB Output is correct
97 Correct 17 ms 3660 KB Output is correct
98 Correct 70 ms 14092 KB Output is correct
99 Correct 68 ms 14088 KB Output is correct
100 Correct 63 ms 14068 KB Output is correct
101 Correct 65 ms 14076 KB Output is correct
102 Correct 67 ms 14084 KB Output is correct
103 Correct 63 ms 13972 KB Output is correct
104 Correct 62 ms 14076 KB Output is correct
105 Correct 74 ms 14080 KB Output is correct