Submission #1054959

#TimeUsernameProblemLanguageResultExecution timeMemory
1054959c2zi6Connecting Supertrees (IOI20_supertrees)C++14
100 / 100
111 ms28092 KiB
#define _USE_MATH_DEFINES #include <bits/stdc++.h> #define ff first #define ss second #define pb push_back #define all(a) (a).begin(), (a).end() #define replr(i, a, b) for (int i = int(a); i <= int(b); ++i) #define reprl(i, a, b) for (int i = int(a); i >= int(b); --i) #define rep(i, n) for (int i = 0; i < int(n); ++i) #define mkp(a, b) make_pair(a, b) using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> PII; typedef vector<int> VI; typedef vector<PII> VPI; typedef vector<VI> VVI; typedef vector<VVI> VVVI; typedef vector<VPI> VVPI; typedef pair<ll, ll> PLL; typedef vector<ll> VL; typedef vector<PLL> VPL; typedef vector<VL> VVL; typedef vector<VVL> VVVL; typedef vector<VPL> VVPL; template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;} template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;} #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; template<class T> using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #include "supertrees.h" VVI comps(VVI s, bool t0, bool t1, bool t2) { /*transformations*/ int n = s.size(); rep(i, n) rep(j, n) { if (s[i][j] == 0) s[i][j] = t0; else if (s[i][j] == 1) s[i][j] = t1; else if (s[i][j] == 2) s[i][j] = t2; } sort(all(s)); VVI ret; for (int i = 0; i < n; i++) { if (i == 0 || s[i] != s[i-1]) { if (i) rep(j, n) { if (s[i][j] && s[i-1][j]) { return VVI(); } } ret.pb(VI()); rep(j, n) if (s[i][j]) ret.back().pb(j); } } return ret; } int construct(VVI p) { int n = p.size(); VVI comp = comps(p, 0, 1, 1); if (comp.size() == 0) return 0; VVI ans(n, VI(n)); /*for (VI vec : comp) {*/ /* replr(i, 1, vec.size()-1) {*/ /* ans[vec[0]][vec[i]] = true;*/ /* ans[vec[i]][vec[0]] = true;*/ /* }*/ /*}*/ VVVI a; for (VI vec : comp) { int s = vec.size(); a.pb(VVI(s, VI(s))); rep(i, s) { rep(j, s) { int x = vec[i]; int y = vec[j]; a.back()[i][j] = p[x][y]; } } } VPI edges; rep(c, comp.size()) { int n = comp[c].size(); VVI p = a[c]; VVI trees = comps(p, 0, 1, 0); if (trees.size() == 0) return 0; for (VI& v : trees) for (int& x : v) x = comp[c][x]; /*cout << "COMPONENT ";*/ /*for (int x : comp[c]) cout << x << " "; cout << endl;*/ /*rep(i, n) {*/ /* rep(j, n) cout << p[i][j] << " ";*/ /* cout << endl;*/ /*}*/ /*for (VI v : trees) {*/ /* cout << " TREE ";*/ /* for (int x : v) cout << x << " ";*/ /* cout << endl;*/ /*}*/ VI roots; for (VI v : trees) { int r = v[0]; roots.pb(r); replr(i, 1, v.size()-1) { edges.pb({r, v[i]}); } } int r = roots.size(); if (r == 1) continue; if (r == 2) return 0; rep(i, r) { edges.pb({roots[i], roots[(i+1)%r]}); } } for (auto[u, v] : edges) { ans[u][v] = ans[v][u] = 1; /*cout << u << " " << v << endl;*/ } build(ans); return 1; }

Compilation message (stderr)

supertrees.cpp: In function 'int construct(VVI)':
supertrees.cpp:84:13: warning: unused variable 'n' [-Wunused-variable]
   84 |         int n = comp[c].size();
      |             ^
supertrees.cpp:119:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  119 |     for (auto[u, v] : edges) {
      |              ^
#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...