/*
DavitMarg
In a honky-tonk,
Down in Mexico
*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
#define fastIO ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int N = 1005;
#ifndef death
#include "supertrees.h"
#endif
#ifdef death
void build(vector<vector<int>> b)
{
for (int i = 0; i < b.size(); i++)
{
for (int j = 0; j < b.size(); j++)
cout << b[i][j] << " ";
cout << endl;
}
}
#endif
int parent[N];
void init(int n)
{
for (int i = 0; i < n; i++)
parent[i] = i;
}
int par(int v)
{
if (v == parent[v])
return v;
return parent[v] = par(parent[v]);
}
void dsu(int a, int b)
{
a = par(a);
b = par(b);
if (a == b)
return;
parent[b] = a;
}
int n,z;
vector<vector<int>> ans,p;
void add(int a, int b)
{
ans[a][b] = ans[b][a] = 1;
}
void solve(vector<int> v)
{
init(v.size());
for (int i = 0; i < v.size(); i++)
for (int j = i + 1; j < v.size(); j++)
if (p[v[i]][v[j]] == 1)
dsu(i, j);
for (int i = 0; i < v.size(); i++)
for (int j = i + 1; j < v.size(); j++)
if (p[v[i]][v[j]] == 2 && par(i) == par(j))
{
z = 1;
return;
}
map<int, vector<int>> VS;
vector<int> V;
for (int i = 0; i < v.size(); i++)
VS[v[par(i)]].PB(v[i]);
for (auto it = VS.begin(); it != VS.end(); ++it)
{
for (int i = 0; i < it->second.size() - 1; i++)
add(it->second[i], it->second[i + 1]);
V.push_back(it->first);
}
if (V.size() > 2)
{
for (int i = 0; i < V.size(); i++)
add(V[i], V[(i + 1) % V.size()]);
}
else if (V.size() == 2)
{
z = 1;
}
}
int construct(vector<vector<int>> P)
{
p = P;
n = p.size();
ans.resize(n, vector<int>(n,0));
init(n);
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++)
if (p[i][j])
{
dsu(i, j);
if (p[i][j] == 3)
return 0;
}
map<int, vector<int>> vs;
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
if (p[i][j] == 0 && par(i) == par(j))
return 0;
vs[par(i)].push_back(i);
}
for (auto it = vs.begin(); it != vs.end(); ++it)
solve(it->second);
if (z)
return 0;
build(ans);
return 1;
}
#ifdef death
int main()
{
fastIO;
vector<vector<int>> P;
int nn;
cin >> nn;
for (int i = 0; i < nn; i++)
{
P.push_back(vector<int>());
for (int j = 0; j < nn; j++)
{
int x;
cin >> x;
P[i].push_back(x);
}
}
cout << construct(P) << endl;
return 0;
}
#endif
/*
4
1 1 0 0
1 1 0 0
0 0 1 1
0 0 1 1
*/
Compilation message
supertrees.cpp: In function 'void solve(std::vector<int>)':
supertrees.cpp:86:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
86 | for (int i = 0; i < v.size(); i++)
| ~~^~~~~~~~~~
supertrees.cpp:87:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
87 | for (int j = i + 1; j < v.size(); j++)
| ~~^~~~~~~~~~
supertrees.cpp:91:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
91 | for (int i = 0; i < v.size(); i++)
| ~~^~~~~~~~~~
supertrees.cpp:92:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
92 | for (int j = i + 1; j < v.size(); j++)
| ~~^~~~~~~~~~
supertrees.cpp:100:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
100 | for (int i = 0; i < v.size(); i++)
| ~~^~~~~~~~~~
supertrees.cpp:105:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
105 | for (int i = 0; i < it->second.size() - 1; i++)
| ~~^~~~~~~~~~~~~~~~~~~~~~~
supertrees.cpp:112:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
112 | for (int i = 0; i < V.size(); i++)
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
11 ms |
1408 KB |
Output is correct |
7 |
Correct |
263 ms |
26076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
11 ms |
1408 KB |
Output is correct |
7 |
Correct |
263 ms |
26076 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
11 ms |
1408 KB |
Output is correct |
13 |
Correct |
246 ms |
26180 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
16 |
Correct |
5 ms |
1056 KB |
Output is correct |
17 |
Correct |
120 ms |
16152 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
60 ms |
6776 KB |
Output is correct |
21 |
Correct |
264 ms |
26104 KB |
Output is correct |
22 |
Correct |
254 ms |
26328 KB |
Output is correct |
23 |
Correct |
256 ms |
26104 KB |
Output is correct |
24 |
Correct |
251 ms |
26232 KB |
Output is correct |
25 |
Correct |
105 ms |
16120 KB |
Output is correct |
26 |
Correct |
102 ms |
16120 KB |
Output is correct |
27 |
Correct |
257 ms |
26104 KB |
Output is correct |
28 |
Correct |
247 ms |
26136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
10 ms |
1408 KB |
Output is correct |
9 |
Correct |
239 ms |
26104 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
11 ms |
1408 KB |
Output is correct |
13 |
Correct |
261 ms |
26232 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
16 |
Correct |
5 ms |
896 KB |
Output is correct |
17 |
Correct |
115 ms |
16248 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
256 KB |
Output is correct |
21 |
Correct |
60 ms |
6776 KB |
Output is correct |
22 |
Correct |
244 ms |
26104 KB |
Output is correct |
23 |
Correct |
239 ms |
26104 KB |
Output is correct |
24 |
Correct |
259 ms |
26104 KB |
Output is correct |
25 |
Correct |
106 ms |
16248 KB |
Output is correct |
26 |
Correct |
107 ms |
16120 KB |
Output is correct |
27 |
Correct |
239 ms |
26232 KB |
Output is correct |
28 |
Correct |
264 ms |
26104 KB |
Output is correct |
29 |
Correct |
105 ms |
16248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
63 ms |
6776 KB |
Output is correct |
5 |
Correct |
242 ms |
26232 KB |
Output is correct |
6 |
Correct |
243 ms |
26104 KB |
Output is correct |
7 |
Correct |
257 ms |
26232 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
64 ms |
6776 KB |
Output is correct |
10 |
Correct |
245 ms |
26104 KB |
Output is correct |
11 |
Correct |
239 ms |
26104 KB |
Output is correct |
12 |
Correct |
259 ms |
26104 KB |
Output is correct |
13 |
Correct |
1 ms |
256 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
16 |
Correct |
60 ms |
6992 KB |
Output is correct |
17 |
Correct |
243 ms |
26104 KB |
Output is correct |
18 |
Correct |
252 ms |
26108 KB |
Output is correct |
19 |
Correct |
249 ms |
26148 KB |
Output is correct |
20 |
Correct |
244 ms |
26104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
11 ms |
1408 KB |
Output is correct |
7 |
Correct |
263 ms |
26076 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
11 ms |
1408 KB |
Output is correct |
13 |
Correct |
246 ms |
26180 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
16 |
Correct |
5 ms |
1056 KB |
Output is correct |
17 |
Correct |
120 ms |
16152 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
60 ms |
6776 KB |
Output is correct |
21 |
Correct |
264 ms |
26104 KB |
Output is correct |
22 |
Correct |
254 ms |
26328 KB |
Output is correct |
23 |
Correct |
256 ms |
26104 KB |
Output is correct |
24 |
Correct |
251 ms |
26232 KB |
Output is correct |
25 |
Correct |
105 ms |
16120 KB |
Output is correct |
26 |
Correct |
102 ms |
16120 KB |
Output is correct |
27 |
Correct |
257 ms |
26104 KB |
Output is correct |
28 |
Correct |
247 ms |
26136 KB |
Output is correct |
29 |
Correct |
1 ms |
256 KB |
Output is correct |
30 |
Correct |
1 ms |
256 KB |
Output is correct |
31 |
Correct |
1 ms |
256 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
1 ms |
256 KB |
Output is correct |
34 |
Correct |
1 ms |
256 KB |
Output is correct |
35 |
Correct |
1 ms |
256 KB |
Output is correct |
36 |
Correct |
10 ms |
1408 KB |
Output is correct |
37 |
Correct |
239 ms |
26104 KB |
Output is correct |
38 |
Correct |
1 ms |
384 KB |
Output is correct |
39 |
Correct |
1 ms |
256 KB |
Output is correct |
40 |
Correct |
11 ms |
1408 KB |
Output is correct |
41 |
Correct |
261 ms |
26232 KB |
Output is correct |
42 |
Correct |
1 ms |
256 KB |
Output is correct |
43 |
Correct |
1 ms |
256 KB |
Output is correct |
44 |
Correct |
5 ms |
896 KB |
Output is correct |
45 |
Correct |
115 ms |
16248 KB |
Output is correct |
46 |
Correct |
1 ms |
256 KB |
Output is correct |
47 |
Correct |
1 ms |
384 KB |
Output is correct |
48 |
Correct |
1 ms |
256 KB |
Output is correct |
49 |
Correct |
60 ms |
6776 KB |
Output is correct |
50 |
Correct |
244 ms |
26104 KB |
Output is correct |
51 |
Correct |
239 ms |
26104 KB |
Output is correct |
52 |
Correct |
259 ms |
26104 KB |
Output is correct |
53 |
Correct |
106 ms |
16248 KB |
Output is correct |
54 |
Correct |
107 ms |
16120 KB |
Output is correct |
55 |
Correct |
239 ms |
26232 KB |
Output is correct |
56 |
Correct |
264 ms |
26104 KB |
Output is correct |
57 |
Correct |
105 ms |
16248 KB |
Output is correct |
58 |
Correct |
1 ms |
256 KB |
Output is correct |
59 |
Correct |
1 ms |
256 KB |
Output is correct |
60 |
Correct |
5 ms |
1152 KB |
Output is correct |
61 |
Correct |
116 ms |
16120 KB |
Output is correct |
62 |
Correct |
1 ms |
256 KB |
Output is correct |
63 |
Correct |
1 ms |
256 KB |
Output is correct |
64 |
Correct |
1 ms |
256 KB |
Output is correct |
65 |
Correct |
60 ms |
6776 KB |
Output is correct |
66 |
Correct |
103 ms |
16120 KB |
Output is correct |
67 |
Correct |
105 ms |
16120 KB |
Output is correct |
68 |
Correct |
109 ms |
16120 KB |
Output is correct |
69 |
Correct |
103 ms |
16248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
11 ms |
1408 KB |
Output is correct |
7 |
Correct |
263 ms |
26076 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
11 ms |
1408 KB |
Output is correct |
13 |
Correct |
246 ms |
26180 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
16 |
Correct |
5 ms |
1056 KB |
Output is correct |
17 |
Correct |
120 ms |
16152 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
60 ms |
6776 KB |
Output is correct |
21 |
Correct |
264 ms |
26104 KB |
Output is correct |
22 |
Correct |
254 ms |
26328 KB |
Output is correct |
23 |
Correct |
256 ms |
26104 KB |
Output is correct |
24 |
Correct |
251 ms |
26232 KB |
Output is correct |
25 |
Correct |
105 ms |
16120 KB |
Output is correct |
26 |
Correct |
102 ms |
16120 KB |
Output is correct |
27 |
Correct |
257 ms |
26104 KB |
Output is correct |
28 |
Correct |
247 ms |
26136 KB |
Output is correct |
29 |
Correct |
1 ms |
256 KB |
Output is correct |
30 |
Correct |
1 ms |
256 KB |
Output is correct |
31 |
Correct |
1 ms |
256 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
1 ms |
256 KB |
Output is correct |
34 |
Correct |
1 ms |
256 KB |
Output is correct |
35 |
Correct |
1 ms |
256 KB |
Output is correct |
36 |
Correct |
10 ms |
1408 KB |
Output is correct |
37 |
Correct |
239 ms |
26104 KB |
Output is correct |
38 |
Correct |
1 ms |
384 KB |
Output is correct |
39 |
Correct |
1 ms |
256 KB |
Output is correct |
40 |
Correct |
11 ms |
1408 KB |
Output is correct |
41 |
Correct |
261 ms |
26232 KB |
Output is correct |
42 |
Correct |
1 ms |
256 KB |
Output is correct |
43 |
Correct |
1 ms |
256 KB |
Output is correct |
44 |
Correct |
5 ms |
896 KB |
Output is correct |
45 |
Correct |
115 ms |
16248 KB |
Output is correct |
46 |
Correct |
1 ms |
256 KB |
Output is correct |
47 |
Correct |
1 ms |
384 KB |
Output is correct |
48 |
Correct |
1 ms |
256 KB |
Output is correct |
49 |
Correct |
60 ms |
6776 KB |
Output is correct |
50 |
Correct |
244 ms |
26104 KB |
Output is correct |
51 |
Correct |
239 ms |
26104 KB |
Output is correct |
52 |
Correct |
259 ms |
26104 KB |
Output is correct |
53 |
Correct |
106 ms |
16248 KB |
Output is correct |
54 |
Correct |
107 ms |
16120 KB |
Output is correct |
55 |
Correct |
239 ms |
26232 KB |
Output is correct |
56 |
Correct |
264 ms |
26104 KB |
Output is correct |
57 |
Correct |
105 ms |
16248 KB |
Output is correct |
58 |
Correct |
1 ms |
256 KB |
Output is correct |
59 |
Correct |
1 ms |
256 KB |
Output is correct |
60 |
Correct |
1 ms |
256 KB |
Output is correct |
61 |
Correct |
63 ms |
6776 KB |
Output is correct |
62 |
Correct |
242 ms |
26232 KB |
Output is correct |
63 |
Correct |
243 ms |
26104 KB |
Output is correct |
64 |
Correct |
257 ms |
26232 KB |
Output is correct |
65 |
Correct |
1 ms |
256 KB |
Output is correct |
66 |
Correct |
64 ms |
6776 KB |
Output is correct |
67 |
Correct |
245 ms |
26104 KB |
Output is correct |
68 |
Correct |
239 ms |
26104 KB |
Output is correct |
69 |
Correct |
259 ms |
26104 KB |
Output is correct |
70 |
Correct |
1 ms |
256 KB |
Output is correct |
71 |
Correct |
1 ms |
256 KB |
Output is correct |
72 |
Correct |
1 ms |
256 KB |
Output is correct |
73 |
Correct |
60 ms |
6992 KB |
Output is correct |
74 |
Correct |
243 ms |
26104 KB |
Output is correct |
75 |
Correct |
252 ms |
26108 KB |
Output is correct |
76 |
Correct |
249 ms |
26148 KB |
Output is correct |
77 |
Correct |
244 ms |
26104 KB |
Output is correct |
78 |
Correct |
1 ms |
256 KB |
Output is correct |
79 |
Correct |
1 ms |
256 KB |
Output is correct |
80 |
Correct |
5 ms |
1152 KB |
Output is correct |
81 |
Correct |
116 ms |
16120 KB |
Output is correct |
82 |
Correct |
1 ms |
256 KB |
Output is correct |
83 |
Correct |
1 ms |
256 KB |
Output is correct |
84 |
Correct |
1 ms |
256 KB |
Output is correct |
85 |
Correct |
60 ms |
6776 KB |
Output is correct |
86 |
Correct |
103 ms |
16120 KB |
Output is correct |
87 |
Correct |
105 ms |
16120 KB |
Output is correct |
88 |
Correct |
109 ms |
16120 KB |
Output is correct |
89 |
Correct |
103 ms |
16248 KB |
Output is correct |
90 |
Correct |
1 ms |
256 KB |
Output is correct |
91 |
Correct |
1 ms |
256 KB |
Output is correct |
92 |
Correct |
5 ms |
1024 KB |
Output is correct |
93 |
Correct |
119 ms |
16120 KB |
Output is correct |
94 |
Correct |
1 ms |
256 KB |
Output is correct |
95 |
Correct |
1 ms |
384 KB |
Output is correct |
96 |
Correct |
1 ms |
256 KB |
Output is correct |
97 |
Correct |
26 ms |
4352 KB |
Output is correct |
98 |
Correct |
106 ms |
16120 KB |
Output is correct |
99 |
Correct |
105 ms |
16120 KB |
Output is correct |
100 |
Correct |
104 ms |
16120 KB |
Output is correct |
101 |
Correct |
107 ms |
16120 KB |
Output is correct |
102 |
Correct |
115 ms |
16120 KB |
Output is correct |
103 |
Correct |
110 ms |
16120 KB |
Output is correct |
104 |
Correct |
113 ms |
16248 KB |
Output is correct |
105 |
Correct |
110 ms |
16120 KB |
Output is correct |