Submission #379493

#TimeUsernameProblemLanguageResultExecution timeMemory
379493SuhaibSawalha1Connecting Supertrees (IOI20_supertrees)C++14
40 / 100
278 ms24300 KiB
#include "supertrees.h" #include <bits/stdc++.h> using namespace std; vector<int> dsu, sz; int find (int u) { return u == dsu[u] ? u : dsu[u] = find(dsu[u]); } bool unite (int u, int v) { if ((u = find(u)) != (v = find(v))) { if (sz[u] < sz[v]) { swap(u, v); } dsu[v] = u; sz[u] += sz[v]; return 1; } return 0; } int construct(vector<vector<int>> p) { int n = p.size(); dsu.resize(n); iota(dsu.begin(), dsu.end(), 0); sz.resize(n, 1); vector<vector<int>> ans(n, vector<int>(n)); bool two = 0; auto sit = [&] (int i, int j, int t) { ans[i][j] = ans[j][i] = t; }; for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { if (p[i][j] == 1) { sit(i, j, unite(i, j)); } if (p[i][j] == 2) { two = 1; unite(i, j); } } } for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { if (p[i][j] == 0 && find(i) == find(j)) { return 0; } } } if (two) { vector<vector<int>> c(n); for (int i = 0; i < n; ++i) { c[find(i)].push_back(i); } for (int i = 0; i < n; ++i) { if (c[i].size() >= 2) { if (c[i].size() == 2) { return 0; } sit(c[i][0], c[i][1], 1); sit(c[i][1], c[i][2], 1); for (int j = 3; j < c[i].size(); ++j) { sit(c[i][j], c[i][j - 1], 1); } sit(c[i].back(), c[i][0], 1); } } } build(ans); return 1; }

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:63:27: 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 = 3; j < c[i].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...