Submission #812706

#TimeUsernameProblemLanguageResultExecution timeMemory
812706KemalKConnecting Supertrees (IOI20_supertrees)C++17
40 / 100
172 ms24012 KiB
#include "supertrees.h" #include <vector> #include <bits/stdc++.h> using namespace std; const int N = 1e3 + 5; int pr[N]; int sz[N]; int get(int x){ if (pr[x] == x){ return x; } return (pr[x] = get(pr[x])); } void unit(int a, int b){ a = get(a); b = get(b); if (a != b){ if (sz[a] < sz[b]){ swap(a, b); } pr[b] = a; sz[a] += sz[b]; } } int construct(std::vector<std::vector<int>> p) { int n = p.size(); for (int i = 0; i < n; i++){ pr[i] = i; sz[i] = 1; } int check = 0; for (int i = 0; i < n; i++){ for (int j = 0; j < n; j++){ if (p[i][j]){ unit(i, j); check = max(check, p[i][j]); } } } for (int i = 0; i < n; i++){ for (int j = 0; j < n; j++){ if (p[i][j] == 0 and get(i) == get(j)){ //impossible return 0; } } } vector <vector<int>> answer(n, vector<int>(n)); if(!check){ build(answer); return 1; } for (int i = 0; i < n; i++){ vector <int> branch; for (int j = 0; j < n; j++){ if (get(j) == 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; } if (check == 2){ if(branch.size() == 2){ return 0; } if (branch.size() > 2){ answer[branch[0]][branch.back()] = 1; answer[branch.back()][branch[0]] = 1; } } } build(answer); return 1; }

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:58:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |   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...