Submission #1185020

#TimeUsernameProblemLanguageResultExecution timeMemory
1185020islam_2010Connecting Supertrees (IOI20_supertrees)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
vector<int> comp(n, -1);
int c = 0;
void dfs(int n, vector<vector<int>> p, int node){
    comp[node] = c;
    for(int i = 0; i < n; i++){
        if(p[node][i]==1 && comp[i]==-1){
            dfs(n, p, node);
        }
    }
}

int construct(vector<vector<int>> p) {
    int n = p.size();
    vector<vector<int>> b(n, vector<int>(n, 0));

    for(int i = 0; i < n; i++){
        if(comp[i]==-1){
            dfs(n, p, i);

        }
    }

    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if (p[i][j] == 1 && comp[i] != comp[j]) {
                return 0;
            }
            if (p[i][j] == 0 && comp[i] == comp[j]) {
                return 0;
            }
            
        }
    }
    for (int c = 0; c < cid; c++) {
        vector<int> g;
        for (int i = 0; i < n; i++) {
            if (comp[i] == c) g.push_back(i);
        }
        for (int i = 0; i + 1 < g.size(); i++) {
            int u = g[i], v = g[i + 1];
            b[u][v] = b[v][u] = 1;
        }
    }

    

    build(b);
    return 1;
}

Compilation message (stderr)

supertrees.cpp:4:18: error: 'n' was not declared in this scope; did you mean 'yn'?
    4 | vector<int> comp(n, -1);
      |                  ^
      |                  yn
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:37:25: error: 'cid' was not declared in this scope
   37 |     for (int c = 0; c < cid; c++) {
      |                         ^~~