Submission #576156

#TimeUsernameProblemLanguageResultExecution timeMemory
576156VanillaConnecting Supertrees (IOI20_supertrees)C++17
40 / 100
216 ms22936 KiB
#include <bits/stdc++.h> #include "supertrees.h" using namespace std; const int maxn = 1002; int dsu[3][maxn]; set <int> comp [3][maxn]; int get_dad (int x, int d[]) { return d[x] = (x == d[x] ? x: get_dad(d[x], d)); } void merge (int a, int b, int d[]){ a = get_dad(a, d); b = get_dad(b, d); d[b] = a; } int construct(vector<vector<int>> p) { int n = p.size(); vector <vector <int> > b (n, vector <int> (n)); for (int i = 0; i < n; i++){ dsu[0][i] = dsu[1][i] = dsu[2][i] = i; comp[1][i].insert(i); comp[2][i].insert(i); } for (int i = 0; i < n; i++){ for (int j = 0; j < i; j++){ merge(i,j, dsu[p[i][j]]); } } for (int i = 0; i < n; i++){ for (int j = 0; j < i; j++){ if (p[i][j] == 0 && (get_dad(i, dsu[1]) == get_dad(j, dsu[1]) || get_dad(i, dsu[2]) == get_dad(j, dsu[2]))) return 0; if (p[i][j] == 1 && get_dad(i, dsu[2]) == get_dad(j, dsu[2])) return 0; if (p[i][j] == 2 && get_dad(i, dsu[1]) == get_dad(j, dsu[1])) return 0; if (p[i][j] == 1) comp[1][get_dad(i, dsu[1])].insert(j); if (p[i][j] == 2) comp[2][get_dad(i, dsu[2])].insert(j); } } for (int i = 0; i < n; i++){ if (comp[1][i].size() != 1) { // cout << "1 " << i << ": "; vector <int> v; for (int j: comp[1][i]) { // cout << j << " "; v.push_back(j); } // cout << "\n"; for (int j = 0; j < v.size() - 1; j++){ b[v[j]][v[j + 1]] = b[v[j + 1]][v[j]] = 1; } } if (comp[2][i].size() != 1){ if (comp[2][i].size() == 2) return 0; // cout << "2 " << i << ": "; vector <int> v; for (int j: comp[2][i]) { // cout << j << " "; v.push_back(j); } // cout << "\n"; for (int j = 0; j < v.size(); j++){ b[v[j]][v[(j + 1) % v.size()]] = b[v[(j + 1) % v.size()]][v[j]] = 1; } } } // for (int i = 0; i < n; i++){ // for (int j = 0; j <i; j++){ // if (b[i][j]) { // cout << j << " " << i << "\n"; // } // } // } build(b); return 1; }

Compilation message (stderr)

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