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], isline[1005];
vi comp[1005];
bool vis[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));
vector<vi> check = vector<vi>(n, vi(n, 0));
memset(isline, -1, sizeof isline);
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);
if (ok) isline[i] = i;
}
for (auto i:line) {
if (vis[i]) continue;
vis[i] = 1;
cyc.pb(i);
int pre = i;
FOR(j, 0, n-1) if (i != j and v[i][j] == 1 and isline[j]) {
ans[pre][j] = ans[j][pre] = 1;
pre = j; vis[j] = 1; isline[j] = i;
}
}
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;
for (auto i:comp[it]) for (auto j:comp[it]) {
if (isline[i] == -1 or isline[j] == -1 or isline[i] != isline[j]) check[i][j] = 2;
else check[i][j] = 1;
if (i == j) check[i][j] = 1;
}
}
if (check != v) return 0;
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... |