Submission #813029

#TimeUsernameProblemLanguageResultExecution timeMemory
813029KemalKConnecting Supertrees (IOI20_supertrees)C++17
0 / 100
1 ms340 KiB
#include "supertrees.h" #include <vector> #include <bits/stdc++.h> using namespace std; // DSU int Root(int a, vector <int> &root){ if (root[a] == a){ return a; } return (root[a] = Root(root[a], root)); } void unit(int a, int b, vector <int> &root, vector <int> &sz){ a = Root(a, root); b = Root(b, root); if (a != b){ if (sz[a] < sz[b]){ swap(a, b); } root[b] = root[a]; sz[a] += sz[b]; } } int construct(std::vector<std::vector<int>> p) { int n = p.size(); vector<vector <int>> answer(n, vector <int> (n)); vector <int> root(n), sz(n, 1); for (int i = 0; i < n; i++){ root[i] = i; } int check = 0; for (int i = 0; i < n; i++){ for (int j = 0; j < n; j++){ if (p[i][j] != 1){ check = max(check, p[i][j]); } } } if (check != 2 and check != 3){ for (int i = 0 ; i < n; i++){ for (int j = 0; j < n; j++){ if(p[i][j]){ unit(i, j, root, sz); } } } for (int i = 0; i <= n; i++){ for (int j = 0; j < n; j++){ if (p[i][j] == 1 and Root(i, root) != Root(j, root)){ return 0; } } } vector <vector <int>> forest(n, vector <int> (n)); for (int i = 0; i < n; i++){ vector <int> branch; for (int j = 0; j < n; j++){ if (Root(j, root) == i){ branch.push_back(j); } } for (int j = 0; j + 1 < branch.size(); j++){ answer[branch[j]][branch[j + 1]] = 1; answer[branch[j + 1]][branch[j]] = 1; } } } build(answer); return 1; }

Compilation message (stderr)

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