Submission #631784

# Submission time Handle Problem Language Result Execution time Memory
631784 2022-08-18T17:41:01 Z PoonYaPat Connecting Supertrees (IOI20_supertrees) C++14
100 / 100
247 ms 25036 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
 
int head[1001],hc[1001];
bool ans[1001][1001];
vector<int> cycle[1001];
 
int construct(vector<vector<int>> p) {
 
	int n = p.size();
	vector<vector<int>> answer;
	memset(head,-1,sizeof(head));
	memset(hc,-1,sizeof(hc));
 
	//create tree
	for (int i=0; i<n; ++i) {
        for (int j=i+1; j<n; ++j) {
            if (p[i][j]==1) {
 
                if (head[i]!=-1 && head[j]!=-1) {
                    if (head[i]!=head[j]) return 0;
                }
                else if (head[i]!=-1) head[j]=head[i], ans[head[i]][j]=ans[j][head[i]]=true;
                else if (head[j]!=-1) head[i]=head[j], ans[head[j]][i]=ans[i][head[j]]=true;
                else {
                    head[i]=i; head[j]=i; ans[i][j]=ans[j][i]=true;
                }
            }
        }
	}
	for (int i=0; i<n; ++i) {
        if (head[i]==-1) head[i]=i;
	}
 
    //create cycle
    for (int i=0; i<n; ++i) {
        for (int j=i+1; j<n; ++j) {
            if (p[i][j]!=1 && head[i]==head[j] && head[i]!=-1) return 0;
            if (p[i][j]==2) {
                int x=head[i], y=head[j];
 
                if (hc[x]!=-1 && hc[y]!=-1) {
                    if (hc[x]!=hc[y]) return 0;
                }
                else if (hc[x]!=-1) hc[y]=hc[x], cycle[hc[x]].push_back(y);
                else if (hc[y]!=-1) hc[x]=hc[y], cycle[hc[y]].push_back(x);
                else {
                    hc[i]=i; hc[j]=i;
                    cycle[i].push_back(i);
                    cycle[i].push_back(j);
                }
            }
        }
	}
 
	for (int i=0; i<n; ++i) {
        if (cycle[i].size()) {
          	if (cycle[i].size()==2) return 0;
            for (int j=1; j<cycle[i].size(); ++j) ans[cycle[i][j]][cycle[i][j-1]]=ans[cycle[i][j-1]][cycle[i][j]]=true;
            ans[cycle[i][cycle[i].size()-1]][cycle[i][0]]=ans[cycle[i][0]][cycle[i][cycle[i].size()-1]]=true;
        }
	}
 
	//check component
	for (int i=0; i<n; ++i) {
        for (int j=i+1; j<n; ++j) {
            if (p[i][j]==3) return 0;
            if (p[i][j]==0 && hc[head[i]]==hc[head[j]] && hc[head[i]]!=-1) return 0;
        }
	}
 
	for (int i=0; i<n; ++i) {
        vector<int> row;
        for (int j=0; j<n; ++j) row.push_back(ans[i][j]);
        row.resize(n);
        answer.push_back(row);
    }
    build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:60:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |             for (int j=1; j<cycle[i].size(); ++j) ans[cycle[i][j]][cycle[i][j-1]]=ans[cycle[i][j-1]][cycle[i][j]]=true;
      |                           ~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 8 ms 1492 KB Output is correct
7 Correct 179 ms 24684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 8 ms 1492 KB Output is correct
7 Correct 179 ms 24684 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 23 ms 1256 KB Output is correct
13 Correct 247 ms 23432 KB Output is correct
14 Correct 1 ms 352 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 4 ms 860 KB Output is correct
17 Correct 160 ms 10536 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 352 KB Output is correct
20 Correct 47 ms 6800 KB Output is correct
21 Correct 187 ms 24152 KB Output is correct
22 Correct 223 ms 24212 KB Output is correct
23 Correct 195 ms 24128 KB Output is correct
24 Correct 196 ms 23360 KB Output is correct
25 Correct 86 ms 10444 KB Output is correct
26 Correct 179 ms 10288 KB Output is correct
27 Correct 210 ms 24132 KB Output is correct
28 Correct 195 ms 23344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 14 ms 1240 KB Output is correct
9 Correct 181 ms 23964 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 15 ms 1472 KB Output is correct
13 Correct 178 ms 24996 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 79 ms 11040 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 60 ms 6672 KB Output is correct
22 Correct 177 ms 25036 KB Output is correct
23 Correct 168 ms 24984 KB Output is correct
24 Correct 185 ms 24924 KB Output is correct
25 Correct 68 ms 10280 KB Output is correct
26 Correct 68 ms 10180 KB Output is correct
27 Correct 168 ms 24996 KB Output is correct
28 Correct 176 ms 25028 KB Output is correct
29 Correct 69 ms 10280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 48 ms 6676 KB Output is correct
5 Correct 175 ms 24192 KB Output is correct
6 Correct 176 ms 24116 KB Output is correct
7 Correct 175 ms 24196 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 43 ms 6792 KB Output is correct
10 Correct 170 ms 24160 KB Output is correct
11 Correct 174 ms 24140 KB Output is correct
12 Correct 187 ms 24236 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 43 ms 6736 KB Output is correct
17 Correct 175 ms 24168 KB Output is correct
18 Correct 184 ms 24160 KB Output is correct
19 Correct 171 ms 24184 KB Output is correct
20 Correct 176 ms 23320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 8 ms 1492 KB Output is correct
7 Correct 179 ms 24684 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 23 ms 1256 KB Output is correct
13 Correct 247 ms 23432 KB Output is correct
14 Correct 1 ms 352 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 4 ms 860 KB Output is correct
17 Correct 160 ms 10536 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 352 KB Output is correct
20 Correct 47 ms 6800 KB Output is correct
21 Correct 187 ms 24152 KB Output is correct
22 Correct 223 ms 24212 KB Output is correct
23 Correct 195 ms 24128 KB Output is correct
24 Correct 196 ms 23360 KB Output is correct
25 Correct 86 ms 10444 KB Output is correct
26 Correct 179 ms 10288 KB Output is correct
27 Correct 210 ms 24132 KB Output is correct
28 Correct 195 ms 23344 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 300 KB Output is correct
36 Correct 14 ms 1240 KB Output is correct
37 Correct 181 ms 23964 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 15 ms 1472 KB Output is correct
41 Correct 178 ms 24996 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 4 ms 852 KB Output is correct
45 Correct 79 ms 11040 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 1 ms 332 KB Output is correct
49 Correct 60 ms 6672 KB Output is correct
50 Correct 177 ms 25036 KB Output is correct
51 Correct 168 ms 24984 KB Output is correct
52 Correct 185 ms 24924 KB Output is correct
53 Correct 68 ms 10280 KB Output is correct
54 Correct 68 ms 10180 KB Output is correct
55 Correct 168 ms 24996 KB Output is correct
56 Correct 176 ms 25028 KB Output is correct
57 Correct 69 ms 10280 KB Output is correct
58 Correct 1 ms 328 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 4 ms 856 KB Output is correct
61 Correct 74 ms 11084 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 1 ms 332 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 50 ms 6680 KB Output is correct
66 Correct 71 ms 10148 KB Output is correct
67 Correct 74 ms 11040 KB Output is correct
68 Correct 88 ms 11024 KB Output is correct
69 Correct 69 ms 10320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 8 ms 1492 KB Output is correct
7 Correct 179 ms 24684 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 23 ms 1256 KB Output is correct
13 Correct 247 ms 23432 KB Output is correct
14 Correct 1 ms 352 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 4 ms 860 KB Output is correct
17 Correct 160 ms 10536 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 352 KB Output is correct
20 Correct 47 ms 6800 KB Output is correct
21 Correct 187 ms 24152 KB Output is correct
22 Correct 223 ms 24212 KB Output is correct
23 Correct 195 ms 24128 KB Output is correct
24 Correct 196 ms 23360 KB Output is correct
25 Correct 86 ms 10444 KB Output is correct
26 Correct 179 ms 10288 KB Output is correct
27 Correct 210 ms 24132 KB Output is correct
28 Correct 195 ms 23344 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 300 KB Output is correct
36 Correct 14 ms 1240 KB Output is correct
37 Correct 181 ms 23964 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 15 ms 1472 KB Output is correct
41 Correct 178 ms 24996 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 4 ms 852 KB Output is correct
45 Correct 79 ms 11040 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 1 ms 332 KB Output is correct
49 Correct 60 ms 6672 KB Output is correct
50 Correct 177 ms 25036 KB Output is correct
51 Correct 168 ms 24984 KB Output is correct
52 Correct 185 ms 24924 KB Output is correct
53 Correct 68 ms 10280 KB Output is correct
54 Correct 68 ms 10180 KB Output is correct
55 Correct 168 ms 24996 KB Output is correct
56 Correct 176 ms 25028 KB Output is correct
57 Correct 69 ms 10280 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 48 ms 6676 KB Output is correct
62 Correct 175 ms 24192 KB Output is correct
63 Correct 176 ms 24116 KB Output is correct
64 Correct 175 ms 24196 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 43 ms 6792 KB Output is correct
67 Correct 170 ms 24160 KB Output is correct
68 Correct 174 ms 24140 KB Output is correct
69 Correct 187 ms 24236 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 1 ms 332 KB Output is correct
72 Correct 0 ms 340 KB Output is correct
73 Correct 43 ms 6736 KB Output is correct
74 Correct 175 ms 24168 KB Output is correct
75 Correct 184 ms 24160 KB Output is correct
76 Correct 171 ms 24184 KB Output is correct
77 Correct 176 ms 23320 KB Output is correct
78 Correct 1 ms 328 KB Output is correct
79 Correct 1 ms 340 KB Output is correct
80 Correct 4 ms 856 KB Output is correct
81 Correct 74 ms 11084 KB Output is correct
82 Correct 1 ms 340 KB Output is correct
83 Correct 1 ms 332 KB Output is correct
84 Correct 1 ms 340 KB Output is correct
85 Correct 50 ms 6680 KB Output is correct
86 Correct 71 ms 10148 KB Output is correct
87 Correct 74 ms 11040 KB Output is correct
88 Correct 88 ms 11024 KB Output is correct
89 Correct 69 ms 10320 KB Output is correct
90 Correct 1 ms 340 KB Output is correct
91 Correct 1 ms 340 KB Output is correct
92 Correct 4 ms 832 KB Output is correct
93 Correct 72 ms 10788 KB Output is correct
94 Correct 1 ms 340 KB Output is correct
95 Correct 1 ms 340 KB Output is correct
96 Correct 1 ms 332 KB Output is correct
97 Correct 19 ms 3232 KB Output is correct
98 Correct 73 ms 11084 KB Output is correct
99 Correct 85 ms 11164 KB Output is correct
100 Correct 74 ms 11136 KB Output is correct
101 Correct 86 ms 10260 KB Output is correct
102 Correct 71 ms 10148 KB Output is correct
103 Correct 73 ms 11160 KB Output is correct
104 Correct 68 ms 11044 KB Output is correct
105 Correct 89 ms 10132 KB Output is correct