Submission #428736

# Submission time Handle Problem Language Result Execution time Memory
428736 2021-06-15T14:08:48 Z Emin2004 Connecting Supertrees (IOI20_supertrees) C++14
100 / 100
373 ms 28184 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define pii pair <int, int>
#define pb push_back
#define F first
#define S second
#define ll long long
#define io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define M_PI 3.14159265358979323846

const int N = 1005;
const int mod = 1e9 + 7;

int parent[N], rnk[N], ans[N][N], incyc[N], mnmn;
vector<int> component[N];
set<int> s;

int getpar(int a){
    if(parent[a] == a) return a;
    return parent[a] = getpar(parent[a]);
}

void uni(int a, int b){
    if(rnk[a] > rnk[b]) swap(a, b);
    parent[a] = b;
    s.insert(b);
    if(s.find(a) != s.end()) s.erase(s.find(a));
    if(rnk[a] == rnk[b]) rnk[b]++;
}

void DFS(int node, int par, int root){
    component[root].pb(node);
    for(int i = 0; i < mnmn; i++){
        if(i == par || ans[node][i] == 0) continue;
        DFS(i, node, root);
    }
}

int construct(vector<vector<int>> p) {
	int n = p.size();
	mnmn = n;
	for(int i = 0; i < n; i++) {
        rnk[i] = 0;
        parent[i] = i;
        s.insert(i);
	}
	for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(i == j) continue;
            if(p[i][j] == 3) return 0;
            int x = getpar(i);
            int y = getpar(j);
            if(x == y && p[i][j] == 0) return 0;
            if(x != y && p[i][j] == 1){
                uni(x, y);
                ans[x][y] = 1;
                ans[y][x] = 1;
            }
        }
	}
	for(set<int>::iterator itr = s.begin(); itr != s.end(); itr++){
        DFS(*itr, *itr, *itr);
	}
	for(set<int>::iterator itr = s.begin(); itr != s.end(); itr++){
        vector<int> v;
        int x = *itr;
        for(set<int>::iterator itr2 = s.begin(); itr2 != s.end(); itr2++){
            int y = *itr2;
            if(x == y) continue;
            if(p[x][y] == 2){
                v.pb(y);
                if((incyc[x] == 1) && getpar(x) != getpar(y)) return 0;
            }
        }
        if(v.size() != 0) v.pb(x);
        if(v.size() == 2) return 0;
        if(incyc[x]) continue;
        for(int i : v){
            for(int j : v){
                if(i == j) continue;
                for(int c1 : component[i]){
                    for(int c2 : component[j]) if(p[c1][c2] != 2) return 0;
                }
            }
            incyc[i] = 1;
        }
        int last = x;
        for(int i : v){
            ans[last][i] = 1;
            ans[i][last] = 1;
            last = i;
            parent[i] = x;
        }
	}
	vector<vector<int>> answer(n);
	for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            answer[i].pb(ans[i][j]);
        }
	}
	build(answer);
	return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 11 ms 2096 KB Output is correct
7 Correct 258 ms 28184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 11 ms 2096 KB Output is correct
7 Correct 258 ms 28184 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 11 ms 1332 KB Output is correct
13 Correct 253 ms 24196 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 6 ms 1100 KB Output is correct
17 Correct 109 ms 12228 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 67 ms 8072 KB Output is correct
21 Correct 254 ms 28044 KB Output is correct
22 Correct 259 ms 27640 KB Output is correct
23 Correct 260 ms 28044 KB Output is correct
24 Correct 330 ms 24348 KB Output is correct
25 Correct 114 ms 14088 KB Output is correct
26 Correct 105 ms 12440 KB Output is correct
27 Correct 278 ms 27968 KB Output is correct
28 Correct 260 ms 24328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 11 ms 1356 KB Output is correct
9 Correct 270 ms 24220 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 15 ms 2124 KB Output is correct
13 Correct 269 ms 28140 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 5 ms 716 KB Output is correct
17 Correct 125 ms 10244 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 71 ms 8168 KB Output is correct
22 Correct 278 ms 28048 KB Output is correct
23 Correct 316 ms 28036 KB Output is correct
24 Correct 297 ms 28064 KB Output is correct
25 Correct 115 ms 10376 KB Output is correct
26 Correct 168 ms 14168 KB Output is correct
27 Correct 264 ms 28052 KB Output is correct
28 Correct 373 ms 28048 KB Output is correct
29 Correct 131 ms 10376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 71 ms 8076 KB Output is correct
5 Correct 289 ms 28052 KB Output is correct
6 Correct 282 ms 27604 KB Output is correct
7 Correct 310 ms 27972 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 73 ms 8140 KB Output is correct
10 Correct 288 ms 28136 KB Output is correct
11 Correct 287 ms 28168 KB Output is correct
12 Correct 290 ms 28056 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 368 KB Output is correct
16 Correct 84 ms 8160 KB Output is correct
17 Correct 315 ms 28096 KB Output is correct
18 Correct 295 ms 27684 KB Output is correct
19 Correct 293 ms 27520 KB Output is correct
20 Correct 263 ms 24432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 11 ms 2096 KB Output is correct
7 Correct 258 ms 28184 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 11 ms 1332 KB Output is correct
13 Correct 253 ms 24196 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 6 ms 1100 KB Output is correct
17 Correct 109 ms 12228 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 67 ms 8072 KB Output is correct
21 Correct 254 ms 28044 KB Output is correct
22 Correct 259 ms 27640 KB Output is correct
23 Correct 260 ms 28044 KB Output is correct
24 Correct 330 ms 24348 KB Output is correct
25 Correct 114 ms 14088 KB Output is correct
26 Correct 105 ms 12440 KB Output is correct
27 Correct 278 ms 27968 KB Output is correct
28 Correct 260 ms 24328 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 328 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 11 ms 1356 KB Output is correct
37 Correct 270 ms 24220 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 15 ms 2124 KB Output is correct
41 Correct 269 ms 28140 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 5 ms 716 KB Output is correct
45 Correct 125 ms 10244 KB Output is correct
46 Correct 1 ms 332 KB Output is correct
47 Correct 1 ms 332 KB Output is correct
48 Correct 1 ms 332 KB Output is correct
49 Correct 71 ms 8168 KB Output is correct
50 Correct 278 ms 28048 KB Output is correct
51 Correct 316 ms 28036 KB Output is correct
52 Correct 297 ms 28064 KB Output is correct
53 Correct 115 ms 10376 KB Output is correct
54 Correct 168 ms 14168 KB Output is correct
55 Correct 264 ms 28052 KB Output is correct
56 Correct 373 ms 28048 KB Output is correct
57 Correct 131 ms 10376 KB Output is correct
58 Correct 1 ms 332 KB Output is correct
59 Correct 1 ms 332 KB Output is correct
60 Correct 8 ms 996 KB Output is correct
61 Correct 116 ms 11552 KB Output is correct
62 Correct 1 ms 324 KB Output is correct
63 Correct 1 ms 332 KB Output is correct
64 Correct 1 ms 332 KB Output is correct
65 Correct 83 ms 8164 KB Output is correct
66 Correct 162 ms 11964 KB Output is correct
67 Correct 125 ms 12168 KB Output is correct
68 Correct 129 ms 12432 KB Output is correct
69 Correct 111 ms 10364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 11 ms 2096 KB Output is correct
7 Correct 258 ms 28184 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 11 ms 1332 KB Output is correct
13 Correct 253 ms 24196 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 6 ms 1100 KB Output is correct
17 Correct 109 ms 12228 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 67 ms 8072 KB Output is correct
21 Correct 254 ms 28044 KB Output is correct
22 Correct 259 ms 27640 KB Output is correct
23 Correct 260 ms 28044 KB Output is correct
24 Correct 330 ms 24348 KB Output is correct
25 Correct 114 ms 14088 KB Output is correct
26 Correct 105 ms 12440 KB Output is correct
27 Correct 278 ms 27968 KB Output is correct
28 Correct 260 ms 24328 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 328 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 11 ms 1356 KB Output is correct
37 Correct 270 ms 24220 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 15 ms 2124 KB Output is correct
41 Correct 269 ms 28140 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 5 ms 716 KB Output is correct
45 Correct 125 ms 10244 KB Output is correct
46 Correct 1 ms 332 KB Output is correct
47 Correct 1 ms 332 KB Output is correct
48 Correct 1 ms 332 KB Output is correct
49 Correct 71 ms 8168 KB Output is correct
50 Correct 278 ms 28048 KB Output is correct
51 Correct 316 ms 28036 KB Output is correct
52 Correct 297 ms 28064 KB Output is correct
53 Correct 115 ms 10376 KB Output is correct
54 Correct 168 ms 14168 KB Output is correct
55 Correct 264 ms 28052 KB Output is correct
56 Correct 373 ms 28048 KB Output is correct
57 Correct 131 ms 10376 KB Output is correct
58 Correct 1 ms 332 KB Output is correct
59 Correct 1 ms 324 KB Output is correct
60 Correct 1 ms 332 KB Output is correct
61 Correct 71 ms 8076 KB Output is correct
62 Correct 289 ms 28052 KB Output is correct
63 Correct 282 ms 27604 KB Output is correct
64 Correct 310 ms 27972 KB Output is correct
65 Correct 1 ms 332 KB Output is correct
66 Correct 73 ms 8140 KB Output is correct
67 Correct 288 ms 28136 KB Output is correct
68 Correct 287 ms 28168 KB Output is correct
69 Correct 290 ms 28056 KB Output is correct
70 Correct 1 ms 332 KB Output is correct
71 Correct 1 ms 332 KB Output is correct
72 Correct 1 ms 368 KB Output is correct
73 Correct 84 ms 8160 KB Output is correct
74 Correct 315 ms 28096 KB Output is correct
75 Correct 295 ms 27684 KB Output is correct
76 Correct 293 ms 27520 KB Output is correct
77 Correct 263 ms 24432 KB Output is correct
78 Correct 1 ms 332 KB Output is correct
79 Correct 1 ms 332 KB Output is correct
80 Correct 8 ms 996 KB Output is correct
81 Correct 116 ms 11552 KB Output is correct
82 Correct 1 ms 324 KB Output is correct
83 Correct 1 ms 332 KB Output is correct
84 Correct 1 ms 332 KB Output is correct
85 Correct 83 ms 8164 KB Output is correct
86 Correct 162 ms 11964 KB Output is correct
87 Correct 125 ms 12168 KB Output is correct
88 Correct 129 ms 12432 KB Output is correct
89 Correct 111 ms 10364 KB Output is correct
90 Correct 1 ms 332 KB Output is correct
91 Correct 1 ms 324 KB Output is correct
92 Correct 6 ms 692 KB Output is correct
93 Correct 106 ms 10124 KB Output is correct
94 Correct 1 ms 332 KB Output is correct
95 Correct 1 ms 332 KB Output is correct
96 Correct 1 ms 332 KB Output is correct
97 Correct 26 ms 2892 KB Output is correct
98 Correct 111 ms 10128 KB Output is correct
99 Correct 103 ms 11416 KB Output is correct
100 Correct 102 ms 11532 KB Output is correct
101 Correct 114 ms 10252 KB Output is correct
102 Correct 102 ms 10132 KB Output is correct
103 Correct 106 ms 10120 KB Output is correct
104 Correct 136 ms 10136 KB Output is correct
105 Correct 114 ms 10184 KB Output is correct