Submission #309394

#TimeUsernameProblemLanguageResultExecution timeMemory
309394pere_gilConnecting Supertrees (IOI20_supertrees)C++14
Compilation error
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;
}

Compilation message (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:11: error: could not convert '(int (*)[n])(& res)' from 'int (*)[n]' to 'std::vector<std::vector<int> >'
   45 |     build(res);
      |           ^~~
      |           |
      |           int (*)[n]
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]);
      |          ~~~~~~~^~~~~~~~