Submission #396747

#TimeUsernameProblemLanguageResultExecution timeMemory
396747priority_queueConnecting Supertrees (IOI20_supertrees)C++14
Compilation error
0 ms0 KiB
// ioi 2020, day 1, supertrees

#include <bits/stdc++.h>

using namespace std;

#define forint(i, N) for (int i = 0; i < (N); i++)

using namespace std;


void build(std::vector<std::vector<int> > b) {
    for (auto& a : b) {
        for (auto& aa : a) {
            cout << aa << " ";
        }
        cout << endl;
    }
}


int construct(vector<std::vector<int> > p) {

    int N = p.size();

    vector< vector<int> > b(N, vector<int>(N, 0));

    vector<int> visited(N, -1);

    forint(i, N) {
        if (visited[i] < 0) { // create new. All connected to i also not visited
            //visited[i] = i;
            vector<int> path2;
            vector<int> path3;

            forint (j, N) {
                if (j == i) {
                    continue;
                }
                if (p[i][j] == 1) {
                    b[i][j] = 1;
                    b[j][i] = 1;
                    visited[j] = i;
                    continue;
                }

                if (p[i][j] == 2) {
                    if (!path3.empty()) {
                        return 0;
                    }
                    path2.push_back(j);
                    visited[j] = i;
                    continue;
                }

                if (p[i][j] == 3) {
                    if (!path2.empty()) {
                        return 0;
                    }
                    path3.push_back(j);
                    visited[j] = i;
                    continue;
                }
            }

            if (!path2.empty()) {
                if (path2.size() < 2) {
                    return 0;
                }
                b[i][path2[0]] = 1;
                b[path2[0]][i] = 1;
                forint(j, path2.size()-1) {
                    b[path2[j]][path2[j+1]] = 1;
                    b[path2[j+1]][path2[j]] = 1;
                }

                b[i][path2[path2.size()-1]] = 1;
                b[path2[path2.size()-1]][i] = 1;

            }

            if (!path3.empty()) {
                if (path3.size() < 3) {
                    return 0;
                }

                b[i][path3[1]] = 1;
                b[path3[1]][i] = 1;
                for(int j = 1; j < path3.size()-1; j++) {
                    b[path3[j]][path3[j+1]] = 1;
                    b[path3[j+1]][path3[j]] = 1;
                }

                b[i][path3[path3.size()-1]] = 1;
                b[path3[path3.size()-1]][i] = 1;

                b[i][path3[0]] = 1;
                b[path3[0]][i] = 1;

                b[path3[0]][path3[1]] = 1;
                b[path3[1]][path3[0]] = 1;
            }
        }
        else { // check if it is OK
            forint (j, N) {
                if (j != i && j != visited[i]) {
                    if (p[i][j] == p[visited[i]][j] && p[i][j] == p[visited[i]][i]) {
                        continue;
                    }
                    if (p[i][j] == p[visited[i]][j] * p[visited[i]][i]) {
                        continue;
                    }
                    //cout << i << " ---- " << j << endl;
                    return 0;
                }
            }
        }
    }

    build(b);

    return 1;

}

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:7:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 | #define forint(i, N) for (int i = 0; i < (N); i++)
      |                                        ^
supertrees.cpp:72:17: note: in expansion of macro 'forint'
   72 |                 forint(j, path2.size()-1) {
      |                 ^~~~~~
supertrees.cpp:89:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |                 for(int j = 1; j < path3.size()-1; j++) {
      |                                ~~^~~~~~~~~~~~~~~~
/tmp/ccFEsI1x.o: In function `build(std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >)':
grader.cpp:(.text+0x1d0): multiple definition of `build(std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >)'
/tmp/ccIpOyL3.o:supertrees.cpp:(.text+0x0): first defined here
collect2: error: ld returned 1 exit status