Submission #772862

#TimeUsernameProblemLanguageResultExecution timeMemory
772862fve5Connecting Supertrees (IOI20_supertrees)C++17
56 / 100
187 ms28016 KiB
#include <bits/stdc++.h> #include "supertrees.h" using namespace std; struct DSU { vector<int> nodes; int find(int node) { if (nodes[node] < 0) return node; return nodes[node] = find(nodes[node]); } void join(int u, int v) { u = find(u), v = find(v); if (u == v) return; if (nodes[u] > nodes[v]) swap(u, v); nodes[u] += nodes[v]; nodes[v] = u; } map<int, vector<int>> get_cc() { map<int, vector<int>> ans; for (int i = 0; i < nodes.size(); i++) { ans[find(i)].push_back(i); } return ans; } DSU(int size) : nodes(size, -1) { } }; int construct(vector<vector<int>> p) { int n = p.size(); vector adj(n, vector(n, 0)); vector act_p(n, vector(n, 0)); DSU dsu(n); for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (p[i][j]) dsu.join(i, j); } } auto ccs = dsu.get_cc(); for (auto [_, cc]: ccs) { DSU dsu2(cc.size()); for (auto x: cc) { for (auto y: cc) { act_p[x][y] = 2; } } for (int i = 0; i < cc.size(); i++) { for (int j = 0; j < cc.size(); j++) { if (p[cc[i]][cc[j]] == 1) dsu2.join(i, j); } } auto ccs2 = dsu2.get_cc(); vector<int> cycle; for (auto [r, cc2]: ccs2) { for (auto x: cc2) { for (auto y: cc2) { act_p[cc[x]][cc[y]] = 1; } } cycle.push_back(cc[r]); for (int i = 1; i < cc2.size(); i++) { adj[cc[cc2[i]]][cc[cc2[i - 1]]] = adj[cc[cc2[i - 1]]][cc[cc2[i]]] = 1; } } if (cycle.size() < 3) continue; for (int i = 0; i < cycle.size(); i++) { adj[cycle[i]][cycle[(i + 1) % cycle.size()]] = adj[cycle[(i + 1) % cycle.size()]][cycle[i]] = 1; } } if (p == act_p) { build(adj); return 1; } else { return 0; } }

Compilation message (stderr)

supertrees.cpp: In member function 'std::map<int, std::vector<int> > DSU::get_cc()':
supertrees.cpp:24:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |         for (int i = 0; i < nodes.size(); i++) {
      |                         ~~^~~~~~~~~~~~~~
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:53:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         for (int i = 0; i < cc.size(); i++) {
      |                         ~~^~~~~~~~~~~
supertrees.cpp:54:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |             for (int j = 0; j < cc.size(); j++) {
      |                             ~~^~~~~~~~~~~
supertrees.cpp:67:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |             for (int i = 1; i < cc2.size(); i++) {
      |                             ~~^~~~~~~~~~~~
supertrees.cpp:72:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |         for (int i = 0; i < cycle.size(); i++) {
      |                         ~~^~~~~~~~~~~~~~
#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...