제출 #306661

#제출 시각아이디문제언어결과실행 시간메모리
306661vivaan_gupta슈퍼트리 잇기 (IOI20_supertrees)C++14
11 / 100
250 ms22232 KiB
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <ratio> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #include <climits> #include "supertrees.h" #define ll long long #define ld long double #define mp make_pair #define pb push_back #define in insert #define vll vector<ll> #define endl "\n" #define f first #define s second #define pll pair<int,int> // #define int ll using namespace std; struct DSU { int connected; vector<int> par, sz; void init(int n) { par = sz = vector<int> (n + 1, 0); for(int i = 1; i <= n; i++) par[i] = i, sz[i] = 1; connected = n; } int getPar(int u) { while(u != par[u]) { par[u] = par[par[u]]; u = par[u]; } return u; } int getSize(int u) { return sz[getPar(u)]; } void unite(int u, int v) { int par1 = getPar(u), par2 = getPar(v); if(par1 == par2) return; connected--; if(sz[par1] > sz[par2]) swap(par1, par2); sz[par2] += sz[par1]; sz[par1] = 0; par[par1] = par[par2]; } }; int construct(std::vector<std::vector<int>> p) { DSU g,g2; int n = p.size(); g.init(n-1); g2.init(n-1); std::vector<std::vector<int>> ans; for (int i = 0; i < n; i++) { std::vector<int> row; row.resize(n); ans.push_back(row); } for(int i =0;i<n;i++){ for(int j =i+1;j<n;j++){ if(p[i][j] >= 1){ g.unite(i,j); } if(p[i][j] == 1){ g2.unite(i,j); } } } map<int,int> col; vector<int> wow[n+1]; int c = 1; for(int i =0;i<n;i++){ int op = g.getPar(i); if(col[op] == 0){ col[op] = c; c++; } wow[col[op]].pb(i); } c--; for(int i =0;i<n;i++){ for(int j =0;j<n;j++){ ans[i][j] = 0; } } for(int i = 1;i<=c;i++){ if(wow[i].size() == 1) continue; bool ok = true; bool ok2 = true; set<int> lol; for(int j =0;j<wow[i].size();j++){ for(int k =j+1;k<wow[j].size();k++){ ok &= (p[wow[i][j]][wow[i][k]] == 1); ok2 &= (p[wow[i][j]][wow[i][k]] == 2); // if(p[wow[i][j]][wow[i][k]] == 0) return 0; lol.in(p[wow[i][j]][wow[i][k]]); } } if(lol.size() == 1 && *(lol.begin()) == 1){ // if(!ok){ // return 0; // } for(int j =0;j<wow[i].size()-1;j++){ ans[wow[i][j]][wow[i][j+1]] = 1; ans[wow[i][j+1]][wow[i][j]] = 1; } continue; } if(lol.size() == 1){ // if(!ok2){ // return 0; // } // if(wow[i].size() == 2) return 0; for(int j =0;j<wow[i].size()-1;j++){ ans[wow[i][j]][wow[i][j+1]] = 1; ans[wow[i][j+1]][wow[i][j]] = 1; } ans[wow[i].back()][wow[i][0]] = 1; ans[wow[i][0]][wow[i].back()] = 1; continue; } col.clear(); int gg = 1; vector<int> chains[n+2]; for(int j = 0;j<wow[i].size();j++){ int op = g2.getPar(wow[i][j]); if(col[op] == 0){ col[op] = gg; gg++; } chains[col[op]].pb(wow[i][j]); } vector<int> v; for(int j =1;j<gg;j++){ bool poss = true; for(int k =0;k<chains[j].size();k++){ for(int l = k+1;l<chains[j].size();l++){ assert(p[chains[j][k]][chains[j][l]] == 1); } } // if(!poss) return 0; for(int k=0;k<chains[j].size()-1;k++){ ans[chains[j][k]][chains[j][k+1]] = 1; ans[chains[j][k+1]][chains[j][k]] = 1; } v.pb(chains[j].back()); } for(int i= 0;i<v.size()-1;i++){ ans[v[i]][v[i+1]] = 1; ans[v[i+1]][v[i]] = 1; } if(v.size() == 1) continue; ans[v.back()][v[0]] = 1; ans[v[0]][v.back()] = 1; } build(ans); return 1; } // void solve(){ // } // signed main(){ // ios_base::sync_with_stdio(0); // cin.tie(NULL); // // freopen(".in","r",stdin);freopen(".out","w",stdout); // ll tt=1; // // cin >> tt; // while(tt--){ // solve(); // } // }

컴파일 시 표준 에러 (stderr) 메시지

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:141:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  141 |   for(int j =0;j<wow[i].size();j++){
      |                ~^~~~~~~~~~~~~~
supertrees.cpp:142:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  142 |    for(int k =j+1;k<wow[j].size();k++){
      |                   ~^~~~~~~~~~~~~~
supertrees.cpp:153:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  153 |    for(int j =0;j<wow[i].size()-1;j++){
      |                 ~^~~~~~~~~~~~~~~~
supertrees.cpp:164:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  164 |    for(int j =0;j<wow[i].size()-1;j++){
      |                 ~^~~~~~~~~~~~~~~~
supertrees.cpp:176:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  176 |   for(int j = 0;j<wow[i].size();j++){
      |                 ~^~~~~~~~~~~~~~
supertrees.cpp:187:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  187 |    for(int k =0;k<chains[j].size();k++){
      |                 ~^~~~~~~~~~~~~~~~~
supertrees.cpp:188:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  188 |     for(int l = k+1;l<chains[j].size();l++){
      |                     ~^~~~~~~~~~~~~~~~~
supertrees.cpp:193:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  193 |    for(int k=0;k<chains[j].size()-1;k++){
      |                ~^~~~~~~~~~~~~~~~~~~
supertrees.cpp:186:9: warning: unused variable 'poss' [-Wunused-variable]
  186 |    bool poss = true;
      |         ^~~~
supertrees.cpp:200:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  200 |   for(int i= 0;i<v.size()-1;i++){
      |                ~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...