This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(int i = (int)a; i <= (int)b; i++)
#define DEC(i, a, b) for(int i = (int)a; i >= (int)b; i--)
typedef pair<int, int> pi;
typedef pair<pi, int> pii;
typedef pair<pi, pi> pipi;
#define f first
#define s second
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define disc(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
#define INF (int) 1e9 + 100
#define LLINF (ll) 1e18
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sandybridge __attribute__((optimize("Ofast"), target("arch=sandybridge")))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //can be used by calling rng() or shuffle(A, A+n, rng)
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
int n, p[1005];
vi comp[1005];
int fs(int x) {
if (p[x] == x) return x;
return p[x] = fs(p[x]);
}
int construct(vector<vector<int>> v) {
n = v.size();
vector<vi> ans = vector<vi>(n, vi(n, 0));
FOR(i, 0, n-1) p[i] = i;
FOR(i, 0, n-1) FOR(j, 0, n-1) if (v[i][j]) p[fs(i)] = fs(j);
FOR(i, 0, n-1) comp[fs(i)].pb(i);
FOR(it, 0, n-1) {
vi line, cyc;
for (auto i:comp[it]) {
bool ok = 0;
for (auto j:comp[it]) if (i != j and v[i][j] == 1) ok = 1;
(ok ? line : cyc).pb(i);
}
//~ for (auto i:line) cout << i << " "; cout << "\n";
//~ for (auto i:cyc) cout << i << " "; cout << "\n";
FOR(i, 1, line.size()-1) ans[line[i-1]][line[i]] = ans[line[i]][line[i-1]] = 1;
if (!line.empty()) cyc.pb(line[0]);
//~ if (!line.empty() and !cyc.empty()) ans[line[0]][cyc[0]] = ans[cyc[0]][line[0]] = 1;
FOR(i, 1, cyc.size()-1) ans[cyc[i-1]][cyc[i]] = ans[cyc[i]][cyc[i-1]] = 1;
if (cyc.size() > 1) ans[cyc[0]][cyc.back()] = ans[cyc.back()][cyc[0]] = 1;
}
build(ans);
return 1;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |