Submission #783556

# Submission time Handle Problem Language Result Execution time Memory
783556 2023-07-15T03:49:22 Z mindiyak Connecting Supertrees (IOI20_supertrees) C++14
Compilation error
0 ms 0 KB
#include <vector>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <string>

static int n;
static std::vector<std::vector<int>> p;
static std::vector<std::vector<int>> b;
static bool called = false;

int construct(std::vector<std::vector<int>> p);
void build(std::vector<std::vector<int>> b);

static void check(bool cond, std::string message) {
    if (!cond) {
        printf("%s\n", message.c_str());
        fclose(stdout);
        exit(0);
    }
}

void build(std::vector<std::vector<int>> _b) {
    check(!called, "build is called more than once");
    called = true;
    check((int)_b.size() == n, "Invalid number of rows in b");
    for (int i = 0; i < n; i++) {
        check((int)_b[i].size() == n, "Invalid number of columns in b");
    }
    b = _b;
}

int main() {
    assert(scanf("%d", &n) == 1);
    
    p.resize(n);
    for (int i = 0; i < n; i++) {
        p[i].resize(n);
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            assert(scanf("%d", &p[i][j]) == 1);
        }
    }
    fclose(stdin);

    int possible = construct(p);

    check(possible == 0 || possible == 1, "Invalid return value of construct");
    if (possible == 1) {
        check(called, "construct returned 1 without calling build");
    } else {
        check(!called, "construct called build but returned 0");
    }

    printf("%d\n", possible);
    if (possible == 1) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (j) {
                    printf(" ");
                }
                printf("%d", b[i][j]);
            }
            printf("\n");
        }
    }
    fclose(stdout);
}


#include "supertrees.h"
#include <vector>
#include <iostream>

#define pb push_back

using namespace std;

int find_head(vector<int> a,int val){
	if(a[val] == val)
	    return val;
	return find_head(a,a[val]);
}

int find_leaf(vector<int> a,int val){
	if(a[val] == val)
	    return val;
	return find_leaf(a,a[val]);
}

int construct(vector<vector<int>> p) {
    // cout << "started" << endl;
	int n = p.size();

	vector<vector<int>> ans;
	vector<int> temp(n,0);
	vector<int> head;
	vector<int> leaf;
	for (int i = 0; i < n; i++) {
		ans.pb(temp);
		head.pb(i);
		leaf.pb(i);
	}

	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(p[i][j] == 1){
				int c = min(i,j),d = max(i,j);
				int h_c = find_head(head,c);
				int h_d = find_head(head,d);
				if(h_c != h_d){
				    ans[h_c][h_d] = 1;
				    ans[h_d][h_c] = 1;
				}
				head[h_d] = h_c;
				leaf[h_c] = find_leaf(leaf,d);
			} 
		}
	}

	build(ans);
// 	cout << "finish" << endl;
	return 1;
}

Compilation message

/usr/bin/ld: /tmp/cc5v3nNu.o: in function `build(std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >)':
grader.cpp:(.text+0x320): multiple definition of `build(std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >)'; /tmp/ccadmHjv.o:supertrees.cpp:(.text+0x370): first defined here
/usr/bin/ld: /tmp/cc5v3nNu.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccadmHjv.o:supertrees.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status