Submission #666907

#TimeUsernameProblemLanguageResultExecution timeMemory
666907YENGOYAN슈퍼트리 잇기 (IOI20_supertrees)C++17
Compilation error
0 ms0 KiB
#include "supertrees.h"
#include <vector>

using namespace std;

vector<int> par, sizes;

int get(int u){
    if(par[u] == u) return u;
    return par[u] = get(par[u]);
}

bool areInOne(int u, int v){
    return get(u) == get(v);
}

void union_sets(int u, int v){
    int a = get(u), b = get(v);
    if(a == b) return;
    if(sizes[a] < sizes[b]) swap(a, b);
    sizes[a] += sizes[b];
    par[b] = a;
}

vector<int> comp;

void dfs(int u, vector<vector<int>> &gp, vector<bool> &vis){
    comp.push_back(u);
    vis[u] = 1;
    for(int &v : gp[u]){
        if(!vis[v]){
            dfs(v, gp, vis);
        }
    }

}

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

	int n = p.size();
	vector<vector<int>> gp(n, vector<int> (n));
	par = sizes = vector<int> (n);
	for(int i = 0; i < n; i++) par[i] = i, sizes[i] = 1;
	set<int> vec;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            if(!areInOne(i, j) && p[i][j] == 1){
                gp[i][j] = gp[j][i] = 1;
                union_sets(i, j);
                vec.insert(i);
                vec.insert(j);
            }
        }
    }
    vector<vector<int>> graph(n);
    for(int i = 0; i < n; i++){
        for(int j =  i + 1; j < n; j++){
            if(p[i][j] == 2) {
                graph[i].push_back(j);
                graph[j].push_back(i);
            }
        }
    }

    vector<bool> vis(n);
    for(int i = 0; i < n; i++){
        if(vis[i]) continue;
        comp.clear();
        dfs(u, graph, vis);
        bool f = 0;
        vector<int> rightComp;
        for(int i = 0; i < comp.size(); i++){
            if(vec.find(comp[i]) == vec.end()) rightComp.push_back(comp[i]);
            else if(!f) rightComp.push_back(comp[i]), f = 1;
        }
        for(int i = 0; i < comp.size() - 1; i++){
            gp[comp[i]][comp[i + 1]] = gp[comp[i + 1]][comp[i]] = 1;
        }
    }
	build(gp);
	return 1;
}

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:44:2: error: 'set' was not declared in this scope
   44 |  set<int> vec;
      |  ^~~
supertrees.cpp:2:1: note: 'std::set' is defined in header '<set>'; did you forget to '#include <set>'?
    1 | #include "supertrees.h"
  +++ |+#include <set>
    2 | #include <vector>
supertrees.cpp:44:6: error: expected primary-expression before 'int'
   44 |  set<int> vec;
      |      ^~~
supertrees.cpp:50:17: error: 'vec' was not declared in this scope
   50 |                 vec.insert(i);
      |                 ^~~
supertrees.cpp:69:13: error: 'u' was not declared in this scope
   69 |         dfs(u, graph, vis);
      |             ^
supertrees.cpp:72:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |         for(int i = 0; i < comp.size(); i++){
      |                        ~~^~~~~~~~~~~~~
supertrees.cpp:73:16: error: 'vec' was not declared in this scope
   73 |             if(vec.find(comp[i]) == vec.end()) rightComp.push_back(comp[i]);
      |                ^~~
supertrees.cpp:76:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |         for(int i = 0; i < comp.size() - 1; i++){
      |                        ~~^~~~~~~~~~~~~~~~~