답안 #760585

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
760585 2023-06-17T21:45:07 Z raysh07 슈퍼트리 잇기 (IOI20_supertrees) C++17
56 / 100
166 ms 26196 KB
#include "supertrees.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;

const int N = 1001;
int root[N];
vector <int> adj[N];
bool vis[N];
vector <int> comp;

int find(int x){
    if (root[x] == x) return x;
    return root[x] = find(root[x]);
}

void unite(int x, int y){
    x = find(x); y = find(y);
    
    if (x == y) return;
    root[x] = y;
}

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

int construct(vector<vector<int>> p) {
	int n = p.size();
	vector<vector<int>> ans(n, vector<int>(n, 0));
	
	for (int i = 0; i < n; i++) root[i] = i;
	
	for (int i = 0; i < n; i++){
	    for (int j = i + 1; j < n; j++){
	        if (p[i][j] == 1) unite(i, j);
	        if (p[i][j] == 3) return 0;
	    }
	}
	
	for (int i = 0; i < n; i++){
	    for (int j = i + 1; j < n; j++){
	        if (find(i) == find(j) && p[i][j] == 0) return 0;
	    }
	}
	
	for (int i = 0; i < n; i++){
	    if (find(i) != i){
	        ans[i][find(i)] = ans[find(i)][i] = 1;
	    }
	}
	
	for (int i = 0; i < n; i++){
	    for (int j = i + 1; j < n; j++){
	        if (p[i][j] == 2 && find(i) == i && find(j) == j) {
	            adj[i].push_back(j);
	            adj[j].push_back(i);
	        }
	    }
	}
	
	for (int i = 0; i < n; i++){
	    if (vis[i] || find(i) != i) continue;
	    
	    comp.clear();
	    dfs(i);
	    
	    if (comp.size() == 2) return 0;
	    
	    for (int j = 0; j < comp.size() - 1; j++){
	        ans[comp[j]][comp[j + 1]] = ans[comp[j + 1]][comp[j]] = 1;
	    }
	    if (comp.size() != 1)
	    ans[comp[0]][comp.back()] = ans[comp.back()][comp[0]] = 1;
	}
	build(ans);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:75:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |      for (int j = 0; j < comp.size() - 1; j++){
      |                      ~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1108 KB Output is correct
7 Correct 166 ms 22052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1108 KB Output is correct
7 Correct 166 ms 22052 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 6 ms 1108 KB Output is correct
13 Correct 155 ms 22084 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 70 ms 14100 KB Output is correct
18 Correct 1 ms 260 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 39 ms 6220 KB Output is correct
21 Correct 163 ms 23948 KB Output is correct
22 Correct 155 ms 23952 KB Output is correct
23 Correct 159 ms 24012 KB Output is correct
24 Correct 154 ms 23952 KB Output is correct
25 Correct 60 ms 14100 KB Output is correct
26 Correct 66 ms 14104 KB Output is correct
27 Correct 165 ms 23996 KB Output is correct
28 Correct 154 ms 23964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 7 ms 1148 KB Output is correct
9 Correct 152 ms 22032 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1416 KB Output is correct
13 Correct 163 ms 26196 KB Output is correct
14 Incorrect 0 ms 212 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 39 ms 5688 KB Output is correct
5 Correct 154 ms 22048 KB Output is correct
6 Correct 161 ms 21988 KB Output is correct
7 Correct 158 ms 22044 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 39 ms 5840 KB Output is correct
10 Correct 160 ms 22560 KB Output is correct
11 Correct 153 ms 22056 KB Output is correct
12 Correct 161 ms 25136 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 40 ms 5776 KB Output is correct
17 Correct 155 ms 22560 KB Output is correct
18 Correct 160 ms 22272 KB Output is correct
19 Correct 156 ms 22136 KB Output is correct
20 Correct 154 ms 21968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1108 KB Output is correct
7 Correct 166 ms 22052 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 6 ms 1108 KB Output is correct
13 Correct 155 ms 22084 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 70 ms 14100 KB Output is correct
18 Correct 1 ms 260 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 39 ms 6220 KB Output is correct
21 Correct 163 ms 23948 KB Output is correct
22 Correct 155 ms 23952 KB Output is correct
23 Correct 159 ms 24012 KB Output is correct
24 Correct 154 ms 23952 KB Output is correct
25 Correct 60 ms 14100 KB Output is correct
26 Correct 66 ms 14104 KB Output is correct
27 Correct 165 ms 23996 KB Output is correct
28 Correct 154 ms 23964 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 7 ms 1148 KB Output is correct
37 Correct 152 ms 22032 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 7 ms 1416 KB Output is correct
41 Correct 163 ms 26196 KB Output is correct
42 Incorrect 0 ms 212 KB Answer gives possible 1 while actual possible 0
43 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1108 KB Output is correct
7 Correct 166 ms 22052 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 6 ms 1108 KB Output is correct
13 Correct 155 ms 22084 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 70 ms 14100 KB Output is correct
18 Correct 1 ms 260 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 39 ms 6220 KB Output is correct
21 Correct 163 ms 23948 KB Output is correct
22 Correct 155 ms 23952 KB Output is correct
23 Correct 159 ms 24012 KB Output is correct
24 Correct 154 ms 23952 KB Output is correct
25 Correct 60 ms 14100 KB Output is correct
26 Correct 66 ms 14104 KB Output is correct
27 Correct 165 ms 23996 KB Output is correct
28 Correct 154 ms 23964 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 7 ms 1148 KB Output is correct
37 Correct 152 ms 22032 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 7 ms 1416 KB Output is correct
41 Correct 163 ms 26196 KB Output is correct
42 Incorrect 0 ms 212 KB Answer gives possible 1 while actual possible 0
43 Halted 0 ms 0 KB -