답안 #956553

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
956553 2024-04-02T07:02:09 Z KK_1729 슈퍼트리 잇기 (IOI20_supertrees) C++17
19 / 100
167 ms 24388 KB
#include "supertrees.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;

struct UFDS {
    vector<int> link, siz;
    UFDS(int n) : link(n), siz(n, 1) { iota(link.begin(), link.end(), 0); } //each element as its own subset, with size 1
    int findRoot(int x) {
        if(x == link[x]) return x;
        return link[x] = findRoot(link[x]);
        /*
        A shorter way of writing the following is:
        return x == link[x]  ? x : link[x]  =  findRoot(link[x]);  
        */
    }
    bool same(int x, int y) { return findRoot(x) == findRoot(y); }
    bool unite(int x, int y) {
        x = findRoot(x);
        y = findRoot(y);
        if (x == y)
            return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        link[y] = x;
        return true;
    }
    int size(int x) { return siz[findRoot(x)]; }
};


int construct(std::vector<std::vector<int>> p) {
	int n = p.size();
	std::vector<std::vector<int>> answer;
	for (int i = 0; i < n; i++) {
		std::vector<int> row;
		row.resize(n);
		answer.push_back(row);
	}


	UFDS ds(n);
	for (int i = 0; i < n; ++i){
		for (int j = 0; j < n; ++j){
			if (i == j) continue;
			if (p[i][j] == 2) ds.unite(i, j);
			else{
				if (ds.same(i, j)) return 0;
			}
		}
	}


	vector<vector<int>> parents(n);

	for (int i = 0; i < n; ++i) parents[ds.findRoot(i)].push_back(i);
	
	for (auto item: parents){
		int u = item.size();
		if (u == 2) return 0;
		for (int i = 0; i < u-1; i++){
			answer[item[i]][item[i+1]] = 1;
			answer[item[i+1]][item[i]] = 1;
		}
		if (u > 1){
			answer[item[0]][item[u-1]] = 1;
			answer[item[u-1]][item[0]] = 1;
		}
	}
	build(answer);
	return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Too few ways to get from 0 to 1, should be 1 found 0
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Too few ways to get from 0 to 1, should be 1 found 0
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 436 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 348 KB Output is correct
8 Correct 7 ms 1372 KB Output is correct
9 Correct 151 ms 24200 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 8 ms 1212 KB Output is correct
13 Correct 158 ms 24288 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 928 KB Output is correct
17 Correct 69 ms 14160 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 436 KB Output is correct
21 Correct 43 ms 6224 KB Output is correct
22 Correct 157 ms 24388 KB Output is correct
23 Correct 152 ms 24016 KB Output is correct
24 Correct 166 ms 24140 KB Output is correct
25 Correct 64 ms 14416 KB Output is correct
26 Correct 69 ms 14200 KB Output is correct
27 Correct 165 ms 24088 KB Output is correct
28 Correct 167 ms 24072 KB Output is correct
29 Correct 64 ms 14160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Too few ways to get from 1 to 2, should be 1 found 0
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Too few ways to get from 0 to 1, should be 1 found 0
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Too few ways to get from 0 to 1, should be 1 found 0
3 Halted 0 ms 0 KB -