답안 #301292

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
301292 2020-09-17T20:18:06 Z Gilgamesh 슈퍼트리 잇기 (IOI20_supertrees) Java 11
컴파일 오류
0 ms 0 KB
#include "supertrees.h"
#include <vector>

const int mxN = 1000;

int parent[mxN];
int rnk[mxN];

int find(int x) 
{ 
    if(parent[x] == -1)
        parent[x] = x;
    if (parent[x] != x) { 
        parent[x] = find(parent[x]); 
    }
    return parent[x]; 
}
bool merge(int x, int y) 
{ 
    int xRoot = find(x), yRoot = find(y); 
    if (xRoot == yRoot) 
        return false; 
    if (rnk[xRoot] < rnk[yRoot]) 
        parent[xRoot] = yRoot; 
    else if (rnk[yRoot] < rnk[xRoot]) 
        parent[yRoot] = xRoot; 
    else 
    { 
        parent[yRoot] = xRoot; 
        rnk[xRoot] = rnk[xRoot] + 1; 
    } 
    return true;
} 

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);
    }
    for(int i = 0; i < n; ++i){
        parent[i] = i;
    }
    for(int i = 0; i < n; ++i){
        for(int j = i + 1; j < n; ++j){
            if(!p[i][j] && find(i) == find(j)){
                return 0;
            }
            if(p[i][j]) merge(i, j);
        }
    }
    for(int i = 0; i < n; ++i){
        for(int j = i + 1; j < n; ++j){
            if(!p[i][j] && find(i) == find(j)) return 0;
        }
    }
    std::vector<int> sets[n];
    for(int i = 0; i < n; ++i){
        int rep = find(i);
        sets[rep].emplace_back(i);
    }
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < sets[i].size() - 1; ++j){
            answer[sets[i][j]][sets[i][j + 1]] = 1;
            answer[sets[i][j + 1]][sets[i][j]] = 1;
        }
        if(sets[i].size() > 1){
            answer[sets[i][0]][sets[i][sets[i].size()-1]] = 1;
            answer[sets[i][sets[i].size()-1]][sets[i][0]] = 1;
        }
    }
    build(answer);
    return 1;
}

Compilation message

supertrees.java:1: error: illegal character: '#'
#include "supertrees.h"
^
supertrees.java:1: error: class, interface, or enum expected
#include "supertrees.h"
         ^
supertrees.java:2: error: illegal character: '#'
#include <vector>
^
supertrees.java:6: error: class, interface, or enum expected
int parent[mxN];
^
supertrees.java:7: error: class, interface, or enum expected
int rnk[mxN];
^
supertrees.java:9: error: class, interface, or enum expected
int find(int x) 
^
supertrees.java:13: error: class, interface, or enum expected
    if (parent[x] != x) { 
    ^
supertrees.java:15: error: class, interface, or enum expected
    }
    ^
supertrees.java:17: error: class, interface, or enum expected
}
^
supertrees.java:21: error: class, interface, or enum expected
    if (xRoot == yRoot) 
    ^
supertrees.java:23: error: class, interface, or enum expected
    if (rnk[xRoot] < rnk[yRoot]) 
    ^
supertrees.java:25: error: class, interface, or enum expected
    else if (rnk[yRoot] < rnk[xRoot]) 
    ^
supertrees.java:27: error: class, interface, or enum expected
    else 
    ^
supertrees.java:30: error: class, interface, or enum expected
        rnk[xRoot] = rnk[xRoot] + 1; 
        ^
supertrees.java:31: error: class, interface, or enum expected
    } 
    ^
supertrees.java:33: error: class, interface, or enum expected
} 
^
supertrees.java:37: error: class, interface, or enum expected
    std::vector<std::vector<int>> answer;
    ^
supertrees.java:38: error: class, interface, or enum expected
    for (int i = 0; i < n; i++) {
    ^
supertrees.java:38: error: class, interface, or enum expected
    for (int i = 0; i < n; i++) {
                    ^
supertrees.java:38: error: class, interface, or enum expected
    for (int i = 0; i < n; i++) {
                           ^
supertrees.java:40: error: class, interface, or enum expected
        row.resize(n);
        ^
supertrees.java:41: error: class, interface, or enum expected
        answer.push_back(row);
        ^
supertrees.java:42: error: class, interface, or enum expected
    }
    ^
supertrees.java:43: error: class, interface, or enum expected
    for(int i = 0; i < n; ++i){
                   ^
supertrees.java:43: error: class, interface, or enum expected
    for(int i = 0; i < n; ++i){
                          ^
supertrees.java:45: error: class, interface, or enum expected
    }
    ^
supertrees.java:46: error: class, interface, or enum expected
    for(int i = 0; i < n; ++i){
                   ^
supertrees.java:46: error: class, interface, or enum expected
    for(int i = 0; i < n; ++i){
                          ^
supertrees.java:47: error: class, interface, or enum expected
        for(int j = i + 1; j < n; ++j){
                           ^
supertrees.java:47: error: class, interface, or enum expected
        for(int j = i + 1; j < n; ++j){
                                  ^
supertrees.java:50: error: class, interface, or enum expected
            }
            ^
supertrees.java:52: error: class, interface, or enum expected
        }
        ^
supertrees.java:54: error: class, interface, or enum expected
    for(int i = 0; i < n; ++i){
                   ^
supertrees.java:54: error: class, interface, or enum expected
    for(int i = 0; i < n; ++i){
                          ^
supertrees.java:55: error: class, interface, or enum expected
        for(int j = i + 1; j < n; ++j){
                           ^
supertrees.java:55: error: class, interface, or enum expected
        for(int j = i + 1; j < n; ++j){
                                  ^
supertrees.java:57: error: class, interface, or enum expected
        }
        ^
supertrees.java:60: error: class, interface, or enum expected
    for(int i = 0; i < n; ++i){
    ^
supertrees.java:60: error: class, interface, or enum expected
    for(int i = 0; i < n; ++i){
                   ^
supertrees.java:60: error: class, interface, or enum expected
    for(int i = 0; i < n; ++i){
                          ^
supertrees.java:62: error: class, interface, or enum expected
        sets[rep].emplace_back(i);
        ^
supertrees.java:63: error: class, interface, or enum expected
    }
    ^
supertrees.java:64: error: class, interface, or enum expected
    for(int i = 0; i < n; ++i){
                   ^
supertrees.java:64: error: class, interface, or enum expected
    for(int i = 0; i < n; ++i){
                          ^
supertrees.java:65: error: class, interface, or enum expected
        for(int j = 0; j < sets[i].size() - 1; ++j){
                       ^
supertrees.java:65: error: class, interface, or enum expected
        for(int j = 0; j < sets[i].size() - 1; ++j){
                                               ^
supertrees.java:67: error: class, interface, or enum expected
            answer[sets[i][j + 1]][sets[i][j]] = 1;
            ^
supertrees.java:68: error: class, interface, or enum expected
        }
        ^
supertrees.java:71: error: class, interface, or enum expected
            answer[sets[i][sets[i].size()-1]][sets[i][0]] = 1;
            ^
supertrees.java:72: error: class, interface, or enum expected
        }
        ^
supertrees.java:75: error: class, interface, or enum expected
    return 1;
    ^
supertrees.java:76: error: class, interface, or enum expected
}
^
52 errors