답안 #952777

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
952777 2024-03-24T19:10:06 Z emad234 슈퍼트리 잇기 (IOI20_supertrees) C++17
21 / 100
1000 ms 63196 KB
#include "supertrees.h"
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define pii pair<ll, ll>
const ll mod = 1e9 + 7;
const ll mxN = 1e6 + 5;
using namespace std;

int dsu[mxN];
int find(int x) { return dsu[x] == x ? x : dsu[x] = find(dsu[x]); }
void merge(int a, int b) { dsu[find(b)] = find(a); }
int construct(std::vector<std::vector<int>> p)
{
	vector<vector<int>> b;
	int n = p.size(), m = p.size();
	b.resize(n);
	for (int i = 0; i < n; i++)
		dsu[i] = i;
	for (int i = 0; i < n; i++)
		b[i].resize(m);
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			if (i == j)
				continue;
			if (p[i][j] == 1)
			{
				if (find(i) != find(j))
				{
					merge(i, j);
					b[i][j] = 1;
					b[j][i] = 1;
				}
			}
		}
	}
	vector<vector<int>> ty;
	vector<set<int>> v;
	v.resize(n);
	ty.resize(n);
	for (int i = 0; i < n; i++)
	{
		ty[i].resize(n);
		for (int j = 0; j < m; j++)
		{
			ty[i][j] = -1;
		}
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			if (i == j)
				continue;
			if (find(i) == find(j))
			{
				if (p[i][j] != 1)
					return 0;
			}
			else
			{
				if (ty[i][find(j)] != -1 && p[i][j] != ty[i][find(j)])
					return 0;
				if (p[i][j] == 2)
					v[find(i)].insert(find(j));
				ty[i][find(j)] = p[i][j];
			}
		}
	}
	vector<bool> vis(n);
	for (int i = 0; i < n; i++)
	{
		int prv = -1;
		v[i].insert(i);
		for(auto x : v[i]){
			for(int j = 0;j < n;j++){
				if(x == j) continue;
				if(v[i].find(j) != v[i].end() && p[x][j] != 2) return 0;
			}
		}
		if (vis[i])
			continue;
		if (v[i].size() == 2)
			return 0;
		for (auto x : v[i])
		{
			vis[x] = 1;
			if (prv != -1)
			{
				b[x][prv] = 1;
				b[prv][x] = 1;
			}
			prv = x;
		}
		if (v[i].size() >= 2)
		{
			b[*v[i].begin()][*v[i].rbegin()] = 1;
			b[*v[i].rbegin()][*v[i].begin()] = 1;
		}
	}
	build(b);
	return 1;
}
# 결과 실행 시간 메모리 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 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 7 ms 1372 KB Output is correct
7 Correct 159 ms 26172 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 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 7 ms 1372 KB Output is correct
7 Correct 159 ms 26172 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 596 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 7 ms 1372 KB Output is correct
13 Correct 155 ms 26092 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 72 ms 16164 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 41 ms 6788 KB Output is correct
21 Correct 162 ms 26132 KB Output is correct
22 Correct 168 ms 26148 KB Output is correct
23 Correct 167 ms 26132 KB Output is correct
24 Correct 156 ms 26148 KB Output is correct
25 Correct 67 ms 16152 KB Output is correct
26 Correct 61 ms 16212 KB Output is correct
27 Correct 177 ms 26148 KB Output is correct
28 Correct 160 ms 26404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 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 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 6 ms 1372 KB Output is correct
9 Correct 174 ms 26132 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 109 ms 3212 KB Output is correct
13 Execution timed out 1077 ms 63196 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 44 ms 6956 KB Output is correct
5 Correct 175 ms 26008 KB Output is correct
6 Correct 163 ms 26236 KB Output is correct
7 Correct 167 ms 26144 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 63 ms 7212 KB Output is correct
10 Correct 985 ms 30892 KB Output is correct
11 Correct 171 ms 26448 KB Output is correct
12 Execution timed out 1084 ms 39508 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 7 ms 1372 KB Output is correct
7 Correct 159 ms 26172 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 596 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 7 ms 1372 KB Output is correct
13 Correct 155 ms 26092 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 72 ms 16164 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 41 ms 6788 KB Output is correct
21 Correct 162 ms 26132 KB Output is correct
22 Correct 168 ms 26148 KB Output is correct
23 Correct 167 ms 26132 KB Output is correct
24 Correct 156 ms 26148 KB Output is correct
25 Correct 67 ms 16152 KB Output is correct
26 Correct 61 ms 16212 KB Output is correct
27 Correct 177 ms 26148 KB Output is correct
28 Correct 160 ms 26404 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 6 ms 1372 KB Output is correct
37 Correct 174 ms 26132 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 109 ms 3212 KB Output is correct
41 Execution timed out 1077 ms 63196 KB Time limit exceeded
42 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 7 ms 1372 KB Output is correct
7 Correct 159 ms 26172 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 596 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 7 ms 1372 KB Output is correct
13 Correct 155 ms 26092 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 72 ms 16164 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 41 ms 6788 KB Output is correct
21 Correct 162 ms 26132 KB Output is correct
22 Correct 168 ms 26148 KB Output is correct
23 Correct 167 ms 26132 KB Output is correct
24 Correct 156 ms 26148 KB Output is correct
25 Correct 67 ms 16152 KB Output is correct
26 Correct 61 ms 16212 KB Output is correct
27 Correct 177 ms 26148 KB Output is correct
28 Correct 160 ms 26404 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 6 ms 1372 KB Output is correct
37 Correct 174 ms 26132 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 109 ms 3212 KB Output is correct
41 Execution timed out 1077 ms 63196 KB Time limit exceeded
42 Halted 0 ms 0 KB -