Submission #619707

# Submission time Handle Problem Language Result Execution time Memory
619707 2022-08-02T14:49:46 Z AriaH Connecting Supertrees (IOI20_supertrees) C++17
100 / 100
194 ms 22216 KB
#include "supertrees.h"
/* I can do this all day */
 
#pragma GCC optimize("O3")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
 
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define Mp make_pair
#define point complex
#define endl '\n'
#define SZ(x) (int)x.size()
#define fast_io ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define file_io freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
 
const int N = 1e3 + 10;
const int LOG = 20;
const ll mod = 1e9 + 7;
const ll inf = 8e18;
const double pi = acos(-1);
const ld eps = 1e-18;
const ld one = 1.;
 
ll pw(ll a, ll b, ll M, ll ret = 1) { if(a == 0) return 0; a %= M; while(b) { ret = (b & 1? ret * a % M : ret), a = a * a % M, b >>= 1; } return ret % M; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
int par[N];
 
vector < int > mol[N], vec[N];
 
vector < vector < int > > Ans;
 
inline void add(int i, int j)
{
	Ans[i][j] = Ans[j][i] = 1;
}
 
int get(int x)
{
	return (x == par[x]? x : par[x] = get(par[x]));
}
 
void unify(int v, int u)
{
	v = get(v), u = get(u);
	if(v == u) return;
	par[u] = v;
}
 
int construct(vector < vector < int > > A)
{
	int n = SZ(A);
	for(int i = 0; i < n; i ++) par[i] = i;
	Ans.resize(n);
	for(int i = 0; i < n; i ++)
	{
		Ans[i].resize(n, 0);
		if(A[i][i] != 1) return 0;
		for(int j = 0; j < n; j ++)
		{
			if(A[i][j] == 3) return 0;
			if(A[i][j])
			{
				unify(i, j);
			}
		}
	}
	for(int i = 0; i < n; i ++)
	{
		mol[get(i)].push_back(i);
	}
	for(int i = 0; i < n; i ++)
	{
		/// the connected component check
		for(auto x : mol[i])
		{
			for(auto y : mol[i])
			{
				if(A[x][y] == 0) return 0;
			}
		}
	}
	for(int i = 0; i < n; i ++) par[i] = i;
	for(int i = 0; i < n; i ++)
	{
		for(auto x : mol[i])
		{
			for(auto y : mol[i])
			{
				if(A[x][y] == 1)
				{
					unify(x, y);
				}
			}
		}
	}
	for(int i = 0; i < n; i ++)
	{
		vec[get(i)].push_back(i);
	}
	for(int i = 0; i < n; i ++)
	{
		for(auto x : vec[i])
		{
			for(auto y : vec[i])
			{
				if(A[x][y] != 1)
				{
					return 0;
				}
			}
		}
		for(int j = 1; j < SZ(vec[i]); j ++)
		{
			add(vec[i][j - 1], vec[i][j]);
		}
	}
	for(int i = 0; i < n; i ++)
	{
		vector < int > cyc;
		for(auto x : mol[i])
		{
			if(x == get(x))
			{
				cyc.push_back(x);
			}
		}
		int sz = SZ(cyc);
		if(sz <= 1) continue;
		if(sz == 2) return 0;
		for(int j = 0; j < sz; j ++)
		{
			add(cyc[j], cyc[(j + 1) % sz]);
		}
	}
	build(Ans);
	return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 8 ms 1164 KB Output is correct
7 Correct 174 ms 22088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 8 ms 1164 KB Output is correct
7 Correct 174 ms 22088 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 7 ms 1236 KB Output is correct
13 Correct 168 ms 22076 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 6 ms 724 KB Output is correct
17 Correct 77 ms 12104 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 44 ms 5772 KB Output is correct
21 Correct 170 ms 22076 KB Output is correct
22 Correct 174 ms 22112 KB Output is correct
23 Correct 184 ms 22024 KB Output is correct
24 Correct 167 ms 22088 KB Output is correct
25 Correct 65 ms 12136 KB Output is correct
26 Correct 65 ms 12108 KB Output is correct
27 Correct 184 ms 22104 KB Output is correct
28 Correct 170 ms 22084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 7 ms 1196 KB Output is correct
9 Correct 186 ms 22088 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 8 ms 1196 KB Output is correct
13 Correct 194 ms 22044 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 100 ms 12184 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 42 ms 5764 KB Output is correct
22 Correct 181 ms 22216 KB Output is correct
23 Correct 168 ms 22088 KB Output is correct
24 Correct 186 ms 22092 KB Output is correct
25 Correct 64 ms 12220 KB Output is correct
26 Correct 69 ms 12108 KB Output is correct
27 Correct 168 ms 22092 KB Output is correct
28 Correct 187 ms 22104 KB Output is correct
29 Correct 65 ms 12220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 43 ms 5708 KB Output is correct
5 Correct 168 ms 22052 KB Output is correct
6 Correct 187 ms 22056 KB Output is correct
7 Correct 182 ms 22080 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 43 ms 5768 KB Output is correct
10 Correct 174 ms 22116 KB Output is correct
11 Correct 165 ms 22056 KB Output is correct
12 Correct 185 ms 22176 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 43 ms 5828 KB Output is correct
17 Correct 173 ms 22164 KB Output is correct
18 Correct 169 ms 22076 KB Output is correct
19 Correct 168 ms 22092 KB Output is correct
20 Correct 173 ms 22092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 8 ms 1164 KB Output is correct
7 Correct 174 ms 22088 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 7 ms 1236 KB Output is correct
13 Correct 168 ms 22076 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 6 ms 724 KB Output is correct
17 Correct 77 ms 12104 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 44 ms 5772 KB Output is correct
21 Correct 170 ms 22076 KB Output is correct
22 Correct 174 ms 22112 KB Output is correct
23 Correct 184 ms 22024 KB Output is correct
24 Correct 167 ms 22088 KB Output is correct
25 Correct 65 ms 12136 KB Output is correct
26 Correct 65 ms 12108 KB Output is correct
27 Correct 184 ms 22104 KB Output is correct
28 Correct 170 ms 22084 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 7 ms 1196 KB Output is correct
37 Correct 186 ms 22088 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 8 ms 1196 KB Output is correct
41 Correct 194 ms 22044 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 4 ms 724 KB Output is correct
45 Correct 100 ms 12184 KB Output is correct
46 Correct 0 ms 340 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 0 ms 340 KB Output is correct
49 Correct 42 ms 5764 KB Output is correct
50 Correct 181 ms 22216 KB Output is correct
51 Correct 168 ms 22088 KB Output is correct
52 Correct 186 ms 22092 KB Output is correct
53 Correct 64 ms 12220 KB Output is correct
54 Correct 69 ms 12108 KB Output is correct
55 Correct 168 ms 22092 KB Output is correct
56 Correct 187 ms 22104 KB Output is correct
57 Correct 65 ms 12220 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 0 ms 340 KB Output is correct
60 Correct 4 ms 852 KB Output is correct
61 Correct 81 ms 14136 KB Output is correct
62 Correct 0 ms 340 KB Output is correct
63 Correct 1 ms 468 KB Output is correct
64 Correct 1 ms 356 KB Output is correct
65 Correct 45 ms 6320 KB Output is correct
66 Correct 75 ms 14124 KB Output is correct
67 Correct 69 ms 14124 KB Output is correct
68 Correct 66 ms 14128 KB Output is correct
69 Correct 67 ms 14124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 8 ms 1164 KB Output is correct
7 Correct 174 ms 22088 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 7 ms 1236 KB Output is correct
13 Correct 168 ms 22076 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 6 ms 724 KB Output is correct
17 Correct 77 ms 12104 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 44 ms 5772 KB Output is correct
21 Correct 170 ms 22076 KB Output is correct
22 Correct 174 ms 22112 KB Output is correct
23 Correct 184 ms 22024 KB Output is correct
24 Correct 167 ms 22088 KB Output is correct
25 Correct 65 ms 12136 KB Output is correct
26 Correct 65 ms 12108 KB Output is correct
27 Correct 184 ms 22104 KB Output is correct
28 Correct 170 ms 22084 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 7 ms 1196 KB Output is correct
37 Correct 186 ms 22088 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 8 ms 1196 KB Output is correct
41 Correct 194 ms 22044 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 4 ms 724 KB Output is correct
45 Correct 100 ms 12184 KB Output is correct
46 Correct 0 ms 340 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 0 ms 340 KB Output is correct
49 Correct 42 ms 5764 KB Output is correct
50 Correct 181 ms 22216 KB Output is correct
51 Correct 168 ms 22088 KB Output is correct
52 Correct 186 ms 22092 KB Output is correct
53 Correct 64 ms 12220 KB Output is correct
54 Correct 69 ms 12108 KB Output is correct
55 Correct 168 ms 22092 KB Output is correct
56 Correct 187 ms 22104 KB Output is correct
57 Correct 65 ms 12220 KB Output is correct
58 Correct 0 ms 340 KB Output is correct
59 Correct 0 ms 340 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 43 ms 5708 KB Output is correct
62 Correct 168 ms 22052 KB Output is correct
63 Correct 187 ms 22056 KB Output is correct
64 Correct 182 ms 22080 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 43 ms 5768 KB Output is correct
67 Correct 174 ms 22116 KB Output is correct
68 Correct 165 ms 22056 KB Output is correct
69 Correct 185 ms 22176 KB Output is correct
70 Correct 0 ms 340 KB Output is correct
71 Correct 0 ms 340 KB Output is correct
72 Correct 0 ms 340 KB Output is correct
73 Correct 43 ms 5828 KB Output is correct
74 Correct 173 ms 22164 KB Output is correct
75 Correct 169 ms 22076 KB Output is correct
76 Correct 168 ms 22092 KB Output is correct
77 Correct 173 ms 22092 KB Output is correct
78 Correct 1 ms 340 KB Output is correct
79 Correct 0 ms 340 KB Output is correct
80 Correct 4 ms 852 KB Output is correct
81 Correct 81 ms 14136 KB Output is correct
82 Correct 0 ms 340 KB Output is correct
83 Correct 1 ms 468 KB Output is correct
84 Correct 1 ms 356 KB Output is correct
85 Correct 45 ms 6320 KB Output is correct
86 Correct 75 ms 14124 KB Output is correct
87 Correct 69 ms 14124 KB Output is correct
88 Correct 66 ms 14128 KB Output is correct
89 Correct 67 ms 14124 KB Output is correct
90 Correct 1 ms 340 KB Output is correct
91 Correct 1 ms 340 KB Output is correct
92 Correct 3 ms 728 KB Output is correct
93 Correct 70 ms 10100 KB Output is correct
94 Correct 0 ms 340 KB Output is correct
95 Correct 0 ms 340 KB Output is correct
96 Correct 1 ms 356 KB Output is correct
97 Correct 22 ms 2844 KB Output is correct
98 Correct 65 ms 10412 KB Output is correct
99 Correct 76 ms 10664 KB Output is correct
100 Correct 71 ms 10408 KB Output is correct
101 Correct 64 ms 11432 KB Output is correct
102 Correct 65 ms 10156 KB Output is correct
103 Correct 64 ms 10152 KB Output is correct
104 Correct 62 ms 10156 KB Output is correct
105 Correct 71 ms 10168 KB Output is correct