답안 #1087039

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1087039 2024-09-12T06:07:23 Z SulA 슈퍼트리 잇기 (IOI20_supertrees) C++17
21 / 100
136 ms 32300 KB
#include "supertrees.h"
#include <iostream>
#include <vector>

using namespace std;

vector<int> adj[1000], comp;
bool visited[1000];

void dfs(int u) {
    comp.push_back(u);
    visited[u] = -true;
    for (int v: adj[u]) if (!visited[v]) {
        dfs(v);
    }
}

int construct(vector<vector<int>> p) {
	int n = p.size(), mx = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            mx = max(mx, p[i][j]);
            if (p[i][j] != 0) {
                adj[i].push_back(j);
                adj[j].push_back(i);
            }
        }
    }
    vector<vector<int>> adj(n, vector<int>(n, 0));
    for (int i = 0; i < n; i++) if (!visited[i]) {
        comp.clear();
        dfs(i);
        for (auto x : comp) for (auto y : comp) if (p[x][y] == 0) return 0;
        for (int j = 0; j < comp.size() - 1; j++) {
            adj[ comp[j] ][ comp[j+1] ] = adj[ comp[j+1] ][ comp[j] ] = 1;
        }
        if (mx == 2) {
            if (comp.size() < 3) return 0;
            adj[comp.front()][comp.back()] = adj[comp.back()][comp.front()] = 1;
        }
    }
    build(adj);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:34:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |         for (int j = 0; j < comp.size() - 1; j++) {
      |                         ~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 6 ms 1628 KB Output is correct
7 Correct 119 ms 32092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 6 ms 1628 KB Output is correct
7 Correct 119 ms 32092 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 5 ms 1216 KB Output is correct
13 Correct 122 ms 24144 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 460 KB Output is correct
16 Correct 3 ms 1116 KB Output is correct
17 Correct 64 ms 19400 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 30 ms 6424 KB Output is correct
21 Correct 136 ms 25172 KB Output is correct
22 Correct 115 ms 23960 KB Output is correct
23 Correct 136 ms 28240 KB Output is correct
24 Correct 113 ms 24144 KB Output is correct
25 Correct 60 ms 15184 KB Output is correct
26 Correct 54 ms 14168 KB Output is correct
27 Correct 130 ms 30288 KB Output is correct
28 Correct 117 ms 24148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 456 KB Output is correct
3 Correct 0 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 344 KB Output is correct
8 Correct 5 ms 1388 KB Output is correct
9 Correct 116 ms 23952 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 6 ms 1840 KB Output is correct
13 Correct 131 ms 32300 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 3 ms 1116 KB Output is correct
17 Correct 74 ms 19360 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Incorrect 0 ms 348 KB Answer gives possible 0 while actual possible 1
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 36 ms 6428 KB Output is correct
5 Correct 123 ms 25112 KB Output is correct
6 Correct 110 ms 24080 KB Output is correct
7 Correct 124 ms 28240 KB Output is correct
8 Incorrect 0 ms 344 KB Answer gives possible 0 while actual possible 1
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 6 ms 1628 KB Output is correct
7 Correct 119 ms 32092 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 5 ms 1216 KB Output is correct
13 Correct 122 ms 24144 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 460 KB Output is correct
16 Correct 3 ms 1116 KB Output is correct
17 Correct 64 ms 19400 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 30 ms 6424 KB Output is correct
21 Correct 136 ms 25172 KB Output is correct
22 Correct 115 ms 23960 KB Output is correct
23 Correct 136 ms 28240 KB Output is correct
24 Correct 113 ms 24144 KB Output is correct
25 Correct 60 ms 15184 KB Output is correct
26 Correct 54 ms 14168 KB Output is correct
27 Correct 130 ms 30288 KB Output is correct
28 Correct 117 ms 24148 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 456 KB Output is correct
31 Correct 0 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 344 KB Output is correct
36 Correct 5 ms 1388 KB Output is correct
37 Correct 116 ms 23952 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 6 ms 1840 KB Output is correct
41 Correct 131 ms 32300 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 0 ms 344 KB Output is correct
44 Correct 3 ms 1116 KB Output is correct
45 Correct 74 ms 19360 KB Output is correct
46 Correct 0 ms 344 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Incorrect 0 ms 348 KB Answer gives possible 0 while actual possible 1
49 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 6 ms 1628 KB Output is correct
7 Correct 119 ms 32092 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 5 ms 1216 KB Output is correct
13 Correct 122 ms 24144 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 460 KB Output is correct
16 Correct 3 ms 1116 KB Output is correct
17 Correct 64 ms 19400 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 30 ms 6424 KB Output is correct
21 Correct 136 ms 25172 KB Output is correct
22 Correct 115 ms 23960 KB Output is correct
23 Correct 136 ms 28240 KB Output is correct
24 Correct 113 ms 24144 KB Output is correct
25 Correct 60 ms 15184 KB Output is correct
26 Correct 54 ms 14168 KB Output is correct
27 Correct 130 ms 30288 KB Output is correct
28 Correct 117 ms 24148 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 456 KB Output is correct
31 Correct 0 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 344 KB Output is correct
36 Correct 5 ms 1388 KB Output is correct
37 Correct 116 ms 23952 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 6 ms 1840 KB Output is correct
41 Correct 131 ms 32300 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 0 ms 344 KB Output is correct
44 Correct 3 ms 1116 KB Output is correct
45 Correct 74 ms 19360 KB Output is correct
46 Correct 0 ms 344 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Incorrect 0 ms 348 KB Answer gives possible 0 while actual possible 1
49 Halted 0 ms 0 KB -