답안 #1039662

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1039662 2024-07-31T07:07:39 Z AmirAli_H1 슈퍼트리 잇기 (IOI20_supertrees) C++17
56 / 100
146 ms 27992 KB
// In the name of Allah

#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;

typedef		long long int			ll;
typedef		long double				ld;
typedef		pair<int, int>			pii;
typedef		pair<ll, ll>			pll;
typedef		complex<ld>				cld;

#define		all(x)					(x).begin(),(x).end()
#define		len(x)					((ll) (x).size())
#define		F						first
#define		S						second
#define		pb						push_back
#define		sep						' '
#define		endl					'\n'
#define		Mp						make_pair
#define		kill(x)					cout << x << '\n', exit(0)
#define		set_dec(x)				cout << fixed << setprecision(x);
#define		file_io(x,y)			freopen(x, "r", stdin); freopen(y, "w", stdout);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 1000 + 4;

int n;
int adj[maxn][maxn];
int p[maxn], sz[maxn];
vector<pii> E; int col[maxn];
vector<int> ls[maxn], lsx[maxn];
vector<vector<int>> ans;

int get(int a) {
	return (p[a] == a) ? a : p[a] = get(p[a]);
}

void merge(int a, int b) {
	a = get(a); b = get(b);
	if (a == b) return ;
	if (sz[a] > sz[b]) swap(a, b);
	p[a] = b; sz[b] += sz[a]; sz[a] = 0;
}

int construct(vector<vector<int>> Ax) {
	n = Ax.size();
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			adj[i][j] = Ax[i][j];
		}
	}
	
	iota(p, p + n, 0); fill(sz, sz + n, 1);
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (adj[i][j] >= 1) merge(i, j);
		}
	}
	for (int i = 0; i < n; i++) {
		col[i] = get(i);
		for (int j = i + 1; j < n; j++) {
			if (get(i) == get(j) && adj[i][j] == 0) return 0;
		}
	}
	
	iota(p, p + n, 0); fill(sz, sz + n, 1);
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (adj[i][j] == 1) merge(i, j);
		}
	}
	for (int i = 0; i < n; i++) {
		ls[get(i)].pb(i);
		for (int j = i + 1; j < n; j++) {
			if (get(i) == get(j) && adj[i][j] != 1) return 0;
		}
	}
	
	for (int i = 0; i < n; i++) {
		if (len(ls[i]) == 0) continue;
		for (int j = 1; j < len(ls[i]); j++) {
			E.pb(Mp(ls[i][j - 1], ls[i][j]));
		}
		int v = ls[i].back();
		lsx[col[v]].pb(v);
	}
	
	for (int i = 0; i < n; i++) {
		if (len(lsx[i]) <= 1) continue;
		for (int j = 0; j < len(lsx[i]); j++) {
			int r = j + 1;
			if (r >= len(lsx[i])) r -= len(lsx[i]);
			E.pb(Mp(lsx[i][j], lsx[i][r]));
		}
	}
	
	ans.resize(n);
	for (int i = 0; i < n; i++) ans[i].resize(n);
	for (auto f : E) {
		int u = f.F, v = f.S;
		ans[u][v] = ans[v][u] = 1;
	}
	build(ans);
	return 1;
}
# 결과 실행 시간 메모리 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 2024 KB Output is correct
7 Correct 120 ms 27888 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 2024 KB Output is correct
7 Correct 120 ms 27888 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 5 ms 2140 KB Output is correct
13 Correct 121 ms 27988 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 1628 KB Output is correct
17 Correct 60 ms 14048 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 31 ms 8228 KB Output is correct
21 Correct 129 ms 27988 KB Output is correct
22 Correct 116 ms 27992 KB Output is correct
23 Correct 124 ms 27908 KB Output is correct
24 Correct 117 ms 27924 KB Output is correct
25 Correct 52 ms 13908 KB Output is correct
26 Correct 52 ms 13900 KB Output is correct
27 Correct 127 ms 27988 KB Output is correct
28 Correct 113 ms 27988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 360 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 29 ms 8420 KB Output is correct
5 Correct 146 ms 27988 KB Output is correct
6 Correct 115 ms 27988 KB Output is correct
7 Correct 120 ms 27984 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 29 ms 8312 KB Output is correct
10 Correct 112 ms 27988 KB Output is correct
11 Correct 116 ms 27988 KB Output is correct
12 Correct 121 ms 27768 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 29 ms 8280 KB Output is correct
17 Correct 116 ms 27844 KB Output is correct
18 Correct 119 ms 27984 KB Output is correct
19 Correct 114 ms 27828 KB Output is correct
20 Correct 118 ms 27984 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 2024 KB Output is correct
7 Correct 120 ms 27888 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 5 ms 2140 KB Output is correct
13 Correct 121 ms 27988 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 1628 KB Output is correct
17 Correct 60 ms 14048 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 31 ms 8228 KB Output is correct
21 Correct 129 ms 27988 KB Output is correct
22 Correct 116 ms 27992 KB Output is correct
23 Correct 124 ms 27908 KB Output is correct
24 Correct 117 ms 27924 KB Output is correct
25 Correct 52 ms 13908 KB Output is correct
26 Correct 52 ms 13900 KB Output is correct
27 Correct 127 ms 27988 KB Output is correct
28 Correct 113 ms 27988 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 2024 KB Output is correct
7 Correct 120 ms 27888 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 5 ms 2140 KB Output is correct
13 Correct 121 ms 27988 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 1628 KB Output is correct
17 Correct 60 ms 14048 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 31 ms 8228 KB Output is correct
21 Correct 129 ms 27988 KB Output is correct
22 Correct 116 ms 27992 KB Output is correct
23 Correct 124 ms 27908 KB Output is correct
24 Correct 117 ms 27924 KB Output is correct
25 Correct 52 ms 13908 KB Output is correct
26 Correct 52 ms 13900 KB Output is correct
27 Correct 127 ms 27988 KB Output is correct
28 Correct 113 ms 27988 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -