#include "supertrees.h"
#include <algorithm>
#include <string.h>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
#include <map>
using namespace std;
#define N 1010
#define ff first
#define ss second
#define ll long long
#define pb push_back
#define mod 1000000007
#define pii pair <int, int>
#define sz(a) int(a.size())
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
ll bigmod(ll a,ll e) {if(e==0)return 1;ll x=bigmod(a*a%mod,e>>1);return e&1?x*a%mod:x;}
int n;
int vis[N];
int vis2[N];
int vis3[N];
int arr[N][N];
int pat[N][N];
vector <int> E;
int P[N], sz[N];
int ata(int x)
{
if(x == P[x]) return x;
return P[x] = ata(P[x]);
}
void uni(int a, int b)
{
a = ata(a);
b = ata(b);
if(a == b) return;
if(sz[a] < sz[b]) swap(a, b);
P[b] = a, sz[a] += sz[b], sz[b] = 0;
arr[a][b] = arr[b][a] = 1;
}
void dfs(int nd)
{
E.pb(nd);
vis[nd] = 1;
for(int i = 0; i < n; i++) if(i != nd) vis2[i] = (pat[nd][i] != 2 ? 0 : vis2[i]);
for(int i = 0; i < n; i++)
if(pat[nd][i] == 2 && !vis[i] && vis2[i]) {
dfs(i);
return;
}
}
int construct(vector<vector<int>> p) {
n = p.size();
for(int i = 0; i < n; i++) P[i] = i, sz[i] = 1;
for(int i = 0; i < n; i++)
for(int h = 0; h < n; h++) {
pat[i][h] = p[i][h];
if(p[i][h] == 3) return 0;
}
for(int i = 0; i < n; i++) {
if(vis[i]) continue;
E.clear();
memset(vis2, 0, sizeof(vis2));
for(int h = 0; h < n; h++) vis2[h] = (p[i][h] == 2 ? 1 : 0);
dfs(i);
if(E.size() == 2) return 0;
int last = -1;
for(auto h: E) {
if(last != -1) arr[last][h] = arr[h][last] = 1;
last = h;
for(int j = 0; j < n; j++)
if(p[h][j] == 1 && h != j) {
if(vis[j] == 1) return 0;
vis[j] = 1;
uni(h, j);
}
}
if(E.size() == 1) {
int ok = 0, ok2 = 1;
for(int h = 0; h < n; h++) {
if(p[i][h] == 2) ok = 1;
if(i != h && p[i][h] == 1) ok2 = 0;
}
if(ok == 1 && ok2 == 1) return 0;
continue;
}
arr[E[0]][last] = arr[last][E[0]] = 1;
}
for(int i = 0; i < n; i++)
for(int h = 0; h < n; h++)
if(!p[i][h] && ata(i) == ata(h)) return 0;
vector <vector <int>> ret;
ret.resize(n);
for(int i = 0; i < n; i++)
for(int h = 0; h < n; h++)
ret[i].pb(arr[i][h]);
build(ret);
return 1;
}
Compilation message
supertrees.cpp:23: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
23 | #pragma GCC optimization ("O3")
|
supertrees.cpp:24: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
24 | #pragma GCC optimization ("unroll-loops")
|
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
12 ms |
2816 KB |
Output is correct |
7 |
Correct |
260 ms |
30072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
12 ms |
2816 KB |
Output is correct |
7 |
Correct |
260 ms |
30072 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
11 ms |
2048 KB |
Output is correct |
13 |
Correct |
248 ms |
26232 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
1792 KB |
Output is correct |
17 |
Correct |
107 ms |
14200 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
65 ms |
9592 KB |
Output is correct |
21 |
Correct |
252 ms |
30072 KB |
Output is correct |
22 |
Correct |
253 ms |
29688 KB |
Output is correct |
23 |
Correct |
268 ms |
30200 KB |
Output is correct |
24 |
Correct |
252 ms |
26360 KB |
Output is correct |
25 |
Incorrect |
254 ms |
30072 KB |
Answer gives possible 1 while actual possible 0 |
26 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
11 ms |
2048 KB |
Output is correct |
9 |
Correct |
247 ms |
26108 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
12 ms |
2816 KB |
Output is correct |
13 |
Correct |
267 ms |
30172 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
7 ms |
2176 KB |
Output is correct |
17 |
Correct |
124 ms |
15992 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
66 ms |
9720 KB |
Output is correct |
22 |
Correct |
250 ms |
30072 KB |
Output is correct |
23 |
Correct |
248 ms |
30072 KB |
Output is correct |
24 |
Correct |
265 ms |
30200 KB |
Output is correct |
25 |
Correct |
96 ms |
12512 KB |
Output is correct |
26 |
Incorrect |
274 ms |
30172 KB |
Answer gives possible 1 while actual possible 0 |
27 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
64 ms |
9592 KB |
Output is correct |
5 |
Correct |
255 ms |
30072 KB |
Output is correct |
6 |
Correct |
264 ms |
29604 KB |
Output is correct |
7 |
Correct |
271 ms |
30072 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
66 ms |
9648 KB |
Output is correct |
10 |
Correct |
260 ms |
30072 KB |
Output is correct |
11 |
Correct |
250 ms |
30032 KB |
Output is correct |
12 |
Correct |
280 ms |
30072 KB |
Output is correct |
13 |
Correct |
1 ms |
416 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
65 ms |
9720 KB |
Output is correct |
17 |
Correct |
256 ms |
30200 KB |
Output is correct |
18 |
Correct |
322 ms |
29832 KB |
Output is correct |
19 |
Correct |
258 ms |
29816 KB |
Output is correct |
20 |
Correct |
256 ms |
26360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
12 ms |
2816 KB |
Output is correct |
7 |
Correct |
260 ms |
30072 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
11 ms |
2048 KB |
Output is correct |
13 |
Correct |
248 ms |
26232 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
1792 KB |
Output is correct |
17 |
Correct |
107 ms |
14200 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
65 ms |
9592 KB |
Output is correct |
21 |
Correct |
252 ms |
30072 KB |
Output is correct |
22 |
Correct |
253 ms |
29688 KB |
Output is correct |
23 |
Correct |
268 ms |
30200 KB |
Output is correct |
24 |
Correct |
252 ms |
26360 KB |
Output is correct |
25 |
Incorrect |
254 ms |
30072 KB |
Answer gives possible 1 while actual possible 0 |
26 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
12 ms |
2816 KB |
Output is correct |
7 |
Correct |
260 ms |
30072 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
11 ms |
2048 KB |
Output is correct |
13 |
Correct |
248 ms |
26232 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
1792 KB |
Output is correct |
17 |
Correct |
107 ms |
14200 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
65 ms |
9592 KB |
Output is correct |
21 |
Correct |
252 ms |
30072 KB |
Output is correct |
22 |
Correct |
253 ms |
29688 KB |
Output is correct |
23 |
Correct |
268 ms |
30200 KB |
Output is correct |
24 |
Correct |
252 ms |
26360 KB |
Output is correct |
25 |
Incorrect |
254 ms |
30072 KB |
Answer gives possible 1 while actual possible 0 |
26 |
Halted |
0 ms |
0 KB |
- |