제출 #303504

#제출 시각아이디문제언어결과실행 시간메모리
303504Jarif_Rahman슈퍼트리 잇기 (IOI20_supertrees)C++17
11 / 100
266 ms24824 KiB
#include "supertrees.h" #include <bits/stdc++.h> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; vector<vector<int>> v; vector <vector<int>> dsu1; vector <int> dsu2; void unite(int a, int b){ if(dsu2[a] == dsu2[b]) return; int x = dsu2[a], y = dsu2[b]; if(dsu1[x].size() < dsu1.size()){ while(!dsu1[x].empty()){ int ss = dsu1[x].back(); dsu1[x].pop_back(); dsu2[ss] = y; dsu1[y].pb(ss); } } else{ while(!dsu1[y].empty()){ int ss = dsu1[y].back(); dsu1[y].pop_back(); dsu2[ss] = x; dsu1[x].pb(ss); } } } int construct(vector<vector<int>> p){ v.clear(); dsu1.clear(); dsu2.clear(); int n = p.size(); v = vector<vector<int>>(n, vector<int>(n, 0)); dsu1 = vector<vector<int>>(n); dsu2 = vector<int>(n); for(int i = 0; i < n ; i++) dsu1[i].pb(i); for(int i = 0; i < n; i++) dsu2[i] = i; for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if(p[i][j] != 0) unite(i, j); for(auto sth: dsu1){ if(sth.size() < 2) continue; vector <int> two, one; for(int x: sth){ int o = 0,tw = 0; for(int k = 0; k < n; k++){ if(k == x) continue; if(p[x][k] == 1) o++; } if(o == 0) two.pb(x); else one.pb(x); } for(int i = 0; i < (int)one.size() - 1; i++){ int x = one[i], y = one[i+1]; v[x][y] = 1; v[y][x] = 1; } if(two.size() == 0) continue; for(int i = 0; i < (int)two.size() - 1; i++){ int x = two[i], y = two[i+1]; v[x][y] = 1; v[y][x] = 1; } if(one.size() == 0){ int x = two[0], y = two.back(); v[x][y] = 1; v[y][x] = 1; } else{ int x = two[0], y = two.back(), z = one[0]; v[x][z] = 1; v[z][x] = 1; v[y][z] = 1; v[z][y] = 1; } } build(v); return 1; }

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

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:47:23: warning: unused variable 'tw' [-Wunused-variable]
   47 |             int o = 0,tw = 0;
      |                       ^~
#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...