제출 #808704

#제출 시각아이디문제언어결과실행 시간메모리
808704The_Samurai슈퍼트리 잇기 (IOI20_supertrees)C++17
100 / 100
184 ms23132 KiB
#include "bits/stdc++.h" #ifdef sunnatov #include "grader.cpp" #else #include "supertrees.h" #endif using namespace std; struct dsu { vector<int> p, size; void init(int n) { p.assign(n, 0); size.assign(n, 1); for (int i = 0; i < n; i++) p[i] = i; } int get(int a) { return p[a] == a ? a : p[a] = get(p[a]); } void add(int a, int b) { a = get(a); b = get(b); if (a == b) return; if (size[a] > size[b]) swap(a, b); size[b] += size[a]; p[a] = b; } }; int construct(std::vector<std::vector<int>> p) { int n = p.size(); vector<vector<int>> g(n, vector<int>(n)); dsu ds; ds.init(n); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (p[i][j]) { ds.add(i, j); } if (p[i][j] == 3) return 0; } } vector<bool> vis(n); for (int _ = 0; _ < n; _++) { int s = -1; vector<int> v; for (int i = 0; i < n; i++) { if (vis[i]) continue; if (s == -1) s = ds.get(i); if (ds.get(i) != s) continue; v.emplace_back(i); } if (v.empty()) break; for (int i = 0; i < v.size(); i++) { for (int j = i + 1; j < v.size(); j++) { if (!p[v[i]][v[j]]) return 0; } } // something vector<bool> another_vis(n); vector<int> cycle; for (int x: v) { if (another_vis[x]) continue; vector<int> line; for (int i = 0; i < n; i++) { if (p[x][i] == 1) line.emplace_back(i); } for (int i = 0; i < line.size(); i++) { for (int j = i + 1; j < line.size(); j++) { if (p[line[i]][line[j]] != 1) return 0; } } for (int i = 1; i < line.size(); i++) g[line[i - 1]][line[i]] = g[line[i]][line[i - 1]] = 1; for (int y: line) another_vis[y] = true; cycle.emplace_back(line[0]); } if (cycle.size() == 2) return false; if (cycle.size() > 2) { for (int i = 1; i < cycle.size(); i++) g[cycle[i - 1]][cycle[i]] = g[cycle[i]][cycle[i - 1]] = 1; g[cycle[0]][cycle.back()] = g[cycle.back()][cycle[0]] = 1; } for (int x: v) vis[x] = true; } build(g); return 1; }

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

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:59:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |         for (int i = 0; i < v.size(); i++) {
      |                         ~~^~~~~~~~~~
supertrees.cpp:60:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |             for (int j = i + 1; j < v.size(); j++) {
      |                                 ~~^~~~~~~~~~
supertrees.cpp:74:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |             for (int i = 0; i < line.size(); i++) {
      |                             ~~^~~~~~~~~~~~~
supertrees.cpp:75:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |                 for (int j = i + 1; j < line.size(); j++) {
      |                                     ~~^~~~~~~~~~~~~
supertrees.cpp:79:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |             for (int i = 1; i < line.size(); i++) g[line[i - 1]][line[i]] = g[line[i]][line[i - 1]] = 1;
      |                             ~~^~~~~~~~~~~~~
supertrees.cpp:85:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |             for (int i = 1; i < cycle.size(); i++) g[cycle[i - 1]][cycle[i]] = g[cycle[i]][cycle[i - 1]] = 1;
      |                             ~~^~~~~~~~~~~~~~
#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...