Submission #1200385

#TimeUsernameProblemLanguageResultExecution timeMemory
1200385peraConnecting Supertrees (IOI20_supertrees)C++20
Compilation error
0 ms0 KiB
//#include "supertrees.h" #include "bits/stdc++.h" #include <vector> using namespace std; void build(vector<vector<int>> ans){ for(int i = 0;i < (int)ans.size();i ++){ for(int j = 0;j < (int)ans[i].size();j ++){ cout << ans[i][j] << " "; } cout << '\n'; } } struct dsu{ int n , cnt; vector<int> P , sz; dsu(int _size){ n = _size; cnt = _size; P = vector<int>(_size + 1); iota(P.begin() , P.end() , 0); sz = vector<int>(_size + 1); fill(sz.begin() , sz.end() , 1); } function<int(int)> find = [&](int u){ ++u; return u == P[u] ? u : P[u] = find(P[u]); }; function<bool(int , int)> same = [&](int u , int v){ ++u,++v; return find(u) == find(v); }; function<bool(int , int)> join = [&](int u , int v){ ++u,++v; u = find(u); v = find(v); if(u != v){ if(sz[u] < sz[v]){ swap(u , v); } P[v] = u; sz[u] += sz[v]; --cnt; return true; } return false; }; }; int construct(std::vector<std::vector<int>> p) { int n = (int)p.size(); dsu d(n); for(int i = 0;i < n;i ++){ for(int j = 0;j < n;j ++){ if(p[i][j] > 0){ d.join(i , j); } } } for(int i = 0;i < n;i ++){ for(int j = 0;j < n;j ++){ if(d.same(i , j) && !p[i][j]){ return 0; } } } dsu dx(n); for(int i = 0;i < n;i ++){ for(int j = 0;j < n;j ++){ if(p[i][j] == 1){ dx.join(i , j); } } } for(int i = 0;i < n;i ++){ for(int j = 0;j < n;j ++){ if(dx.same(i , j) && p[i][j] != 1){ return 0; } } } vector<vector<int>> ans(n , vector<int>(n)); vector<vector<int>> v(n); for(int i = 0;i < n;i ++){ v[dx.find(i)].emplace_back(i); } for(int i = 0;i < n;i ++){ for(int j = 0;j + 1 < (int)v[i].size();j ++){ ans[v[i][j]][v[i][j + 1]] = 1; ans[v[i][j + 1]][v[i][j]] = 1; } } vector<int> st(n); vector<vector<int>> cyc(n); for(int i = 0;i < n;i ++){ int c1 = 0 , c2 = 0; for(int j = 0;j < n;j ++){ c1 += (p[i][j] == 1); c2 += (p[i][j] == 2); } if(c1 == 1 && c2 == d.sz[d.find(i)] - 1 && c2 > 0){ cyc[d.find(i)].emplace_back(i); } } for(int i = 0;i < n;i ++){ if(d.find(i) == i){ set<int> S; for(int x : cyc[i]){ S.insert(x); } for(int x : v[i]){ S.insert(x); } if((int)S.size() != d.sz[i]){ return 0; } if((int)v[i].size() > 0){ vector<bool> in_cyc(n); for(int x : cyc[i]){ in_cyc[x] = true; } bool done = true; for(int &x : v[i]){ if(in_cyc[x]){ swap(x , v[i][0]); done = true; } } if(!done){ cyc[i].emplace_back(v[i][0]); } } if((int)cyc.size() == 2){ return 0; } if((int)cyc[i].size() > 1){ for(int j = 0;j < (int)cyc[i].size();j ++){ int e = (j + 1) % ((int)cyc[i].size()); ans[cyc[i][j]][cyc[i][e]] = 1; ans[cyc[i][e]][cyc[i][j]] = 1; } } for(int j = 0;j + 1 < (int)v[i].size();j ++){ ans[v[i][j]][v[i][j + 1]] = 1; ans[v[i][j + 1]][v[i][j]] = 1; } } } build(ans); return 1; } int main(){ cout << construct({{1, 2}, {1, 2}}); }

Compilation message (stderr)

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