제출 #309395

#제출 시각아이디문제언어결과실행 시간메모리
309395pere_gil슈퍼트리 잇기 (IOI20_supertrees)C++14
컴파일 에러
0 ms0 KiB
#include "bits/stdc++.h"
#include "supertrees.h"

using namespace std;

int pos[1000];

void init(int n){
    for(int i=0;i<n;i++) pos[i]=i;
}

int findset(int a){
    if(pos[a]==a) return a;
    else findset(pos[a]);
}

void unionset(int A, int B){
    int a=findset(A);
    int b=findset(B);
    if(a!=b) p[b]=a;
}

int construct(int [][] p)
{
    int n=(int)sqrt(sizeof(p)/4);
    init(n);

    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(p[i][j]==1) unionset(i,j);
        }
    }

    vector<int> v[n];
    for(int i=0;i<n;i++) v[findset(i)].push_back(i);

    int res[n][n];
    memset(res,0,sizeof(res));
    for(int i=0;i<n;i++){
        for(int j=0;j<v[i].size()-1;j++){
            res[j][j+1]=1;
        }
    }

    build(res[][]);
    return 1;

    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

supertrees.cpp: In function 'void unionset(int, int)':
supertrees.cpp:20:14: error: 'p' was not declared in this scope
   20 |     if(a!=b) p[b]=a;
      |              ^
supertrees.cpp: At global scope:
supertrees.cpp:23:22: error: multidimensional array must have bounds for all dimensions except the first
   23 | int construct(int [][] p)
      |                      ^
supertrees.cpp:23:24: error: expected ',' or '...' before 'p'
   23 | int construct(int [][] p)
      |                        ^
supertrees.cpp: In function 'int construct()':
supertrees.cpp:25:28: error: 'p' was not declared in this scope
   25 |     int n=(int)sqrt(sizeof(p)/4);
      |                            ^
supertrees.cpp:40:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         for(int j=0;j<v[i].size()-1;j++){
      |                     ~^~~~~~~~~~~~~~
supertrees.cpp:45:15: error: expected primary-expression before ']' token
   45 |     build(res[][]);
      |               ^
supertrees.cpp:45:17: error: expected primary-expression before ']' token
   45 |     build(res[][]);
      |                 ^
supertrees.cpp: In function 'int findset(int)':
supertrees.cpp:14:17: warning: control reaches end of non-void function [-Wreturn-type]
   14 |     else findset(pos[a]);
      |          ~~~~~~~^~~~~~~~