답안 #760584

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
760584 2023-06-17T21:44:00 Z raysh07 슈퍼트리 잇기 (IOI20_supertrees) C++17
46 / 100
179 ms 28164 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++){
	    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:69:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |      for (int j = 0; j < comp.size() - 1; j++){
      |                      ~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 7 ms 1108 KB Output is correct
7 Correct 154 ms 22000 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 7 ms 1108 KB Output is correct
7 Correct 154 ms 22000 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 8 ms 1160 KB Output is correct
13 Correct 153 ms 21976 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 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 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 7 ms 1236 KB Output is correct
9 Correct 169 ms 23996 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1492 KB Output is correct
13 Correct 167 ms 28164 KB Output is correct
14 Incorrect 1 ms 212 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 276 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 48 ms 6256 KB Output is correct
5 Correct 179 ms 24000 KB Output is correct
6 Correct 154 ms 23928 KB Output is correct
7 Correct 160 ms 24012 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 39 ms 6300 KB Output is correct
10 Correct 158 ms 24580 KB Output is correct
11 Correct 154 ms 23952 KB Output is correct
12 Correct 168 ms 27080 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 43 ms 6300 KB Output is correct
17 Correct 156 ms 24536 KB Output is correct
18 Correct 161 ms 24204 KB Output is correct
19 Correct 158 ms 24204 KB Output is correct
20 Correct 151 ms 23948 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 7 ms 1108 KB Output is correct
7 Correct 154 ms 22000 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 8 ms 1160 KB Output is correct
13 Correct 153 ms 21976 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 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 7 ms 1108 KB Output is correct
7 Correct 154 ms 22000 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 8 ms 1160 KB Output is correct
13 Correct 153 ms 21976 KB Output is correct
14 Incorrect 0 ms 212 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -