#ifdef LOCAL
#include "local.h"
#else
#include <bits/stdc++.h>
#define debug(...)
#define DB(...)
#endif
using namespace std;
const bool __initialization = []() {
cin.tie(nullptr)->sync_with_stdio(false);
cout << setprecision(12) << fixed;
return true;
}();
using ll = long long;
using ld = long double;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define For(i, l, r) for (int i = (l); i <= (r); ++i)
#define Ford(i, r, l) for (int i = (r); i >= (l); --i)
#define Rep(i, n) For (i, 0, (n) - 1)
#define Repd(i, n) Ford (i, (n) - 1, 0)
#define Fe(...) for (auto __VA_ARGS__)
template <class C> inline int isz(const C& c) { return static_cast<int>(c.size()); }
template <class T> inline bool chmin(T& a, const T& b) { return (a > b) ? a = b, true : false; }
template <class T> inline bool chmax(T& a, const T& b) { return (a < b) ? a = b, true : false; }
constexpr ld eps = 1e-9;
constexpr int inf = 1e9;
constexpr ll linf = 1e18;
// =============================================================================
#include "supertrees.h"
constexpr int maxn = 3e5 + 5;
vector<vector<int>> ans;
vector<int> par;
vector<int> deg;
int find(int x) {
return (par[x] < 0) ? x : (par[x] = find(par[x]));
}
bool merge(int u, int v) {
u = find(u), v = find(v);
if (u == v) return false;
if (par[v] < par[u]) swap(u, v);
par[u] += par[v];
par[v] = u;
return true;
}
bool same(int u, int v) {
return find(u) == find(v);
}
int construct(vector<vector<int>> req) {
int n = req.size();
ans.assign(n, vector<int>(n));
par.assign(n, -1);
deg.assign(n, 0);
Rep (i, n) {
For (j, i + 1, n - 1) {
assert(req[i][j] == 0 || req[i][j] == 2);
if (!req[i][j]) continue;
if (merge(i, j)) {
ans[i][j] = ans[j][i] = 1;
if (++deg[i] > 2) return 0;
if (++deg[j] > 2) return 0;
}
}
}
Rep (i, n) {
For (j, i + 1, n - 1) {
if (!req[i][j]) continue;
if (same(i, j) && !ans[i][j]) {
ans[i][j] = ans[j][i] = 1;
if (++deg[i] > 2) return 0;
if (++deg[j] > 2) return 0;
}
}
}
Rep (i, n) {
if (par[i] == -2) {
return 0;
}
}
build(ans);
return 1;
}
// does oj.uz allow IOI-style scoring?
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
7 ms |
1100 KB |
Output is correct |
9 |
Correct |
173 ms |
21956 KB |
Output is correct |
10 |
Incorrect |
0 ms |
204 KB |
Answer gives possible 0 while actual possible 1 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |