답안 #721481

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
721481 2023-04-11T02:26:50 Z joelgun14 슈퍼트리 잇기 (IOI20_supertrees) C++17
21 / 100
187 ms 24052 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
const int lim = 1e3 + 5;
struct disjoint_set {
	int h[lim], sz[lim];
	disjoint_set() {
		fill(sz, sz + lim, 1);
		memset(h, -1, sizeof(h));
	}
	int fh(int nd) {
		return h[nd] == -1 ? nd : h[nd] = fh(h[nd]);
	}
	bool merge(int x, int y) {
		x = fh(x), y =fh(y);
		if(x != y) {
			if(sz[x] < sz[y])
				swap(x, y);
			h[y] = x;
			sz[x] += sz[y];
		}
		return x != y;
	}
};
int construct(std::vector<std::vector<int>> p) {
	int n = p.size();
	std::vector<std::vector<int>> answer(n, vector<int>(n, 0));
	bool ans = 1;
	disjoint_set one, two;
	for (int i = 0; i < n; i++) {
		for(int j = 0; j < n; ++j) {
			if(p[i][j] == 3) {
				return 0;
			}
			else if(p[i][j] == 2) {
				two.merge(i, j);
			}	
			else if(p[i][j] == 1) {
				// jadiin 1 group
				one.merge(i, j);
				two.merge(i, j);
			}
		}
	}
	// harus exactly one
	// yg path 1 jadiin 1 grup, tempel ke 1 node
	// nanti jadiin groups banyak
	// group 2 -> harus connected component ish style
	// nanti cek tiap grup yg ter konek bs atau ngga
	for(int i = 0; i < n; ++i) {
		for(int j = i + 1; j < n; ++j) {
			if(p[i][j] == 1) {

			}
			else if(p[i][j] == 2) {
				if(one.fh(i) == one.fh(j)) {
					return 0;
				}
			}
			else {
				if(one.fh(i) == one.fh(j) || two.fh(i) == two.fh(j))
					return 0;
			}
		}		
	}
	// every one group connect ke 1, inside two group nanti buat cycle
	// minimal one group inside 2 harus ada 3
	bool vis[n];
	memset(vis, 0, sizeof(vis));
	for(int i = 0; i < n; ++i) {
		//cout << i << " " << one.fh(i) << endl;
		if(i != one.fh(i))
			answer[i][one.fh(i)] = answer[one.fh(i)][i] = 1;
	}
	for(int i = 0; i < n; ++i) {
		if(vis[i])
			continue;
		set<int> onegroup;
		for(int j = i; j < n; ++j) {
			if(two.fh(j) == two.fh(i)) {
				vis[j] = 1;
				onegroup.insert(one.fh(j));
			}
		}
		if(onegroup.size() == 2)
			return 0;
		if(onegroup.size() == 1)
			continue;
		vector<int> tmp;
		for(auto j : onegroup)
			tmp.push_back(j);
		for(int i = 0; i < tmp.size(); ++i) {
			answer[tmp[i]][tmp[(i + 1) % n]] = answer[tmp[(i + 1) % n]][tmp[i]] = 1;
		}
	}
	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:92:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |   for(int i = 0; i < tmp.size(); ++i) {
      |                  ~~^~~~~~~~~~~~
supertrees.cpp:28:7: warning: unused variable 'ans' [-Wunused-variable]
   28 |  bool ans = 1;
      |       ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1176 KB Output is correct
7 Correct 179 ms 23924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1176 KB Output is correct
7 Correct 179 ms 23924 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 296 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 9 ms 1232 KB Output is correct
13 Correct 165 ms 23892 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 4 ms 828 KB Output is correct
17 Correct 86 ms 14068 KB Output is correct
18 Correct 1 ms 300 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 44 ms 6220 KB Output is correct
21 Correct 181 ms 24052 KB Output is correct
22 Correct 176 ms 23988 KB Output is correct
23 Correct 180 ms 23924 KB Output is correct
24 Correct 166 ms 23940 KB Output is correct
25 Correct 70 ms 14068 KB Output is correct
26 Correct 72 ms 14076 KB Output is correct
27 Correct 177 ms 24048 KB Output is correct
28 Correct 162 ms 24012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 7 ms 1208 KB Output is correct
9 Correct 159 ms 23920 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 8 ms 1236 KB Output is correct
13 Correct 178 ms 23932 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 84 ms 14072 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Incorrect 41 ms 6196 KB Too many ways to get from 0 to 457, should be 0 found no less than 1
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 43 ms 6156 KB Output is correct
5 Correct 175 ms 23940 KB Output is correct
6 Correct 169 ms 23932 KB Output is correct
7 Correct 187 ms 23920 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Incorrect 50 ms 6180 KB Too many ways to get from 0 to 457, should be 0 found no less than 1
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1176 KB Output is correct
7 Correct 179 ms 23924 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 296 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 9 ms 1232 KB Output is correct
13 Correct 165 ms 23892 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 4 ms 828 KB Output is correct
17 Correct 86 ms 14068 KB Output is correct
18 Correct 1 ms 300 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 44 ms 6220 KB Output is correct
21 Correct 181 ms 24052 KB Output is correct
22 Correct 176 ms 23988 KB Output is correct
23 Correct 180 ms 23924 KB Output is correct
24 Correct 166 ms 23940 KB Output is correct
25 Correct 70 ms 14068 KB Output is correct
26 Correct 72 ms 14076 KB Output is correct
27 Correct 177 ms 24048 KB Output is correct
28 Correct 162 ms 24012 KB Output is correct
29 Correct 1 ms 256 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 304 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 7 ms 1208 KB Output is correct
37 Correct 159 ms 23920 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 8 ms 1236 KB Output is correct
41 Correct 178 ms 23932 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 4 ms 852 KB Output is correct
45 Correct 84 ms 14072 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Incorrect 41 ms 6196 KB Too many ways to get from 0 to 457, should be 0 found no less than 1
50 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1176 KB Output is correct
7 Correct 179 ms 23924 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 296 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 9 ms 1232 KB Output is correct
13 Correct 165 ms 23892 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 4 ms 828 KB Output is correct
17 Correct 86 ms 14068 KB Output is correct
18 Correct 1 ms 300 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 44 ms 6220 KB Output is correct
21 Correct 181 ms 24052 KB Output is correct
22 Correct 176 ms 23988 KB Output is correct
23 Correct 180 ms 23924 KB Output is correct
24 Correct 166 ms 23940 KB Output is correct
25 Correct 70 ms 14068 KB Output is correct
26 Correct 72 ms 14076 KB Output is correct
27 Correct 177 ms 24048 KB Output is correct
28 Correct 162 ms 24012 KB Output is correct
29 Correct 1 ms 256 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 304 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 7 ms 1208 KB Output is correct
37 Correct 159 ms 23920 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 8 ms 1236 KB Output is correct
41 Correct 178 ms 23932 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 4 ms 852 KB Output is correct
45 Correct 84 ms 14072 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Incorrect 41 ms 6196 KB Too many ways to get from 0 to 457, should be 0 found no less than 1
50 Halted 0 ms 0 KB -