Submission #650306

#TimeUsernameProblemLanguageResultExecution timeMemory
650306esomerConnecting Supertrees (IOI20_supertrees)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#include "supertrees.h"

using namespace std;

#define ll long long
#define endl "\n"

const int MOD = 998244353;
/*
int n2;
std::vector<std::vector<int>> p;
std::vector<std::vector<int>> b;
bool called = false;

static void check(bool cond, std::string message) {
    if (!cond) {
        cout << message << endl;
        exit(0);
    }
}

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

void DFS(int x, vector<int>& num, int curr, int type, vector<vector<int>>& edges){
    if(curr == (int)num.size() - 1){
        if(type == 1) return;
        else{
            edges[num[curr]][x] = 1;
            edges[x][num[curr]] = 1;
            return;
        }
    }
    edges[num[curr]][num[curr + 1]] = 1;
    edges[num[curr + 1]][num[curr]] = 1;
    DFS(x, num, curr + 1, type, edges);
}

int construct(vector<vector<int>>& v){
    int n = (int)v[0].size();
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(p[i][j] == 3) return 0;
        }
    }
    vector<bool> done(n, 0);
    vector<vector<int>> edges(n, vector<int> (n, 0));
    for(int i = 0; i < n; i++){
        if(done[i]) continue;
        vector<int> two;
        vector<int> one;
        set<int> cc;
        cc.insert(i);
        done[i] = 1;
        for(int j = 0; j < n; j++){
            if(i == j) continue;
            if(v[i][j] == 1) {one.push_back(j); cc.insert(j);}
            else if(v[i][j] == 2) {two.push_back(j); cc.insert(j);}
        }
        for(int x : two){
            done[x] = 1;
            for(int j = 0; j < n; j++){
                if(x == j) continue;
                bool good = cc.count(j);
                if(good == false && v[x][j] > 0) return 0;
                if(good == true && v[x][j] != max(v[i][j], v[i][x])) return 0;
            }
        }
        for(int x : one){
            done[x] = 1;
            for(int j = 0; j < n; j++){
                if(x == j) continue;
                bool good = cc.count(j);
                if(good == false && v[x][j] > 0) return 0;
                if(good == true && v[x][j] != max(v[i][j], v[i][x])) return 0;
            }
        }
        if(two.size() == 1) return 0;
        if(one.size() > 0){
            edges[i][one[0]] = 1;
            edges[one[0]][i] = 1;
            DFS(i, one, 0, 1, edges);
        }
        if(two.size() > 0){
            edges[i][two[0]] = 1;
            edges[two[0]][i] = 1;
            DFS(i, two, 0, 2, edges);
        }
    }
    build(edges);
    return 1;
}
/*
int main() {
    cin >> n2;

    p.resize(n2);
    for (int i = 0; i < n2; i++) {
        p[i].resize(n2);
    }

    for (int i = 0; i < n2; i++) {
        for (int j = 0; j < n2; j++) {
            cin >> p[i][j];
        }
    }

    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");
    }

    cout << possible << endl;
    if (possible == 1) {
        for (int i = 0; i < n2; i++) {
            for (int j = 0; j < n2; j++) {
                if (j) {
                    cout << " ";
                }
                cout << b[i][j];
            }
            printf("\n");
        }
    }
}*/

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >&)':
supertrees.cpp:51:16: error: 'p' was not declared in this scope
   51 |             if(p[i][j] == 3) return 0;
      |                ^