Submission #301989

# Submission time Handle Problem Language Result Execution time Memory
301989 2020-09-18T10:56:54 Z Trickster Connecting Supertrees (IOI20_supertrees) C++14
100 / 100
282 ms 30328 KB
#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 P[N];
int n, ans;
int arr[N][N];
int pat[N][N];
vector <int> E;
int vis[N], vis2[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;

	P[b] = a;
	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) {
		if(pat[nd][i] == 1) vis2[i] = (vis2[i] == 1 ? 2 : vis2[i]);
		if(pat[nd][i] == 0) vis2[i] = 0;
	}

	for(int i = 0; i < n; i++)
		if(pat[nd][i] == 2 && !vis[i]) {
			if(vis2[i] != 1) {
				if(vis2[i] == 2) continue;
				
				ans = 1;
				return;
			}
			dfs(i);
			return;
		}
}
void upd(int nd)
{
	vis[nd] = 1;

	for(int i = 0; i < n; i++) {
		if(ata(i) == ata(nd)) continue;

		if(pat[nd][i] == 1) {
			if(vis[i] == 1) {
				ans = 1;
				return;
			}
			uni(nd, i);
			upd(i);
		}
	}
}

int construct(vector<vector<int>> p) {
	n = p.size();

	for(int i = 0; i < n; i++) P[i] = i;

	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++) {
			if(i == h) continue;
			if(p[i][h] == 1) vis2[h] = 2;
			if(p[i][h] == 2) vis2[h] = 1;
		}

		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;

			upd(h);
			last = h;
		}
		if(E.size() == 1) continue;

		arr[E[0]][last] = arr[last][E[0]] = 1;
	}
	if(ans == 1) return 0;

	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")
      |
# Verdict Execution time Memory 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 12 ms 2816 KB Output is correct
7 Correct 255 ms 30072 KB Output is correct
# Verdict Execution time Memory 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 12 ms 2816 KB Output is correct
7 Correct 255 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 512 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 11 ms 2048 KB Output is correct
13 Correct 253 ms 26196 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 6 ms 2272 KB Output is correct
17 Correct 115 ms 16120 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 69 ms 9592 KB Output is correct
21 Correct 255 ms 30072 KB Output is correct
22 Correct 255 ms 29560 KB Output is correct
23 Correct 273 ms 30176 KB Output is correct
24 Correct 252 ms 26336 KB Output is correct
25 Correct 109 ms 16096 KB Output is correct
26 Correct 108 ms 15608 KB Output is correct
27 Correct 270 ms 30072 KB Output is correct
28 Correct 268 ms 26360 KB Output is correct
# Verdict Execution time Memory 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 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 11 ms 2048 KB Output is correct
9 Correct 282 ms 26204 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 15 ms 2816 KB Output is correct
13 Correct 254 ms 30200 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 1408 KB Output is correct
17 Correct 108 ms 12152 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 63 ms 9720 KB Output is correct
22 Correct 249 ms 30072 KB Output is correct
23 Correct 247 ms 30072 KB Output is correct
24 Correct 273 ms 30072 KB Output is correct
25 Correct 96 ms 12412 KB Output is correct
26 Correct 104 ms 16120 KB Output is correct
27 Correct 252 ms 30072 KB Output is correct
28 Correct 267 ms 30328 KB Output is correct
29 Correct 100 ms 12408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 288 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 66 ms 9592 KB Output is correct
5 Correct 272 ms 30072 KB Output is correct
6 Correct 254 ms 29536 KB Output is correct
7 Correct 273 ms 30172 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 68 ms 9720 KB Output is correct
10 Correct 256 ms 30072 KB Output is correct
11 Correct 247 ms 30072 KB Output is correct
12 Correct 272 ms 30072 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 64 ms 9720 KB Output is correct
17 Correct 248 ms 30200 KB Output is correct
18 Correct 260 ms 29816 KB Output is correct
19 Correct 252 ms 29688 KB Output is correct
20 Correct 246 ms 26364 KB Output is correct
# Verdict Execution time Memory 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 12 ms 2816 KB Output is correct
7 Correct 255 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 512 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 11 ms 2048 KB Output is correct
13 Correct 253 ms 26196 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 6 ms 2272 KB Output is correct
17 Correct 115 ms 16120 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 69 ms 9592 KB Output is correct
21 Correct 255 ms 30072 KB Output is correct
22 Correct 255 ms 29560 KB Output is correct
23 Correct 273 ms 30176 KB Output is correct
24 Correct 252 ms 26336 KB Output is correct
25 Correct 109 ms 16096 KB Output is correct
26 Correct 108 ms 15608 KB Output is correct
27 Correct 270 ms 30072 KB Output is correct
28 Correct 268 ms 26360 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 0 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 512 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 11 ms 2048 KB Output is correct
37 Correct 282 ms 26204 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 15 ms 2816 KB Output is correct
41 Correct 254 ms 30200 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 5 ms 1408 KB Output is correct
45 Correct 108 ms 12152 KB Output is correct
46 Correct 1 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 63 ms 9720 KB Output is correct
50 Correct 249 ms 30072 KB Output is correct
51 Correct 247 ms 30072 KB Output is correct
52 Correct 273 ms 30072 KB Output is correct
53 Correct 96 ms 12412 KB Output is correct
54 Correct 104 ms 16120 KB Output is correct
55 Correct 252 ms 30072 KB Output is correct
56 Correct 267 ms 30328 KB Output is correct
57 Correct 100 ms 12408 KB Output is correct
58 Correct 1 ms 384 KB Output is correct
59 Correct 1 ms 384 KB Output is correct
60 Correct 6 ms 2304 KB Output is correct
61 Correct 108 ms 12152 KB Output is correct
62 Correct 1 ms 384 KB Output is correct
63 Correct 1 ms 384 KB Output is correct
64 Correct 1 ms 384 KB Output is correct
65 Correct 80 ms 9720 KB Output is correct
66 Correct 108 ms 16124 KB Output is correct
67 Correct 112 ms 15864 KB Output is correct
68 Correct 103 ms 15768 KB Output is correct
69 Correct 94 ms 12280 KB Output is correct
# Verdict Execution time Memory 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 12 ms 2816 KB Output is correct
7 Correct 255 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 512 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 11 ms 2048 KB Output is correct
13 Correct 253 ms 26196 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 6 ms 2272 KB Output is correct
17 Correct 115 ms 16120 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 69 ms 9592 KB Output is correct
21 Correct 255 ms 30072 KB Output is correct
22 Correct 255 ms 29560 KB Output is correct
23 Correct 273 ms 30176 KB Output is correct
24 Correct 252 ms 26336 KB Output is correct
25 Correct 109 ms 16096 KB Output is correct
26 Correct 108 ms 15608 KB Output is correct
27 Correct 270 ms 30072 KB Output is correct
28 Correct 268 ms 26360 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 0 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 512 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 11 ms 2048 KB Output is correct
37 Correct 282 ms 26204 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 15 ms 2816 KB Output is correct
41 Correct 254 ms 30200 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 5 ms 1408 KB Output is correct
45 Correct 108 ms 12152 KB Output is correct
46 Correct 1 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 63 ms 9720 KB Output is correct
50 Correct 249 ms 30072 KB Output is correct
51 Correct 247 ms 30072 KB Output is correct
52 Correct 273 ms 30072 KB Output is correct
53 Correct 96 ms 12412 KB Output is correct
54 Correct 104 ms 16120 KB Output is correct
55 Correct 252 ms 30072 KB Output is correct
56 Correct 267 ms 30328 KB Output is correct
57 Correct 100 ms 12408 KB Output is correct
58 Correct 1 ms 384 KB Output is correct
59 Correct 1 ms 288 KB Output is correct
60 Correct 1 ms 384 KB Output is correct
61 Correct 66 ms 9592 KB Output is correct
62 Correct 272 ms 30072 KB Output is correct
63 Correct 254 ms 29536 KB Output is correct
64 Correct 273 ms 30172 KB Output is correct
65 Correct 1 ms 384 KB Output is correct
66 Correct 68 ms 9720 KB Output is correct
67 Correct 256 ms 30072 KB Output is correct
68 Correct 247 ms 30072 KB Output is correct
69 Correct 272 ms 30072 KB Output is correct
70 Correct 1 ms 384 KB Output is correct
71 Correct 1 ms 384 KB Output is correct
72 Correct 1 ms 512 KB Output is correct
73 Correct 64 ms 9720 KB Output is correct
74 Correct 248 ms 30200 KB Output is correct
75 Correct 260 ms 29816 KB Output is correct
76 Correct 252 ms 29688 KB Output is correct
77 Correct 246 ms 26364 KB Output is correct
78 Correct 1 ms 384 KB Output is correct
79 Correct 1 ms 384 KB Output is correct
80 Correct 6 ms 2304 KB Output is correct
81 Correct 108 ms 12152 KB Output is correct
82 Correct 1 ms 384 KB Output is correct
83 Correct 1 ms 384 KB Output is correct
84 Correct 1 ms 384 KB Output is correct
85 Correct 80 ms 9720 KB Output is correct
86 Correct 108 ms 16124 KB Output is correct
87 Correct 112 ms 15864 KB Output is correct
88 Correct 103 ms 15768 KB Output is correct
89 Correct 94 ms 12280 KB Output is correct
90 Correct 1 ms 512 KB Output is correct
91 Correct 1 ms 256 KB Output is correct
92 Correct 5 ms 640 KB Output is correct
93 Correct 107 ms 8184 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 384 KB Output is correct
97 Correct 23 ms 2432 KB Output is correct
98 Correct 97 ms 8440 KB Output is correct
99 Correct 93 ms 8824 KB Output is correct
100 Correct 95 ms 8568 KB Output is correct
101 Correct 97 ms 9720 KB Output is correct
102 Correct 105 ms 8288 KB Output is correct
103 Correct 101 ms 8184 KB Output is correct
104 Correct 104 ms 8184 KB Output is correct
105 Correct 102 ms 8184 KB Output is correct