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 <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define db double
#define ll __int128
//#define int long long
#define pb push_back
#define fs first
#define sd second
#define Mod long(1e9 + 7)
#define all(x) x.begin(), x.end()
#define unvisited long(-1)
#define Eps double(1e-9)
#define _for(i, n) for(int i = 0; i < (n); i++)
#define dbg(x) cout << #x ": " << x << endl;
const int Max = 1e6 + 7, Inf = 1e9 + 7;
void build(std::vector<std::vector<int>> b);
struct DSU
{
vector <int> link, size;
int find(int x)
{
while(x != link[x]) x = link[x];
return x;
}
int sz(int x)
{
return size[find(x)];
}
bool same(int a, int b)
{
return find(a) == find(b);
}
void unite(int a, int b)
{
a = find(a); b = find(b);
if(a == b) return;
if(size[a] < size[b]) swap(a, b);
link[b] = a; size[a] += size[b];
}
DSU(int n)
{
link.assign(n+1, 0);
size.assign(n+1, 1);
for(int i = 0; i <= n; i++)
link[i] = i;
}
};
int construct(std::vector<std::vector<int>> p)
{
int n = p.size(); DSU St(n), Fx(n);
vector <vector<int>> g(n, vector <int> (n, 0)),
ans(n, vector <int> (n, 0));
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++) if(j != i)
{
if(p[i][j] != p[j][i] || p[i][j] == 3)
return 0;
if(p[i][j] != 0)
St.unite(i, j);
}
}
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
if(St.same(i, j) && p[i][j] == 0 && i != j) return 0;
}
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
if(p[i][j] == 1 && !Fx.same(i, j))
{
Fx.unite(i, j);
ans[i][j] = ans[j][i] = 1;
}
}
}
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
if(Fx.same(i, j) && p[i][j] == 2) return 0;
}
map <int, int> mp;
for(int i = 0; i < n; i++)
{
if(mp[St.find(i)]) continue;
mp[St.find(i)] = 1;
vector <int> s;
for(int j = 0; j < n; j++)
{
if(St.same(i, j) && St.find(j) == j)
{
s.push_back(j);
}
}
int m = s.size();
if(m > 1)
for(int i = 0; i < m; i++)
ans[s[i]][s[(i+1)%m]] = ans[s[(i+1)%m]][s[i]] = 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... |