#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb(e) push_back(e)
#define sv(a) sort(a.begin(),a.end())
#define sa(a,n) sort(a,a+n)
#define mp(a,b) make_pair(a,b)
#define vf first
#define vs second
#define ar array
#define all(x) x.begin(),x.end()
const int inf = 0x3f3f3f3f;
const int mod = 1000000007;
const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;
bool remender(ll a , ll b){return a%b;}
/*void build(vector<vector<int>>& ans){
for(int i = 0; i < (int)ans.size(); i++){
for(int j = 0; j < (int)ans.size(); j++)cout << ans[i][j] << ' ';
cout << '\n';
}
}*/
struct UFDS {
vector<int> p,siz;
void init(int n){
p.resize(n + 3);
siz.resize(n + 3);
for(int i = 0; i <= n; i++){
p[i] = i;
siz[i] = 1;
}
}
int get(int x){
return p[x]=(x==p[x] ? x : get(p[x]));
}
void unio(int u , int v){
int a = get(u);
int b=get(v);
if(a==b)return;
if(siz[a]>siz[b])swap(a,b);
p[b]=a;
siz[a]+=siz[b];
}
};
vector<vector<int>> b;
vector<int> adj[2003];
int help(vector<int>& v){
UFDS uf;
int n = v.size();
uf.init(n + 2);
for(int i = 0; i < n; i++){
for(int j = i+1; j < n;j++){
if(b[v[i]][v[j]] == 1){
uf.unio(i,j);
}
}
}
for(int i = 0; i < n; i++){
for(int j = i+1; j < n; j++){
if(uf.get(i) == uf.get(j) && b[v[i]][v[j]] == 2)return -1;
}
}
vector<vector<int>> v1;
bool vis1[n + 1];
memset(vis1,0,sizeof vis1);
for(int i = 0; i < n; i++){
if(!vis1[i]){
vector<int> x;
x.pb(v[i]);
vis1[i] = 1;
for(int j = i+1; j < n; j++){
if(uf.get(i) == uf.get(j)){
x.pb(v[j]);
vis1[j] = 1;
}
}
v1.pb(x);
}
}
if(v1.size() == 2)return -1;
for(int i = 0; i < (int)v1.size() && v1.size() > 2; i++){
if(i == (int)v1.size()-1){
adj[v1[i][0]].pb(v1[0][0]);
adj[v1[0][0]].pb(v1[i][0]);
}
else {
adj[v1[i][0]].pb(v1[i + 1][0]);
adj[v1[i+1][0]].pb(v1[i][0]);
}
}
for(int i = 0; i < (int)v1.size(); i++){
for(int j = 1; j < (int)v1[i].size(); j++){
adj[v1[i][j]].pb(v1[i][j-1]);
adj[v1[i][j-1]].pb(v1[i][j]);
}
}
return 1;
}
int construct(std::vector<std::vector<int>> v){
int n = v.size();
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++)if(v[i][j] == 3)return 0;
}
UFDS d;
b = v;
d.init(n + 2);
for(int i = 0; i < n; i++){
for(int j = i + 1; j < n; j++){
if(v[i][j]!=0)d.unio(i,j);
}
}
for(int i = 0; i < n; i++){
for(int j = i + 1 ;j < n; j++){
if(v[i][j] == 0 && d.get(i) == d.get(j))return 0;
}
}
vector<vector<int>> com;
bool vis[n + 1];
memset(vis,0,sizeof vis);
for(int i = 0; i < n; i++){
if(!vis[i]){
vector<int> x;
x.pb(i);
vis[i] = 1;
for(int j = i+1; j < n; j++){
if(d.get(i) == d.get(j)){
x.pb(j);
vis[j] = 1;
}
}
com.pb(x);
}
}
vector<vector<int>> ans(n,vector<int> (n,0));
for(int i = 0; i < (int)com.size(); i++){
int x = help(com[i]);
if(x == -1)return 0;
}
for(int i = 0; i < n; i++){
for(int j : adj[i]){
ans[i][j] = 1;
}
}
build(ans);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
7 ms |
1360 KB |
Output is correct |
7 |
Correct |
177 ms |
26308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
7 ms |
1360 KB |
Output is correct |
7 |
Correct |
177 ms |
26308 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
10 ms |
1356 KB |
Output is correct |
13 |
Correct |
173 ms |
26300 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
4 ms |
716 KB |
Output is correct |
17 |
Correct |
108 ms |
12080 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
46 ms |
6832 KB |
Output is correct |
21 |
Correct |
167 ms |
26016 KB |
Output is correct |
22 |
Correct |
170 ms |
26040 KB |
Output is correct |
23 |
Correct |
183 ms |
26040 KB |
Output is correct |
24 |
Correct |
168 ms |
26040 KB |
Output is correct |
25 |
Correct |
77 ms |
12100 KB |
Output is correct |
26 |
Correct |
68 ms |
12088 KB |
Output is correct |
27 |
Correct |
179 ms |
26036 KB |
Output is correct |
28 |
Correct |
172 ms |
26092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
7 ms |
1356 KB |
Output is correct |
9 |
Correct |
183 ms |
26084 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
7 ms |
1356 KB |
Output is correct |
13 |
Correct |
193 ms |
26040 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
4 ms |
716 KB |
Output is correct |
17 |
Correct |
95 ms |
12088 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
0 ms |
332 KB |
Output is correct |
21 |
Correct |
44 ms |
6832 KB |
Output is correct |
22 |
Correct |
170 ms |
26068 KB |
Output is correct |
23 |
Correct |
180 ms |
26140 KB |
Output is correct |
24 |
Correct |
186 ms |
25984 KB |
Output is correct |
25 |
Correct |
77 ms |
16308 KB |
Output is correct |
26 |
Correct |
82 ms |
12084 KB |
Output is correct |
27 |
Correct |
170 ms |
26040 KB |
Output is correct |
28 |
Correct |
180 ms |
26108 KB |
Output is correct |
29 |
Correct |
95 ms |
16068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
51 ms |
6768 KB |
Output is correct |
5 |
Correct |
181 ms |
26008 KB |
Output is correct |
6 |
Correct |
172 ms |
26040 KB |
Output is correct |
7 |
Correct |
176 ms |
26040 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
44 ms |
6828 KB |
Output is correct |
10 |
Correct |
171 ms |
26064 KB |
Output is correct |
11 |
Correct |
183 ms |
26052 KB |
Output is correct |
12 |
Correct |
182 ms |
26052 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
45 ms |
6808 KB |
Output is correct |
17 |
Correct |
170 ms |
26036 KB |
Output is correct |
18 |
Correct |
175 ms |
26016 KB |
Output is correct |
19 |
Correct |
187 ms |
26028 KB |
Output is correct |
20 |
Correct |
178 ms |
26052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
7 ms |
1360 KB |
Output is correct |
7 |
Correct |
177 ms |
26308 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
10 ms |
1356 KB |
Output is correct |
13 |
Correct |
173 ms |
26300 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
4 ms |
716 KB |
Output is correct |
17 |
Correct |
108 ms |
12080 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
46 ms |
6832 KB |
Output is correct |
21 |
Correct |
167 ms |
26016 KB |
Output is correct |
22 |
Correct |
170 ms |
26040 KB |
Output is correct |
23 |
Correct |
183 ms |
26040 KB |
Output is correct |
24 |
Correct |
168 ms |
26040 KB |
Output is correct |
25 |
Correct |
77 ms |
12100 KB |
Output is correct |
26 |
Correct |
68 ms |
12088 KB |
Output is correct |
27 |
Correct |
179 ms |
26036 KB |
Output is correct |
28 |
Correct |
172 ms |
26092 KB |
Output is correct |
29 |
Correct |
0 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
0 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
0 ms |
332 KB |
Output is correct |
35 |
Correct |
0 ms |
332 KB |
Output is correct |
36 |
Correct |
7 ms |
1356 KB |
Output is correct |
37 |
Correct |
183 ms |
26084 KB |
Output is correct |
38 |
Correct |
1 ms |
332 KB |
Output is correct |
39 |
Correct |
0 ms |
332 KB |
Output is correct |
40 |
Correct |
7 ms |
1356 KB |
Output is correct |
41 |
Correct |
193 ms |
26040 KB |
Output is correct |
42 |
Correct |
0 ms |
332 KB |
Output is correct |
43 |
Correct |
1 ms |
332 KB |
Output is correct |
44 |
Correct |
4 ms |
716 KB |
Output is correct |
45 |
Correct |
95 ms |
12088 KB |
Output is correct |
46 |
Correct |
1 ms |
332 KB |
Output is correct |
47 |
Correct |
0 ms |
332 KB |
Output is correct |
48 |
Correct |
0 ms |
332 KB |
Output is correct |
49 |
Correct |
44 ms |
6832 KB |
Output is correct |
50 |
Correct |
170 ms |
26068 KB |
Output is correct |
51 |
Correct |
180 ms |
26140 KB |
Output is correct |
52 |
Correct |
186 ms |
25984 KB |
Output is correct |
53 |
Correct |
77 ms |
16308 KB |
Output is correct |
54 |
Correct |
82 ms |
12084 KB |
Output is correct |
55 |
Correct |
170 ms |
26040 KB |
Output is correct |
56 |
Correct |
180 ms |
26108 KB |
Output is correct |
57 |
Correct |
95 ms |
16068 KB |
Output is correct |
58 |
Correct |
1 ms |
332 KB |
Output is correct |
59 |
Correct |
0 ms |
332 KB |
Output is correct |
60 |
Correct |
4 ms |
716 KB |
Output is correct |
61 |
Correct |
85 ms |
12100 KB |
Output is correct |
62 |
Correct |
0 ms |
332 KB |
Output is correct |
63 |
Correct |
0 ms |
332 KB |
Output is correct |
64 |
Correct |
0 ms |
332 KB |
Output is correct |
65 |
Correct |
43 ms |
6800 KB |
Output is correct |
66 |
Correct |
73 ms |
12100 KB |
Output is correct |
67 |
Correct |
70 ms |
12080 KB |
Output is correct |
68 |
Correct |
94 ms |
12088 KB |
Output is correct |
69 |
Correct |
77 ms |
16168 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
7 ms |
1360 KB |
Output is correct |
7 |
Correct |
177 ms |
26308 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
10 ms |
1356 KB |
Output is correct |
13 |
Correct |
173 ms |
26300 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
4 ms |
716 KB |
Output is correct |
17 |
Correct |
108 ms |
12080 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
46 ms |
6832 KB |
Output is correct |
21 |
Correct |
167 ms |
26016 KB |
Output is correct |
22 |
Correct |
170 ms |
26040 KB |
Output is correct |
23 |
Correct |
183 ms |
26040 KB |
Output is correct |
24 |
Correct |
168 ms |
26040 KB |
Output is correct |
25 |
Correct |
77 ms |
12100 KB |
Output is correct |
26 |
Correct |
68 ms |
12088 KB |
Output is correct |
27 |
Correct |
179 ms |
26036 KB |
Output is correct |
28 |
Correct |
172 ms |
26092 KB |
Output is correct |
29 |
Correct |
0 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
0 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
0 ms |
332 KB |
Output is correct |
35 |
Correct |
0 ms |
332 KB |
Output is correct |
36 |
Correct |
7 ms |
1356 KB |
Output is correct |
37 |
Correct |
183 ms |
26084 KB |
Output is correct |
38 |
Correct |
1 ms |
332 KB |
Output is correct |
39 |
Correct |
0 ms |
332 KB |
Output is correct |
40 |
Correct |
7 ms |
1356 KB |
Output is correct |
41 |
Correct |
193 ms |
26040 KB |
Output is correct |
42 |
Correct |
0 ms |
332 KB |
Output is correct |
43 |
Correct |
1 ms |
332 KB |
Output is correct |
44 |
Correct |
4 ms |
716 KB |
Output is correct |
45 |
Correct |
95 ms |
12088 KB |
Output is correct |
46 |
Correct |
1 ms |
332 KB |
Output is correct |
47 |
Correct |
0 ms |
332 KB |
Output is correct |
48 |
Correct |
0 ms |
332 KB |
Output is correct |
49 |
Correct |
44 ms |
6832 KB |
Output is correct |
50 |
Correct |
170 ms |
26068 KB |
Output is correct |
51 |
Correct |
180 ms |
26140 KB |
Output is correct |
52 |
Correct |
186 ms |
25984 KB |
Output is correct |
53 |
Correct |
77 ms |
16308 KB |
Output is correct |
54 |
Correct |
82 ms |
12084 KB |
Output is correct |
55 |
Correct |
170 ms |
26040 KB |
Output is correct |
56 |
Correct |
180 ms |
26108 KB |
Output is correct |
57 |
Correct |
95 ms |
16068 KB |
Output is correct |
58 |
Correct |
0 ms |
332 KB |
Output is correct |
59 |
Correct |
1 ms |
332 KB |
Output is correct |
60 |
Correct |
1 ms |
332 KB |
Output is correct |
61 |
Correct |
51 ms |
6768 KB |
Output is correct |
62 |
Correct |
181 ms |
26008 KB |
Output is correct |
63 |
Correct |
172 ms |
26040 KB |
Output is correct |
64 |
Correct |
176 ms |
26040 KB |
Output is correct |
65 |
Correct |
1 ms |
332 KB |
Output is correct |
66 |
Correct |
44 ms |
6828 KB |
Output is correct |
67 |
Correct |
171 ms |
26064 KB |
Output is correct |
68 |
Correct |
183 ms |
26052 KB |
Output is correct |
69 |
Correct |
182 ms |
26052 KB |
Output is correct |
70 |
Correct |
0 ms |
332 KB |
Output is correct |
71 |
Correct |
0 ms |
332 KB |
Output is correct |
72 |
Correct |
0 ms |
332 KB |
Output is correct |
73 |
Correct |
45 ms |
6808 KB |
Output is correct |
74 |
Correct |
170 ms |
26036 KB |
Output is correct |
75 |
Correct |
175 ms |
26016 KB |
Output is correct |
76 |
Correct |
187 ms |
26028 KB |
Output is correct |
77 |
Correct |
178 ms |
26052 KB |
Output is correct |
78 |
Correct |
1 ms |
332 KB |
Output is correct |
79 |
Correct |
0 ms |
332 KB |
Output is correct |
80 |
Correct |
4 ms |
716 KB |
Output is correct |
81 |
Correct |
85 ms |
12100 KB |
Output is correct |
82 |
Correct |
0 ms |
332 KB |
Output is correct |
83 |
Correct |
0 ms |
332 KB |
Output is correct |
84 |
Correct |
0 ms |
332 KB |
Output is correct |
85 |
Correct |
43 ms |
6800 KB |
Output is correct |
86 |
Correct |
73 ms |
12100 KB |
Output is correct |
87 |
Correct |
70 ms |
12080 KB |
Output is correct |
88 |
Correct |
94 ms |
12088 KB |
Output is correct |
89 |
Correct |
77 ms |
16168 KB |
Output is correct |
90 |
Correct |
0 ms |
332 KB |
Output is correct |
91 |
Correct |
0 ms |
332 KB |
Output is correct |
92 |
Correct |
5 ms |
588 KB |
Output is correct |
93 |
Correct |
78 ms |
8104 KB |
Output is correct |
94 |
Correct |
0 ms |
332 KB |
Output is correct |
95 |
Correct |
1 ms |
332 KB |
Output is correct |
96 |
Correct |
0 ms |
332 KB |
Output is correct |
97 |
Correct |
19 ms |
2724 KB |
Output is correct |
98 |
Correct |
69 ms |
10148 KB |
Output is correct |
99 |
Correct |
74 ms |
10144 KB |
Output is correct |
100 |
Correct |
69 ms |
10156 KB |
Output is correct |
101 |
Correct |
71 ms |
10156 KB |
Output is correct |
102 |
Correct |
69 ms |
10144 KB |
Output is correct |
103 |
Correct |
66 ms |
10068 KB |
Output is correct |
104 |
Correct |
68 ms |
10180 KB |
Output is correct |
105 |
Correct |
92 ms |
10156 KB |
Output is correct |