Submission #401037

#TimeUsernameProblemLanguageResultExecution timeMemory
401037dxz05Connecting Supertrees (IOI20_supertrees)C++14
46 / 100
290 ms22464 KiB
#include "supertrees.h" #include <bits/stdc++.h> using namespace std; const int MAXN = 1111; int par[MAXN][3]; int find_set(int x, int flag){ if (x == par[x][flag]) return x; return par[x][flag] = find_set(par[x][flag], flag); } bool union_sets(int x, int y, int flag){ x = find_set(x, flag); y = find_set(y, flag); if (x == y) return false; if (rand() % 2) swap(x, y); par[x][flag] = y; return true; } vector<int> children[MAXN]; int construct(vector<vector<int>> p) { int n = p.size(); vector<vector<int>> answer(n, vector<int>(n, 0)); for (int i = 0; i < n; i++) par[i][1] = par[i][2] = i; for (int i = 0; i < n; i++){ for (int j = 0; j < n; j++){ if (p[i][j] == 1) union_sets(i, j, 1); if (p[i][j] == 3) return 0; } } for (int i = 0; i < n; i++){ for (int j = 0; j < n; j++){ if (p[i][j] == 2){ int x = find_set(i, 1), y = find_set(j, 1); union_sets(x, y, 2); } } } for (int i = 0; i < n; i++){ children[find_set(i, 2)].push_back(i); } for (int i = 0; i < n; i++){ if (children[i].size() < 2) continue; children[i].push_back(children[i].front()); for (int j = 0; j < children[i].size() - 1; j++){ int x = children[i][j], y = children[i][j + 1]; answer[x][y] = answer[y][x] = 1; } } for (int i = 0; i < n; i++){ int x = find_set(i, 1); if (x != i) answer[i][x] = answer[x][i] = 1; } for (int i = 0; i < n; i++){ for (int j = 0; j < n; j++){ if (p[i][j] == 1){ if (find_set(i, 1) != find_set(j, 1)) return 0; } if (p[i][j] == 2){ int x = find_set(i, 1), y = find_set(j, 1); if (find_set(x, 2) != find_set(y, 2)) return 0; } } } build(answer); return 1; }

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:55:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         for (int j = 0; j < children[i].size() - 1; j++){
      |                         ~~^~~~~~~~~~~~~~~~~~~~~~~~
#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...