Submission #999249

# Submission time Handle Problem Language Result Execution time Memory
999249 2024-06-15T08:39:50 Z pan Connecting Supertrees (IOI20_supertrees) C++17
100 / 100
188 ms 32204 KB
#include <bits/stdc++.h>
//#include "bits_stdc++.h"
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define input(x) scanf("%lld", &x);
#define input2(x, y) scanf("%lld%lld", &x, &y);
#define input3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z);
#define input4(x, y, z, a) scanf("%lld%lld%lld%lld", &x, &y, &z, &a);
#define print(x, y) printf("%lld%c", x, y);
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
#define all(x) x.begin(), x.end()
#define discretize(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define FOR(i, x, n) for (ll i =x; i<=n; ++i) 
#define RFOR(i, x, n) for (ll i =x; i>=n; --i) 
using namespace std;
mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
//#define ordered_multiset tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
typedef long long ll;
typedef long double ld;
typedef pair<ld, ll> pd;
typedef pair<string, ll> psl;
typedef pair<ll, ll> pi;
typedef pair<pi, ll> pii;
typedef pair<pi, pi> piii;

ll par[1005];
ll find(ll x) {return ((par[x]==x)?x:par[x] = find(par[x]));}
void unite(ll x, ll y){if ((x=find(x))!=(y=find(y))) par[x] = y;}

vector<ll> compress;
ll adj[1005][1005];
bool visited[1005];

void build(std::vector<std::vector<int> > b);
int construct(std::vector<std::vector<int> > p)
{
	ll n = p.size();
	vector<vector<int> > ret(n, vector<int> (n, 0));
	for (ll i=0; i<n; ++i) for (ll j=0; j<n; ++j) if (p[i][j]==3) return 0;
	for (ll i=0; i<n; ++i) par[i] = i;
	for (ll i=0; i<n; ++i) for (ll j=0; j<n; ++j) if (p[i][j]!=0) unite(i, j);
	for (ll i=0; i<n; ++i) for (ll j=0; j<n; ++j) if (find(i)==find(j) && p[i][j]==0) return 0;
	for (ll i=0; i<n; ++i) par[i] = i;
	for (ll i=0; i<n; ++i) for (ll j=0; j<n; ++j) if (p[i][j]==1) unite(i, j);
	for (ll i=0; i<n; ++i) for (ll j=0; j<n; ++j) if (find(i)==find(j) && p[i][j]!=1) return 0;
	compress.clear();
	for (ll i=0; i<n; ++i) 
	{
		//show2(i, find(i));
		if (find(i)==i) compress.pb(i);
		else ret[i][find(i)] = ret[find(i)][i] = 1;
	}
	for (ll i=0; i<n; ++i) for (ll j=0; j<n; ++j) adj[i][j] = 0;
	for (ll i=0; i<n; ++i) for (ll j=0; j<n; ++j) if (p[i][j]==2) adj[find(i)][find(j)] = adj[find(j)][find(i)] = 1;
	for (ll i=0; i<n; ++i) par[i] = i;
	for (ll u: compress) for (ll u2: compress) {if (adj[u][u2]==1) unite(u, u2);}
	for (ll u: compress) for (ll u2: compress) if (u!=u2 && find(u)==find(u2) && adj[u][u2]!=1) return 0;
	fill(visited,visited+n, 0);
	for (ll u: compress)
	{
		if (visited[u]) continue;
		visited[u] = 1;
		vector<ll> q;
		q.pb(u);
		for (ll i=0; i<q.size(); ++i)
		{
			ll now = q[i];
			for (ll x: compress) if (!visited[x] && adj[now][x]) {visited[x] = 1; q.pb(x);}
		}
		if (q.size()==2) return 0;
		if (q.size()>1)
		{
			ret[q[0]][q.back()] = ret[q.back()][q[0]] = 1;
			for (ll i=0; i<q.size()-1; ++i) ret[q[i]][q[i+1]] = ret[q[i+1]][q[i]] = 1;
		}
	}
	build(ret);
	return 1;
	
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:76:17: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |   for (ll i=0; i<q.size(); ++i)
      |                ~^~~~~~~~~
supertrees.cpp:85:18: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |    for (ll i=0; i<q.size()-1; ++i) ret[q[i]][q[i+1]] = ret[q[i+1]][q[i]] = 1;
      |                 ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 7 ms 3480 KB Output is correct
7 Correct 141 ms 29972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 7 ms 3480 KB Output is correct
7 Correct 141 ms 29972 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 3420 KB Output is correct
13 Correct 124 ms 30036 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 59 ms 12052 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 30 ms 10156 KB Output is correct
21 Correct 131 ms 29992 KB Output is correct
22 Correct 135 ms 30036 KB Output is correct
23 Correct 162 ms 29988 KB Output is correct
24 Correct 149 ms 29992 KB Output is correct
25 Correct 63 ms 12116 KB Output is correct
26 Correct 54 ms 12060 KB Output is correct
27 Correct 141 ms 29976 KB Output is correct
28 Correct 133 ms 30036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 452 KB Output is correct
6 Correct 1 ms 356 KB Output is correct
7 Correct 1 ms 448 KB Output is correct
8 Correct 7 ms 3420 KB Output is correct
9 Correct 142 ms 32028 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 6 ms 3472 KB Output is correct
13 Correct 149 ms 31860 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 4 ms 872 KB Output is correct
17 Correct 65 ms 14240 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 36 ms 10520 KB Output is correct
22 Correct 188 ms 32016 KB Output is correct
23 Correct 131 ms 31824 KB Output is correct
24 Correct 149 ms 31888 KB Output is correct
25 Correct 64 ms 22096 KB Output is correct
26 Correct 59 ms 14092 KB Output is correct
27 Correct 128 ms 31828 KB Output is correct
28 Correct 154 ms 31844 KB Output is correct
29 Correct 67 ms 21912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 33 ms 10556 KB Output is correct
5 Correct 134 ms 31912 KB Output is correct
6 Correct 123 ms 31824 KB Output is correct
7 Correct 139 ms 31888 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 33 ms 10520 KB Output is correct
10 Correct 127 ms 32024 KB Output is correct
11 Correct 143 ms 32204 KB Output is correct
12 Correct 143 ms 31860 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 33 ms 10640 KB Output is correct
17 Correct 134 ms 31824 KB Output is correct
18 Correct 122 ms 31828 KB Output is correct
19 Correct 126 ms 31884 KB Output is correct
20 Correct 124 ms 31896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 7 ms 3480 KB Output is correct
7 Correct 141 ms 29972 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 3420 KB Output is correct
13 Correct 124 ms 30036 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 59 ms 12052 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 30 ms 10156 KB Output is correct
21 Correct 131 ms 29992 KB Output is correct
22 Correct 135 ms 30036 KB Output is correct
23 Correct 162 ms 29988 KB Output is correct
24 Correct 149 ms 29992 KB Output is correct
25 Correct 63 ms 12116 KB Output is correct
26 Correct 54 ms 12060 KB Output is correct
27 Correct 141 ms 29976 KB Output is correct
28 Correct 133 ms 30036 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 452 KB Output is correct
34 Correct 1 ms 356 KB Output is correct
35 Correct 1 ms 448 KB Output is correct
36 Correct 7 ms 3420 KB Output is correct
37 Correct 142 ms 32028 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 6 ms 3472 KB Output is correct
41 Correct 149 ms 31860 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 4 ms 872 KB Output is correct
45 Correct 65 ms 14240 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 36 ms 10520 KB Output is correct
50 Correct 188 ms 32016 KB Output is correct
51 Correct 131 ms 31824 KB Output is correct
52 Correct 149 ms 31888 KB Output is correct
53 Correct 64 ms 22096 KB Output is correct
54 Correct 59 ms 14092 KB Output is correct
55 Correct 128 ms 31828 KB Output is correct
56 Correct 154 ms 31844 KB Output is correct
57 Correct 67 ms 21912 KB Output is correct
58 Correct 0 ms 596 KB Output is correct
59 Correct 1 ms 344 KB Output is correct
60 Correct 3 ms 860 KB Output is correct
61 Correct 64 ms 14224 KB Output is correct
62 Correct 0 ms 344 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 31 ms 10596 KB Output is correct
66 Correct 52 ms 14160 KB Output is correct
67 Correct 49 ms 14164 KB Output is correct
68 Correct 51 ms 14164 KB Output is correct
69 Correct 71 ms 22124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 7 ms 3480 KB Output is correct
7 Correct 141 ms 29972 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 3420 KB Output is correct
13 Correct 124 ms 30036 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 59 ms 12052 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 30 ms 10156 KB Output is correct
21 Correct 131 ms 29992 KB Output is correct
22 Correct 135 ms 30036 KB Output is correct
23 Correct 162 ms 29988 KB Output is correct
24 Correct 149 ms 29992 KB Output is correct
25 Correct 63 ms 12116 KB Output is correct
26 Correct 54 ms 12060 KB Output is correct
27 Correct 141 ms 29976 KB Output is correct
28 Correct 133 ms 30036 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 452 KB Output is correct
34 Correct 1 ms 356 KB Output is correct
35 Correct 1 ms 448 KB Output is correct
36 Correct 7 ms 3420 KB Output is correct
37 Correct 142 ms 32028 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 6 ms 3472 KB Output is correct
41 Correct 149 ms 31860 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 4 ms 872 KB Output is correct
45 Correct 65 ms 14240 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 36 ms 10520 KB Output is correct
50 Correct 188 ms 32016 KB Output is correct
51 Correct 131 ms 31824 KB Output is correct
52 Correct 149 ms 31888 KB Output is correct
53 Correct 64 ms 22096 KB Output is correct
54 Correct 59 ms 14092 KB Output is correct
55 Correct 128 ms 31828 KB Output is correct
56 Correct 154 ms 31844 KB Output is correct
57 Correct 67 ms 21912 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 33 ms 10556 KB Output is correct
62 Correct 134 ms 31912 KB Output is correct
63 Correct 123 ms 31824 KB Output is correct
64 Correct 139 ms 31888 KB Output is correct
65 Correct 1 ms 344 KB Output is correct
66 Correct 33 ms 10520 KB Output is correct
67 Correct 127 ms 32024 KB Output is correct
68 Correct 143 ms 32204 KB Output is correct
69 Correct 143 ms 31860 KB Output is correct
70 Correct 0 ms 348 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 0 ms 348 KB Output is correct
73 Correct 33 ms 10640 KB Output is correct
74 Correct 134 ms 31824 KB Output is correct
75 Correct 122 ms 31828 KB Output is correct
76 Correct 126 ms 31884 KB Output is correct
77 Correct 124 ms 31896 KB Output is correct
78 Correct 0 ms 596 KB Output is correct
79 Correct 1 ms 344 KB Output is correct
80 Correct 3 ms 860 KB Output is correct
81 Correct 64 ms 14224 KB Output is correct
82 Correct 0 ms 344 KB Output is correct
83 Correct 0 ms 348 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 31 ms 10596 KB Output is correct
86 Correct 52 ms 14160 KB Output is correct
87 Correct 49 ms 14164 KB Output is correct
88 Correct 51 ms 14164 KB Output is correct
89 Correct 71 ms 22124 KB Output is correct
90 Correct 0 ms 344 KB Output is correct
91 Correct 0 ms 348 KB Output is correct
92 Correct 3 ms 860 KB Output is correct
93 Correct 60 ms 14220 KB Output is correct
94 Correct 0 ms 344 KB Output is correct
95 Correct 0 ms 348 KB Output is correct
96 Correct 0 ms 348 KB Output is correct
97 Correct 12 ms 3864 KB Output is correct
98 Correct 48 ms 14052 KB Output is correct
99 Correct 50 ms 14160 KB Output is correct
100 Correct 54 ms 14164 KB Output is correct
101 Correct 47 ms 14108 KB Output is correct
102 Correct 49 ms 14160 KB Output is correct
103 Correct 47 ms 14160 KB Output is correct
104 Correct 50 ms 14024 KB Output is correct
105 Correct 56 ms 14160 KB Output is correct