Submission #418839

# Submission time Handle Problem Language Result Execution time Memory
418839 2021-06-06T04:03:41 Z qwerasdfzxcl Connecting Supertrees (IOI20_supertrees) C++14
100 / 100
272 ms 24004 KB
#include "supertrees.h"
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
int col[1010];
bool visited[1010];

int construct(vector<vector<int>> p) {
	int n = p.size();
	vector<vector<int>> answer, C;
	answer.resize(n);
	for (int i=0;i<n;i++) answer[i].resize(n, 0);

	bool valid0 = 1;
	for (int i=0;i<n;i++){
        for (int j=0;j<n;j++) if (p[i][j]==3) valid0 = 0;
	}
	if (!valid0) return 0;

    for (int i=0;i<n;i++) if (!visited[i]){
        visited[i] = 1;
        vector<int> tmp;
        C.push_back(tmp);
        C.back().push_back(i);
        col[i] = C.size();
        for (int j=0;j<n;j++) if (!visited[j] && p[i][j]){
            C.back().push_back(j);
            col[j] = C.size();
            visited[j] = 1;
        }
    }

    bool valid1 = 1;
    for (int i=0;i<n;i++){
        for (int j=0;j<n;j++){
            if (i==j) valid1 &= (p[i][j]==1);
            else if (col[i]==col[j]) valid1 &= (p[i][j]>0);
            else valid1 &= (p[i][j]==0);
        }
    }
    if (!valid1) return 0;

    for (auto &V:C){
        vector<vector<int>> C1;
        vector<int> col1(1010, 0);
        fill(visited, visited+1010, 0);
        for (auto &x:V) if (!visited[x]){
            visited[x] = 1;
            vector<int> tmp;
            C1.push_back(tmp);
            C1.back().push_back(x);
            col1[x] = C1.size();
            for (int j=0;j<n;j++) if (col[j]==col[x] && !visited[j] && p[x][j]==1){
                C1.back().push_back(j);
                visited[j] = 1;
                col1[j] = C1.size();
            }
        }

        bool valid2 = 1;
        for (auto &x:V){
            for (auto &y:V){
                if (col1[x]==col1[y]) valid2 &= (p[x][y]==1);
                else valid2 &= (p[x][y]==2);
            }
        }
        if (!valid2) return 0;
        if ((int)C1.size()==2) return 0;

        for (int i=0;i<(int)C1.size()-1;i++){
            answer[C1[i][0]][C1[i+1][0]] = 1;
            answer[C1[i+1][0]][C1[i][0]] = 1;
        }
        if ((int)C1.size()>1){
            answer[C1.back()[0]][C1[0][0]] = 1;
            answer[C1[0][0]][C1.back()[0]] = 1;
        }
        for (auto &U:C1){
            for (int i=1;i<(int)U.size();i++){
                answer[U[0]][U[i]] = 1;
                answer[U[i]][U[0]] = 1;
            }
        }

    }
	build(answer);
	return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 11 ms 1120 KB Output is correct
7 Correct 229 ms 22024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 11 ms 1120 KB Output is correct
7 Correct 229 ms 22024 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 10 ms 1100 KB Output is correct
13 Correct 236 ms 22032 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 716 KB Output is correct
17 Correct 112 ms 12072 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 81 ms 5652 KB Output is correct
21 Correct 227 ms 22044 KB Output is correct
22 Correct 232 ms 22060 KB Output is correct
23 Correct 238 ms 21956 KB Output is correct
24 Correct 232 ms 22008 KB Output is correct
25 Correct 107 ms 12032 KB Output is correct
26 Correct 100 ms 12028 KB Output is correct
27 Correct 246 ms 22024 KB Output is correct
28 Correct 246 ms 22172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 10 ms 1220 KB Output is correct
9 Correct 242 ms 24004 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 12 ms 1228 KB Output is correct
13 Correct 254 ms 24004 KB Output is correct
14 Correct 1 ms 236 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 844 KB Output is correct
17 Correct 105 ms 14072 KB Output is correct
18 Correct 1 ms 296 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 60 ms 6248 KB Output is correct
22 Correct 239 ms 23928 KB Output is correct
23 Correct 235 ms 23940 KB Output is correct
24 Correct 246 ms 23932 KB Output is correct
25 Correct 99 ms 14020 KB Output is correct
26 Correct 100 ms 14072 KB Output is correct
27 Correct 231 ms 23936 KB Output is correct
28 Correct 245 ms 24000 KB Output is correct
29 Correct 101 ms 14064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 57 ms 5696 KB Output is correct
5 Correct 234 ms 22016 KB Output is correct
6 Correct 231 ms 21956 KB Output is correct
7 Correct 272 ms 21956 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 59 ms 5684 KB Output is correct
10 Correct 236 ms 22012 KB Output is correct
11 Correct 248 ms 22012 KB Output is correct
12 Correct 247 ms 22048 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 60 ms 5744 KB Output is correct
17 Correct 235 ms 21988 KB Output is correct
18 Correct 258 ms 21956 KB Output is correct
19 Correct 238 ms 22160 KB Output is correct
20 Correct 235 ms 22024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 11 ms 1120 KB Output is correct
7 Correct 229 ms 22024 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 10 ms 1100 KB Output is correct
13 Correct 236 ms 22032 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 716 KB Output is correct
17 Correct 112 ms 12072 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 81 ms 5652 KB Output is correct
21 Correct 227 ms 22044 KB Output is correct
22 Correct 232 ms 22060 KB Output is correct
23 Correct 238 ms 21956 KB Output is correct
24 Correct 232 ms 22008 KB Output is correct
25 Correct 107 ms 12032 KB Output is correct
26 Correct 100 ms 12028 KB Output is correct
27 Correct 246 ms 22024 KB Output is correct
28 Correct 246 ms 22172 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 10 ms 1220 KB Output is correct
37 Correct 242 ms 24004 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 12 ms 1228 KB Output is correct
41 Correct 254 ms 24004 KB Output is correct
42 Correct 1 ms 236 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 5 ms 844 KB Output is correct
45 Correct 105 ms 14072 KB Output is correct
46 Correct 1 ms 296 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 60 ms 6248 KB Output is correct
50 Correct 239 ms 23928 KB Output is correct
51 Correct 235 ms 23940 KB Output is correct
52 Correct 246 ms 23932 KB Output is correct
53 Correct 99 ms 14020 KB Output is correct
54 Correct 100 ms 14072 KB Output is correct
55 Correct 231 ms 23936 KB Output is correct
56 Correct 245 ms 24000 KB Output is correct
57 Correct 101 ms 14064 KB Output is correct
58 Correct 1 ms 384 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 5 ms 844 KB Output is correct
61 Correct 105 ms 14072 KB Output is correct
62 Correct 1 ms 204 KB Output is correct
63 Correct 1 ms 296 KB Output is correct
64 Correct 1 ms 204 KB Output is correct
65 Correct 64 ms 6300 KB Output is correct
66 Correct 127 ms 14060 KB Output is correct
67 Correct 107 ms 14148 KB Output is correct
68 Correct 96 ms 14020 KB Output is correct
69 Correct 100 ms 14064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 11 ms 1120 KB Output is correct
7 Correct 229 ms 22024 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 10 ms 1100 KB Output is correct
13 Correct 236 ms 22032 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 716 KB Output is correct
17 Correct 112 ms 12072 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 81 ms 5652 KB Output is correct
21 Correct 227 ms 22044 KB Output is correct
22 Correct 232 ms 22060 KB Output is correct
23 Correct 238 ms 21956 KB Output is correct
24 Correct 232 ms 22008 KB Output is correct
25 Correct 107 ms 12032 KB Output is correct
26 Correct 100 ms 12028 KB Output is correct
27 Correct 246 ms 22024 KB Output is correct
28 Correct 246 ms 22172 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 10 ms 1220 KB Output is correct
37 Correct 242 ms 24004 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 12 ms 1228 KB Output is correct
41 Correct 254 ms 24004 KB Output is correct
42 Correct 1 ms 236 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 5 ms 844 KB Output is correct
45 Correct 105 ms 14072 KB Output is correct
46 Correct 1 ms 296 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 60 ms 6248 KB Output is correct
50 Correct 239 ms 23928 KB Output is correct
51 Correct 235 ms 23940 KB Output is correct
52 Correct 246 ms 23932 KB Output is correct
53 Correct 99 ms 14020 KB Output is correct
54 Correct 100 ms 14072 KB Output is correct
55 Correct 231 ms 23936 KB Output is correct
56 Correct 245 ms 24000 KB Output is correct
57 Correct 101 ms 14064 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 1 ms 204 KB Output is correct
61 Correct 57 ms 5696 KB Output is correct
62 Correct 234 ms 22016 KB Output is correct
63 Correct 231 ms 21956 KB Output is correct
64 Correct 272 ms 21956 KB Output is correct
65 Correct 1 ms 204 KB Output is correct
66 Correct 59 ms 5684 KB Output is correct
67 Correct 236 ms 22012 KB Output is correct
68 Correct 248 ms 22012 KB Output is correct
69 Correct 247 ms 22048 KB Output is correct
70 Correct 1 ms 204 KB Output is correct
71 Correct 1 ms 204 KB Output is correct
72 Correct 1 ms 204 KB Output is correct
73 Correct 60 ms 5744 KB Output is correct
74 Correct 235 ms 21988 KB Output is correct
75 Correct 258 ms 21956 KB Output is correct
76 Correct 238 ms 22160 KB Output is correct
77 Correct 235 ms 22024 KB Output is correct
78 Correct 1 ms 384 KB Output is correct
79 Correct 1 ms 204 KB Output is correct
80 Correct 5 ms 844 KB Output is correct
81 Correct 105 ms 14072 KB Output is correct
82 Correct 1 ms 204 KB Output is correct
83 Correct 1 ms 296 KB Output is correct
84 Correct 1 ms 204 KB Output is correct
85 Correct 64 ms 6300 KB Output is correct
86 Correct 127 ms 14060 KB Output is correct
87 Correct 107 ms 14148 KB Output is correct
88 Correct 96 ms 14020 KB Output is correct
89 Correct 100 ms 14064 KB Output is correct
90 Correct 1 ms 292 KB Output is correct
91 Correct 1 ms 204 KB Output is correct
92 Correct 7 ms 844 KB Output is correct
93 Correct 115 ms 14020 KB Output is correct
94 Correct 1 ms 204 KB Output is correct
95 Correct 1 ms 204 KB Output is correct
96 Correct 1 ms 204 KB Output is correct
97 Correct 25 ms 3696 KB Output is correct
98 Correct 97 ms 14060 KB Output is correct
99 Correct 125 ms 13996 KB Output is correct
100 Correct 94 ms 14072 KB Output is correct
101 Correct 102 ms 14072 KB Output is correct
102 Correct 94 ms 14064 KB Output is correct
103 Correct 96 ms 14068 KB Output is correct
104 Correct 104 ms 14088 KB Output is correct
105 Correct 105 ms 14076 KB Output is correct