Submission #419435

#TimeUsernameProblemLanguageResultExecution timeMemory
419435vkgainzConnecting Supertrees (IOI20_supertrees)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;


//void build(vector<vector<int>> b);

void build(vector<vector<int>> b) {
    int n = (int) b.size();
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            cout << b[i][j] << " ";
        }
        cout << "\n";
    }
}

int construct(vector<vector<int>> p) {
    int n = (int) p.size();
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            if(p[i][j] == 3) return 0;
            if(p[i][j] != p[j][i]) return 0;
        }
    }

    vector<vector<int>> put(n, vector<int>(n));
    vector<bool> vis(n);
    vector<int> id(n);
    vector<vector<int>> store(n);
    for(int x = 0; x < n; x++) {
        if(vis[x]) continue;
        queue<int> q;
        vector<int> f;
        q.push(x);
        vis[x] = true;
        while(!q.empty()) {
            auto curr = q.front();
            f.push_back(curr);
            q.pop();
            for(int next = 0; next < n; next++) {
                if(p[curr][next] == 0) continue;

                if(p[curr][next] == 1) {
                    if(!vis[next]) {
                        vis[next] = true;
                        q.push(next);
                    }
                }
            }
        }

        for(int i = 0; i < (int) f.size(); i++) {
            for(int j = i + 1; j < (int) f.size(); j++) {
                if(p[f[i]][f[j]] != 1) return 0;
            }
        }
        
        for(int i = 0; i < (int) f.size() - 1; i++) {
            put[f[i]][f[i + 1]] = 1, put[f[i + 1]][f[i]] = 1;
        }
        store[x] = f;
        for(int i = 0; i < (int) f.size(); i++) {
            id[f[i]] = x;
        }
    }
    vis.clear(), vis.resize(n);
    for(int i = 0; i < n; i++) {
        bool zer = false, two = false;
        for(int j = i + 1; j < n; j++) {
            for(int x : store[i]) {
                for(int y : store[j]) {
                    if(p[x][y] == 0) zer = true;
                    if(p[x][y] == 2) two = true;
                }
            }
        }
        if(zer && two) return 0;
    }

    for(int i = 0; i < n; i++) {
        if(vis[i]) continue;
        vector<int> in;
        in.push_back(i);
        vis[i] = true;
        for(int j = 0; j < n; j++) {
            if(p[i][j] == 2) {
                in.push_back(j);
                vis[j] = true;
            }
        }
        if(in.size() == 2) return 0;
        if(in.size() == 1) continue;
        for(int j = 0; j < (int) in.size(); j++) {
            put[in[j]][in[(j + 1) % in.size()]] = 1, put[in[(j + 1) % in.size()]][in[j]] = 1;
        }
    }
    build(put);
    return 1;
}

int main() {
    int n; cin >> n;
    vector<vector<int>> p(n, vector<int>(n));
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            cin >> p[i][j];
    construct(p);
}

Compilation message (stderr)

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