Submission #301774

# Submission time Handle Problem Language Result Execution time Memory
301774 2020-09-18T07:48:57 Z Pro100Yan Connecting Supertrees (IOI20_supertrees) C++14
Compilation error
0 ms 0 KB
#include "supertrees.h"
#include <vector>
#include <iostream>
#define ll long long
#define pb push_back
 
using namespace std;
const int N = 2005;
vector<int> gr[N];
int used[N], d[N], sz[N];
vector<vector<int>> ans;
 
int get_parent(int v){
    while(v != d[v])
        v = d[v];
    return v;
}
 
void add(int u, int v){
    //cout << "Add " << u << ' ' << v << endl;
    int f = get_parent(u), s = get_parent(v);
    //cout << "Parents " << f << ' ' << s << endl;
    if(f != s){
        ans[f][s] = ans[s][f] = 1;
       	d[f] = d[s];
}
 
 
 
int construct(std::vector<std::vector<int>> p) {
	int n = p.size();
	int fault = 0;
	for(int i = 0; i < n; i++){
        d[i] = i;
        sz[i] = 1;
	}
	for(int i = 0; i < n; i++){
        ans.pb({});
        for(int j = 0; j < n; j++)
            ans[i].pb(0);
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(p[i][j] && i != j){
                add(i, j);
            }
        }
    }
  	for(int i = 0; i < n; i++){
     	for(int j = 0; j < n; j++){
         	int fp = get_parent(i);
          	int sp = get_parent(j);
          	if((fp == sp && p[i][j] == 0) || (fp != sp && p[i][j]))
             	return 0;
        }
    }
    /*for(int i = 0; i < n; i++){
        if(!used[i])
            dfs(i);
    }*/
	build(ans);
	return 1;
}
/*
5
1 0 0 1 1
0 1 1 0 0
0 1 1 0 0
1 0 0 1 1
1 0 0 1 1
*/

Compilation message

supertrees.cpp: In function 'void add(int, int)':
supertrees.cpp:30:48: error: a function-definition is not allowed here before '{' token
   30 | int construct(std::vector<std::vector<int>> p) {
      |                                                ^
supertrees.cpp:63:1: error: expected '}' at end of input
   63 | }
      | ^
supertrees.cpp:19:23: note: to match this '{'
   19 | void add(int u, int v){
      |                       ^