Submission #1014680

# Submission time Handle Problem Language Result Execution time Memory
1014680 2024-07-05T09:21:27 Z Unforgettablepl Connecting Supertrees (IOI20_supertrees) C++17
100 / 100
140 ms 24184 KB
#include <bits/stdc++.h>
using namespace std;

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

int construct(std::vector<std::vector<int>> p) {
    int n = p.size();
    vector<vector<vector<int>>> components;
    vector<int> componentstype;
    for(int i=0;i<n;i++){
        int mycomponent = -1;
        for(int compo=0;compo<components.size();compo++){
            int shouldbe = p[i][components[compo][0][0]];
            shouldbe = min(shouldbe,1);
            if(shouldbe==1){
                if(mycomponent==-1)mycomponent=compo;
                else return 0;
            }
            for(auto&j:components[compo]){
                for(int&k:j){
                    if(shouldbe==0 and p[i][k]!=0)return 0;
                    if(shouldbe==1 and p[i][k]==0)return 0;
                }
            }
        }
        if(mycomponent==-1){
            components.push_back({{i}});
            componentstype.push_back(-1);
            continue;
        }
        int mychain = -1;
        for(int cha=0;cha<components[mycomponent].size();cha++){
            int shouldbe = p[i][components[mycomponent][cha][0]];
            if(shouldbe==1){
                if(mychain==-1)mychain=cha;
                else return 0;
            } else {
                if(componentstype[mycomponent]==-1)componentstype[mycomponent]=shouldbe;
                else if(componentstype[mycomponent]!=shouldbe)return 0;
            }
            for(int&j:components[mycomponent][cha]){
                if(shouldbe!=p[i][j])return 0;
            }
        }
        if(mychain==-1)components[mycomponent].push_back({i});
        else components[mycomponent][mychain].push_back(i);
    }
    vector<vector<int>> ans(n,vector<int>(n));
    for(int i=0;i<components.size();i++){
        vector<int> heads;
        for(auto&j:components[i]){
            heads.emplace_back(j[0]);
            for(int k=1;k<j.size();k++){
                ans[j[k-1]][j[k]]=ans[j[k]][j[k-1]]=true;
            }
        }
        if(heads.size()==2)return 0;
        if(heads.size()==1)continue;
        if(componentstype[i]==3)return 0;
        heads.emplace_back(heads.front());
        for(int j=1;j<heads.size();j++){
            ans[heads[j-1]][heads[j]]=ans[heads[j]][heads[j-1]]=true;
        }
        if(componentstype[i]==3)ans[heads[0]][heads[2]]=ans[heads[2]][heads[0]]=true;    
    }
    build(ans);
    return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:12:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::vector<int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |         for(int compo=0;compo<components.size();compo++){
      |                         ~~~~~^~~~~~~~~~~~~~~~~~
supertrees.cpp:32:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |         for(int cha=0;cha<components[mycomponent].size();cha++){
      |                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
supertrees.cpp:49:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::vector<int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |     for(int i=0;i<components.size();i++){
      |                 ~^~~~~~~~~~~~~~~~~~
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 k=1;k<j.size();k++){
      |                         ~^~~~~~~~~
supertrees.cpp:61:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |         for(int j=1;j<heads.size();j++){
      |                     ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 5 ms 1372 KB Output is correct
7 Correct 121 ms 24076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 5 ms 1372 KB Output is correct
7 Correct 121 ms 24076 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1372 KB Output is correct
13 Correct 121 ms 24080 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 672 KB Output is correct
17 Correct 54 ms 10068 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 29 ms 6236 KB Output is correct
21 Correct 115 ms 24144 KB Output is correct
22 Correct 123 ms 24152 KB Output is correct
23 Correct 125 ms 24144 KB Output is correct
24 Correct 117 ms 24148 KB Output is correct
25 Correct 50 ms 10116 KB Output is correct
26 Correct 64 ms 10068 KB Output is correct
27 Correct 119 ms 24148 KB Output is correct
28 Correct 122 ms 24056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 5 ms 1372 KB Output is correct
9 Correct 118 ms 24184 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1372 KB Output is correct
13 Correct 117 ms 24072 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 380 KB Output is correct
16 Correct 3 ms 700 KB Output is correct
17 Correct 56 ms 10248 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 40 ms 6232 KB Output is correct
22 Correct 115 ms 24144 KB Output is correct
23 Correct 115 ms 24144 KB Output is correct
24 Correct 139 ms 24148 KB Output is correct
25 Correct 51 ms 14196 KB Output is correct
26 Correct 53 ms 10068 KB Output is correct
27 Correct 115 ms 24072 KB Output is correct
28 Correct 123 ms 24144 KB Output is correct
29 Correct 48 ms 14160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 27 ms 6236 KB Output is correct
5 Correct 119 ms 24080 KB Output is correct
6 Correct 121 ms 24072 KB Output is correct
7 Correct 140 ms 24120 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 38 ms 6252 KB Output is correct
10 Correct 122 ms 24056 KB Output is correct
11 Correct 116 ms 24152 KB Output is correct
12 Correct 121 ms 24152 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 432 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 30 ms 6236 KB Output is correct
17 Correct 114 ms 24144 KB Output is correct
18 Correct 116 ms 24068 KB Output is correct
19 Correct 115 ms 24148 KB Output is correct
20 Correct 118 ms 24076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 5 ms 1372 KB Output is correct
7 Correct 121 ms 24076 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1372 KB Output is correct
13 Correct 121 ms 24080 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 672 KB Output is correct
17 Correct 54 ms 10068 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 29 ms 6236 KB Output is correct
21 Correct 115 ms 24144 KB Output is correct
22 Correct 123 ms 24152 KB Output is correct
23 Correct 125 ms 24144 KB Output is correct
24 Correct 117 ms 24148 KB Output is correct
25 Correct 50 ms 10116 KB Output is correct
26 Correct 64 ms 10068 KB Output is correct
27 Correct 119 ms 24148 KB Output is correct
28 Correct 122 ms 24056 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 5 ms 1372 KB Output is correct
37 Correct 118 ms 24184 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 5 ms 1372 KB Output is correct
41 Correct 117 ms 24072 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 0 ms 380 KB Output is correct
44 Correct 3 ms 700 KB Output is correct
45 Correct 56 ms 10248 KB Output is correct
46 Correct 0 ms 344 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 40 ms 6232 KB Output is correct
50 Correct 115 ms 24144 KB Output is correct
51 Correct 115 ms 24144 KB Output is correct
52 Correct 139 ms 24148 KB Output is correct
53 Correct 51 ms 14196 KB Output is correct
54 Correct 53 ms 10068 KB Output is correct
55 Correct 115 ms 24072 KB Output is correct
56 Correct 123 ms 24144 KB Output is correct
57 Correct 48 ms 14160 KB Output is correct
58 Correct 0 ms 344 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 4 ms 708 KB Output is correct
61 Correct 58 ms 10064 KB Output is correct
62 Correct 1 ms 344 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 31 ms 6320 KB Output is correct
66 Correct 67 ms 10120 KB Output is correct
67 Correct 57 ms 10152 KB Output is correct
68 Correct 48 ms 10068 KB Output is correct
69 Correct 50 ms 14160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 5 ms 1372 KB Output is correct
7 Correct 121 ms 24076 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1372 KB Output is correct
13 Correct 121 ms 24080 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 672 KB Output is correct
17 Correct 54 ms 10068 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 29 ms 6236 KB Output is correct
21 Correct 115 ms 24144 KB Output is correct
22 Correct 123 ms 24152 KB Output is correct
23 Correct 125 ms 24144 KB Output is correct
24 Correct 117 ms 24148 KB Output is correct
25 Correct 50 ms 10116 KB Output is correct
26 Correct 64 ms 10068 KB Output is correct
27 Correct 119 ms 24148 KB Output is correct
28 Correct 122 ms 24056 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 5 ms 1372 KB Output is correct
37 Correct 118 ms 24184 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 5 ms 1372 KB Output is correct
41 Correct 117 ms 24072 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 0 ms 380 KB Output is correct
44 Correct 3 ms 700 KB Output is correct
45 Correct 56 ms 10248 KB Output is correct
46 Correct 0 ms 344 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 40 ms 6232 KB Output is correct
50 Correct 115 ms 24144 KB Output is correct
51 Correct 115 ms 24144 KB Output is correct
52 Correct 139 ms 24148 KB Output is correct
53 Correct 51 ms 14196 KB Output is correct
54 Correct 53 ms 10068 KB Output is correct
55 Correct 115 ms 24072 KB Output is correct
56 Correct 123 ms 24144 KB Output is correct
57 Correct 48 ms 14160 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 344 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 27 ms 6236 KB Output is correct
62 Correct 119 ms 24080 KB Output is correct
63 Correct 121 ms 24072 KB Output is correct
64 Correct 140 ms 24120 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 38 ms 6252 KB Output is correct
67 Correct 122 ms 24056 KB Output is correct
68 Correct 116 ms 24152 KB Output is correct
69 Correct 121 ms 24152 KB Output is correct
70 Correct 0 ms 348 KB Output is correct
71 Correct 0 ms 432 KB Output is correct
72 Correct 0 ms 344 KB Output is correct
73 Correct 30 ms 6236 KB Output is correct
74 Correct 114 ms 24144 KB Output is correct
75 Correct 116 ms 24068 KB Output is correct
76 Correct 115 ms 24148 KB Output is correct
77 Correct 118 ms 24076 KB Output is correct
78 Correct 0 ms 344 KB Output is correct
79 Correct 0 ms 348 KB Output is correct
80 Correct 4 ms 708 KB Output is correct
81 Correct 58 ms 10064 KB Output is correct
82 Correct 1 ms 344 KB Output is correct
83 Correct 0 ms 348 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 31 ms 6320 KB Output is correct
86 Correct 67 ms 10120 KB Output is correct
87 Correct 57 ms 10152 KB Output is correct
88 Correct 48 ms 10068 KB Output is correct
89 Correct 50 ms 14160 KB Output is correct
90 Correct 0 ms 348 KB Output is correct
91 Correct 1 ms 348 KB Output is correct
92 Correct 2 ms 604 KB Output is correct
93 Correct 58 ms 10116 KB Output is correct
94 Correct 0 ms 344 KB Output is correct
95 Correct 0 ms 344 KB Output is correct
96 Correct 0 ms 348 KB Output is correct
97 Correct 12 ms 2948 KB Output is correct
98 Correct 52 ms 10328 KB Output is correct
99 Correct 55 ms 10064 KB Output is correct
100 Correct 53 ms 10064 KB Output is correct
101 Correct 54 ms 14084 KB Output is correct
102 Correct 52 ms 14088 KB Output is correct
103 Correct 48 ms 10064 KB Output is correct
104 Correct 52 ms 10148 KB Output is correct
105 Correct 56 ms 10120 KB Output is correct