#include "bits/stdc++.h"
using namespace std;
#define endl "\n"
#define ll long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
const long long MOD = 1e9+7;
const long long INF = 1e18;
int nx[4] = {0, 0, -1, 1};
int ny[4] = {1, -1, 0, 0};
void build(vector<vector<int>> b);
struct dsu
{
vector<int> len;
vector<int> link;
void init(int n)
{
len.assign(n, 1);
link.assign(n, 0);
for(int i = 0; i<n; i++)
{
link[i] = i;
}
}
int search(int x)
{
if(x!=link[x])
link[x] = search(link[x]);
return link[x];
}
bool check(int a, int b)
{
return search(a)==search(b);
}
void join(int a, int b)
{
a = search(a);
b = search(b);
if(a!=b)
{
if(len[a]<len[b])
swap(a, b);
len[a]+=len[b];
link[b] = a;
}
}
};
int construct(vector<vector<int>> p)
{
int n = int(p[0].size());
vector<vector<int>> b(n, vector<int>(n, 0));
dsu d;
d.init(n);
bool flag = false;
for(int i = 0; i<n; i++)
{
for(int j = i+1; j<n; j++)
{
if(p[i][j]==1)
d.join(i, j);
if(p[i][j]==2)
{
d.join(i, j);
flag = true;
}
}
}
vector<vector<int>> groups(n);
for(int i = 0; i<n; i++)
{
int parent = d.search(i);
groups[parent].pb(i);
}
/*for(int i = 0; i<n; i++)
{
cout << i << ": ";
for(auto elt: groups[i])
cout << elt << ' ';
cout << endl;
}*/
if(!flag)
{
for(int i = 0; i<n; i++)
{
if(groups[i].empty())
continue;
int len = int(groups[i].size());
for(int j = 0; j<len-1; j++)
{
int A = groups[i][j];
int B = groups[i][j+1];
b[A][B] = 1;
b[B][A] = 1;
}
}
}
else
{
for(int i = 0; i<n; i++)
{
if(groups[i].empty())
continue;
if(int(groups[i].size())==2)
return 0;
int len = int(groups[i].size());
for(int j = 0; j<len-1; j++)
{
int A = groups[i][j];
int B = groups[i][j+1];
b[A][B] = 1;
b[B][A] = 1;
}
int A = groups[i][len-1];
int B = groups[i][0];
b[A][B] = 1;
b[B][A] = 1;
}
}
for(int i = 0; i<n; i++)
{
for(int j = i+1; j<n; j++)
{
if(p[i][j]==0&&d.check(i, j))
return 0;
if(!d.check(i, j)&&p[i][j]!=0)
return 0;
}
}
for(int i = 0; i<n; i++)
{
b[i][i] = 0;
}
build(b);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 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 |
8 ms |
1100 KB |
Output is correct |
7 |
Correct |
176 ms |
22016 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 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 |
8 ms |
1100 KB |
Output is correct |
7 |
Correct |
176 ms |
22016 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
7 ms |
1156 KB |
Output is correct |
13 |
Correct |
160 ms |
22084 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
3 ms |
716 KB |
Output is correct |
17 |
Correct |
78 ms |
12040 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
45 ms |
5760 KB |
Output is correct |
21 |
Correct |
196 ms |
22016 KB |
Output is correct |
22 |
Correct |
169 ms |
22060 KB |
Output is correct |
23 |
Correct |
187 ms |
22020 KB |
Output is correct |
24 |
Correct |
180 ms |
22140 KB |
Output is correct |
25 |
Correct |
66 ms |
12164 KB |
Output is correct |
26 |
Correct |
65 ms |
12156 KB |
Output is correct |
27 |
Correct |
207 ms |
22012 KB |
Output is correct |
28 |
Correct |
165 ms |
22084 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
7 ms |
1100 KB |
Output is correct |
9 |
Correct |
170 ms |
22024 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
8 ms |
1100 KB |
Output is correct |
13 |
Correct |
167 ms |
22012 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
4 ms |
716 KB |
Output is correct |
17 |
Correct |
77 ms |
12044 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
45 ms |
6184 KB |
Output is correct |
22 |
Correct |
168 ms |
24048 KB |
Output is correct |
23 |
Correct |
218 ms |
24044 KB |
Output is correct |
24 |
Correct |
185 ms |
24048 KB |
Output is correct |
25 |
Correct |
64 ms |
14072 KB |
Output is correct |
26 |
Correct |
67 ms |
14064 KB |
Output is correct |
27 |
Correct |
167 ms |
23976 KB |
Output is correct |
28 |
Correct |
180 ms |
23920 KB |
Output is correct |
29 |
Correct |
65 ms |
14076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
45 ms |
5744 KB |
Output is correct |
5 |
Correct |
183 ms |
21984 KB |
Output is correct |
6 |
Correct |
177 ms |
22024 KB |
Output is correct |
7 |
Correct |
188 ms |
22008 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
61 ms |
6164 KB |
Output is correct |
10 |
Correct |
205 ms |
23928 KB |
Output is correct |
11 |
Correct |
171 ms |
23928 KB |
Output is correct |
12 |
Correct |
174 ms |
24016 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Incorrect |
0 ms |
204 KB |
Too many ways to get from 4 to 8, should be 1 found no less than 2 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 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 |
8 ms |
1100 KB |
Output is correct |
7 |
Correct |
176 ms |
22016 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
7 ms |
1156 KB |
Output is correct |
13 |
Correct |
160 ms |
22084 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
3 ms |
716 KB |
Output is correct |
17 |
Correct |
78 ms |
12040 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
45 ms |
5760 KB |
Output is correct |
21 |
Correct |
196 ms |
22016 KB |
Output is correct |
22 |
Correct |
169 ms |
22060 KB |
Output is correct |
23 |
Correct |
187 ms |
22020 KB |
Output is correct |
24 |
Correct |
180 ms |
22140 KB |
Output is correct |
25 |
Correct |
66 ms |
12164 KB |
Output is correct |
26 |
Correct |
65 ms |
12156 KB |
Output is correct |
27 |
Correct |
207 ms |
22012 KB |
Output is correct |
28 |
Correct |
165 ms |
22084 KB |
Output is correct |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
0 ms |
204 KB |
Output is correct |
31 |
Correct |
0 ms |
204 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
1 ms |
204 KB |
Output is correct |
36 |
Correct |
7 ms |
1100 KB |
Output is correct |
37 |
Correct |
170 ms |
22024 KB |
Output is correct |
38 |
Correct |
0 ms |
204 KB |
Output is correct |
39 |
Correct |
0 ms |
204 KB |
Output is correct |
40 |
Correct |
8 ms |
1100 KB |
Output is correct |
41 |
Correct |
167 ms |
22012 KB |
Output is correct |
42 |
Correct |
0 ms |
204 KB |
Output is correct |
43 |
Correct |
0 ms |
204 KB |
Output is correct |
44 |
Correct |
4 ms |
716 KB |
Output is correct |
45 |
Correct |
77 ms |
12044 KB |
Output is correct |
46 |
Correct |
0 ms |
204 KB |
Output is correct |
47 |
Correct |
0 ms |
204 KB |
Output is correct |
48 |
Correct |
1 ms |
204 KB |
Output is correct |
49 |
Correct |
45 ms |
6184 KB |
Output is correct |
50 |
Correct |
168 ms |
24048 KB |
Output is correct |
51 |
Correct |
218 ms |
24044 KB |
Output is correct |
52 |
Correct |
185 ms |
24048 KB |
Output is correct |
53 |
Correct |
64 ms |
14072 KB |
Output is correct |
54 |
Correct |
67 ms |
14064 KB |
Output is correct |
55 |
Correct |
167 ms |
23976 KB |
Output is correct |
56 |
Correct |
180 ms |
23920 KB |
Output is correct |
57 |
Correct |
65 ms |
14076 KB |
Output is correct |
58 |
Correct |
0 ms |
204 KB |
Output is correct |
59 |
Correct |
0 ms |
204 KB |
Output is correct |
60 |
Correct |
4 ms |
844 KB |
Output is correct |
61 |
Correct |
76 ms |
14092 KB |
Output is correct |
62 |
Correct |
1 ms |
204 KB |
Output is correct |
63 |
Incorrect |
0 ms |
204 KB |
Too many ways to get from 0 to 9, should be 1 found no less than 2 |
64 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 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 |
8 ms |
1100 KB |
Output is correct |
7 |
Correct |
176 ms |
22016 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
7 ms |
1156 KB |
Output is correct |
13 |
Correct |
160 ms |
22084 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
3 ms |
716 KB |
Output is correct |
17 |
Correct |
78 ms |
12040 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
45 ms |
5760 KB |
Output is correct |
21 |
Correct |
196 ms |
22016 KB |
Output is correct |
22 |
Correct |
169 ms |
22060 KB |
Output is correct |
23 |
Correct |
187 ms |
22020 KB |
Output is correct |
24 |
Correct |
180 ms |
22140 KB |
Output is correct |
25 |
Correct |
66 ms |
12164 KB |
Output is correct |
26 |
Correct |
65 ms |
12156 KB |
Output is correct |
27 |
Correct |
207 ms |
22012 KB |
Output is correct |
28 |
Correct |
165 ms |
22084 KB |
Output is correct |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
0 ms |
204 KB |
Output is correct |
31 |
Correct |
0 ms |
204 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
1 ms |
204 KB |
Output is correct |
36 |
Correct |
7 ms |
1100 KB |
Output is correct |
37 |
Correct |
170 ms |
22024 KB |
Output is correct |
38 |
Correct |
0 ms |
204 KB |
Output is correct |
39 |
Correct |
0 ms |
204 KB |
Output is correct |
40 |
Correct |
8 ms |
1100 KB |
Output is correct |
41 |
Correct |
167 ms |
22012 KB |
Output is correct |
42 |
Correct |
0 ms |
204 KB |
Output is correct |
43 |
Correct |
0 ms |
204 KB |
Output is correct |
44 |
Correct |
4 ms |
716 KB |
Output is correct |
45 |
Correct |
77 ms |
12044 KB |
Output is correct |
46 |
Correct |
0 ms |
204 KB |
Output is correct |
47 |
Correct |
0 ms |
204 KB |
Output is correct |
48 |
Correct |
1 ms |
204 KB |
Output is correct |
49 |
Correct |
45 ms |
6184 KB |
Output is correct |
50 |
Correct |
168 ms |
24048 KB |
Output is correct |
51 |
Correct |
218 ms |
24044 KB |
Output is correct |
52 |
Correct |
185 ms |
24048 KB |
Output is correct |
53 |
Correct |
64 ms |
14072 KB |
Output is correct |
54 |
Correct |
67 ms |
14064 KB |
Output is correct |
55 |
Correct |
167 ms |
23976 KB |
Output is correct |
56 |
Correct |
180 ms |
23920 KB |
Output is correct |
57 |
Correct |
65 ms |
14076 KB |
Output is correct |
58 |
Correct |
1 ms |
204 KB |
Output is correct |
59 |
Correct |
0 ms |
204 KB |
Output is correct |
60 |
Correct |
0 ms |
204 KB |
Output is correct |
61 |
Correct |
45 ms |
5744 KB |
Output is correct |
62 |
Correct |
183 ms |
21984 KB |
Output is correct |
63 |
Correct |
177 ms |
22024 KB |
Output is correct |
64 |
Correct |
188 ms |
22008 KB |
Output is correct |
65 |
Correct |
0 ms |
204 KB |
Output is correct |
66 |
Correct |
61 ms |
6164 KB |
Output is correct |
67 |
Correct |
205 ms |
23928 KB |
Output is correct |
68 |
Correct |
171 ms |
23928 KB |
Output is correct |
69 |
Correct |
174 ms |
24016 KB |
Output is correct |
70 |
Correct |
0 ms |
204 KB |
Output is correct |
71 |
Incorrect |
0 ms |
204 KB |
Too many ways to get from 4 to 8, should be 1 found no less than 2 |
72 |
Halted |
0 ms |
0 KB |
- |