제출 #1119019

#제출 시각아이디문제언어결과실행 시간메모리
1119019mannshah1211슈퍼트리 잇기 (IOI20_supertrees)C++17
0 / 100
1 ms596 KiB
/** * author: tourist * created: **/ #include "supertrees.h" #include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "algo/debug.h" #else #define debug(...) 42 #endif void build(vector<vector<int>> b); class dsu { public: vector<int> p; int n; dsu(int _n) : n(_n) { p.resize(n); iota(p.begin(), p.end(), 0); } int get(int x) { return ((p[x] == x) ? x : (p[x] = get(p[x]))); } bool unite(int u, int v) { u = get(u); v = get(v); if (u != v) { p[v] = u; return true; } return false; } }; int construct(vector<vector<int>> p) { int n = p.size(); dsu ds(n); for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (p[i][j] > 0) { ds.unite(i, j); } } } for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (!p[i][j]) { if (ds.unite(i, j)) { return 0; } } } } dsu two(n), one(n); for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (p[i][j] == 1) { one.unite(i, j); } if (p[i][j] == 2) { two.unite(i, j); } } } vector<vector<int>> b(n, vector<int>(n)); vector<vector<int>> comps(n); for (int i = 0; i < n; i++) { comps[one.get(i)].push_back(i); } for (int i = 0; i < n; i++) { for (int j = 0; j + 1 < comps[i].size(); j++) { b[comps[i][j + 1]][comps[i][j]] = true; b[comps[i][j]][comps[i][j + 1]] = true; } } for (int i = 0; i < n; i++) { comps[i].clear(); } for (int i = 0; i < n; i++) { comps[two.get(i)].push_back(i); } for (int i = 0; i < n; i++) { for (int j = 0; j < comps[i].size(); j++) { b[comps[i][(j + 1) % comps[i].size()]][comps[i][j]] = true; b[comps[i][j]][comps[i][(j + 1) % comps[i].size()]] = true; } } build(b); }

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

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:78:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |     for (int j = 0; j + 1 < comps[i].size(); j++) {
      |                     ~~~~~~^~~~~~~~~~~~~~~~~
supertrees.cpp:90:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |     for (int j = 0; j < comps[i].size(); j++) {
      |                     ~~^~~~~~~~~~~~~~~~~
supertrees.cpp:44:11: warning: control reaches end of non-void function [-Wreturn-type]
   44 |   dsu ds(n);
      |           ^
#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...