답안 #545459

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
545459 2022-04-04T14:43:04 Z Leo121 슈퍼트리 잇기 (IOI20_supertrees) C++14
100 / 100
203 ms 28188 KB
#include "supertrees.h"
#include <bits/stdc++.h>
#define forn(i, a, b) for(int i = int(a); i <= int(b); ++ i)
using namespace std;
const int lim = 1e3;
int graph[lim + 2][lim + 2];
bool visitado[lim + 2];
int componente[lim + 2];
vector<int> lineas[lim + 2];
int n, numcomp;
void dfs(int u){
    forn(v, 0, n - 1){
        if(v != u && graph[u][v] && !componente[v]){
            componente[v] = componente[u];
            dfs(v);
        }
    }
}
int construct(vector<vector<int>> p) {
	n = p.size();
	forn(i, 0, n - 1){
        forn(j, 0, n - 1){
            graph[i][j] = p[i][j];
            if(graph[i][j] == 3){
                return 0;
            }
        }
	}
	forn(i, 0, n - 1){
        if(!componente[i]){
            componente[i] = ++ numcomp;
            dfs(i);
        }
	}
	forn(i, 0, n - 1){
        forn(j, i + 1, n - 1){
            if(!graph[i][j] && componente[i] == componente[j]){
                return 0;
            }
        }
	}
	vector<int> aux[lim + 2];
	forn(i, 0, n - 1){
        if(!visitado[i]){
            lineas[componente[i]].push_back(i);
            visitado[i] = 1;
            forn(j, 0, n - 1){
                if(graph[i][j] == 1){
                    aux[i].push_back(j);
                }
            }
            for(int &u : aux[i]){
                visitado[u] = 1;
                forn(j, 0, n - 1){
                    if(graph[u][j] == 1 && graph[i][j] != 1){
                        return 0;
                    }
                }
            }
        }
	}
	forn(i, 1, numcomp){
        if((int) lineas[i].size() == 2){
            return 0;
        }
	}
	vector<vector<int>> res;
	res.resize(n);
	forn(i, 0, n - 1){
        res[i].resize(n);
        forn(j, 0, n - 1){
            res[i][j] = 0;
        }
	}
	int tamanio;
	forn(i, 1, numcomp){
	    tamanio = lineas[i].size();
        forn(j, 1, tamanio - 1){
            res[lineas[i][j - 1]][lineas[i][j]] = 1;
            res[lineas[i][j]][lineas[i][j - 1]] = 1;
        }
        if(tamanio > 1){
            res[lineas[i][0]][lineas[i][tamanio - 1]] = 1;
            res[lineas[i][tamanio - 1]][lineas[i][0]] = 1;
        }
        for(int &u : lineas[i]){
            tamanio = aux[u].size();
            forn(j, 1, tamanio - 1){
                res[aux[u][j]][aux[u][j - 1]] = 1;
                res[aux[u][j - 1]][aux[u][j]] = 1;
            }
        }
	}
	build(res);
	return 1;
}
# 결과 실행 시간 메모리 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 1 ms 340 KB Output is correct
6 Correct 8 ms 2108 KB Output is correct
7 Correct 171 ms 28032 KB Output is correct
# 결과 실행 시간 메모리 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 1 ms 340 KB Output is correct
6 Correct 8 ms 2108 KB Output is correct
7 Correct 171 ms 28032 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 336 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 8 ms 2004 KB Output is correct
13 Correct 180 ms 27932 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 1496 KB Output is correct
17 Correct 85 ms 14236 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 47 ms 8220 KB Output is correct
21 Correct 179 ms 27980 KB Output is correct
22 Correct 179 ms 28108 KB Output is correct
23 Correct 201 ms 27928 KB Output is correct
24 Correct 181 ms 28188 KB Output is correct
25 Correct 74 ms 14116 KB Output is correct
26 Correct 72 ms 14108 KB Output is correct
27 Correct 192 ms 27960 KB Output is correct
28 Correct 184 ms 27988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 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 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 8 ms 2116 KB Output is correct
9 Correct 175 ms 27928 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 8 ms 2064 KB Output is correct
13 Correct 177 ms 28060 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 1500 KB Output is correct
17 Correct 83 ms 14108 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 61 ms 8248 KB Output is correct
22 Correct 178 ms 27980 KB Output is correct
23 Correct 176 ms 27928 KB Output is correct
24 Correct 191 ms 27988 KB Output is correct
25 Correct 72 ms 14156 KB Output is correct
26 Correct 74 ms 14108 KB Output is correct
27 Correct 178 ms 27928 KB Output is correct
28 Correct 199 ms 27936 KB Output is correct
29 Correct 75 ms 14160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 45 ms 8240 KB Output is correct
5 Correct 183 ms 27932 KB Output is correct
6 Correct 182 ms 27960 KB Output is correct
7 Correct 192 ms 27980 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 47 ms 8260 KB Output is correct
10 Correct 193 ms 27928 KB Output is correct
11 Correct 181 ms 28072 KB Output is correct
12 Correct 203 ms 27980 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 47 ms 8268 KB Output is correct
17 Correct 190 ms 27972 KB Output is correct
18 Correct 186 ms 28088 KB Output is correct
19 Correct 184 ms 27980 KB Output is correct
20 Correct 181 ms 28124 KB Output is correct
# 결과 실행 시간 메모리 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 1 ms 340 KB Output is correct
6 Correct 8 ms 2108 KB Output is correct
7 Correct 171 ms 28032 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 336 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 8 ms 2004 KB Output is correct
13 Correct 180 ms 27932 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 1496 KB Output is correct
17 Correct 85 ms 14236 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 47 ms 8220 KB Output is correct
21 Correct 179 ms 27980 KB Output is correct
22 Correct 179 ms 28108 KB Output is correct
23 Correct 201 ms 27928 KB Output is correct
24 Correct 181 ms 28188 KB Output is correct
25 Correct 74 ms 14116 KB Output is correct
26 Correct 72 ms 14108 KB Output is correct
27 Correct 192 ms 27960 KB Output is correct
28 Correct 184 ms 27988 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 8 ms 2116 KB Output is correct
37 Correct 175 ms 27928 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 8 ms 2064 KB Output is correct
41 Correct 177 ms 28060 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 1500 KB Output is correct
45 Correct 83 ms 14108 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 61 ms 8248 KB Output is correct
50 Correct 178 ms 27980 KB Output is correct
51 Correct 176 ms 27928 KB Output is correct
52 Correct 191 ms 27988 KB Output is correct
53 Correct 72 ms 14156 KB Output is correct
54 Correct 74 ms 14108 KB Output is correct
55 Correct 178 ms 27928 KB Output is correct
56 Correct 199 ms 27936 KB Output is correct
57 Correct 75 ms 14160 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 336 KB Output is correct
60 Correct 4 ms 1500 KB Output is correct
61 Correct 94 ms 14108 KB Output is correct
62 Correct 1 ms 336 KB Output is correct
63 Correct 0 ms 340 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 47 ms 8268 KB Output is correct
66 Correct 76 ms 14108 KB Output is correct
67 Correct 79 ms 14108 KB Output is correct
68 Correct 76 ms 14028 KB Output is correct
69 Correct 72 ms 14184 KB Output is correct
# 결과 실행 시간 메모리 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 1 ms 340 KB Output is correct
6 Correct 8 ms 2108 KB Output is correct
7 Correct 171 ms 28032 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 336 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 8 ms 2004 KB Output is correct
13 Correct 180 ms 27932 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 1496 KB Output is correct
17 Correct 85 ms 14236 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 47 ms 8220 KB Output is correct
21 Correct 179 ms 27980 KB Output is correct
22 Correct 179 ms 28108 KB Output is correct
23 Correct 201 ms 27928 KB Output is correct
24 Correct 181 ms 28188 KB Output is correct
25 Correct 74 ms 14116 KB Output is correct
26 Correct 72 ms 14108 KB Output is correct
27 Correct 192 ms 27960 KB Output is correct
28 Correct 184 ms 27988 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 8 ms 2116 KB Output is correct
37 Correct 175 ms 27928 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 8 ms 2064 KB Output is correct
41 Correct 177 ms 28060 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 1500 KB Output is correct
45 Correct 83 ms 14108 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 61 ms 8248 KB Output is correct
50 Correct 178 ms 27980 KB Output is correct
51 Correct 176 ms 27928 KB Output is correct
52 Correct 191 ms 27988 KB Output is correct
53 Correct 72 ms 14156 KB Output is correct
54 Correct 74 ms 14108 KB Output is correct
55 Correct 178 ms 27928 KB Output is correct
56 Correct 199 ms 27936 KB Output is correct
57 Correct 75 ms 14160 KB Output is correct
58 Correct 0 ms 332 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 0 ms 340 KB Output is correct
61 Correct 45 ms 8240 KB Output is correct
62 Correct 183 ms 27932 KB Output is correct
63 Correct 182 ms 27960 KB Output is correct
64 Correct 192 ms 27980 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 47 ms 8260 KB Output is correct
67 Correct 193 ms 27928 KB Output is correct
68 Correct 181 ms 28072 KB Output is correct
69 Correct 203 ms 27980 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 1 ms 340 KB Output is correct
73 Correct 47 ms 8268 KB Output is correct
74 Correct 190 ms 27972 KB Output is correct
75 Correct 186 ms 28088 KB Output is correct
76 Correct 184 ms 27980 KB Output is correct
77 Correct 181 ms 28124 KB Output is correct
78 Correct 1 ms 340 KB Output is correct
79 Correct 1 ms 336 KB Output is correct
80 Correct 4 ms 1500 KB Output is correct
81 Correct 94 ms 14108 KB Output is correct
82 Correct 1 ms 336 KB Output is correct
83 Correct 0 ms 340 KB Output is correct
84 Correct 1 ms 340 KB Output is correct
85 Correct 47 ms 8268 KB Output is correct
86 Correct 76 ms 14108 KB Output is correct
87 Correct 79 ms 14108 KB Output is correct
88 Correct 76 ms 14028 KB Output is correct
89 Correct 72 ms 14184 KB Output is correct
90 Correct 1 ms 340 KB Output is correct
91 Correct 1 ms 336 KB Output is correct
92 Correct 4 ms 728 KB Output is correct
93 Correct 75 ms 10136 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 340 KB Output is correct
97 Correct 19 ms 2932 KB Output is correct
98 Correct 70 ms 10404 KB Output is correct
99 Correct 68 ms 10712 KB Output is correct
100 Correct 69 ms 10444 KB Output is correct
101 Correct 73 ms 11424 KB Output is correct
102 Correct 69 ms 10140 KB Output is correct
103 Correct 67 ms 10136 KB Output is correct
104 Correct 67 ms 10188 KB Output is correct
105 Correct 76 ms 10196 KB Output is correct