답안 #352361

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
352361 2021-01-20T16:26:44 Z ryansee 슈퍼트리 잇기 (IOI20_supertrees) C++14
100 / 100
276 ms 22380 KB
#include "supertrees.h"

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

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr<<"hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

using ll=long long; 
using ld=long double;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>; 

long long LLINF = 1e18;
int INF = 1e9+1e6;
#define MAXN (1006)
int p[MAXN];
void init() {
	FOR(i,0,MAXN-1) p[i]=i;
}
int find(int x) { return p[x] == x ? x : p[x] = find(p[x]); }
void merge(int x,int y) {
	p[find(x)] = find(y);
}

vector<vector<int>> v;
void add(int x,int y) {
	v[x][y]=v[y][x]=1;
}

int construct(std::vector<std::vector<int>> p) {
	int n = p.size();
	v.resize(n, vector<int>(n, 0));
	init();
	FOR(i,0,n-1) FOR(j,i+1,n-1) if(p[i][j]) merge(i, j);
	FOR(i,0,n-1) FOR(j,i+1,n-1) if(p[i][j]==0 && find(i)==find(j)) return 0;
	vector<vector<int>> nodes;
	FOR(i,0,n-1) if(find(i) == i) {
		nodes.pb({});
		FOR(j,0,n-1) if(find(j) == find(i)) {
			nodes.back().eb(j);
		}
	}
	init();
	for(auto i:nodes) {
		for(auto j:i) for(auto k:i) if(j^k && p[j][k] == 1) merge(j, k);
		for(auto j:i) for(auto k:i) if(j^k && p[j][k] == 2 && find(j)==find(k)) return 0;
		
		bool got3 = 0;
		for(auto j:i) for(auto k:i) if(p[j][k] == 3) {
			got3 = 1;
		}
		if(got3) {
			for(auto j:i) for(auto k:i) if(find(j)^find(k) && p[j][k] ^ 3) return 0;
		}
		vector<int> tmp;
		for(auto j:i) if(find(j)==j) tmp.eb(j);
		if(siz(tmp) == 2 || (got3 && siz(tmp) != 4)) return 0;
		if(siz(tmp) > 1) FOR(i,0,siz(tmp)-1) add(tmp[i], tmp[(i+1)%siz(tmp)]);
		
		if(got3) {
			add(tmp[1], tmp[3]);
		}
		
		for(auto j:i) if(find(j) ^ j) add(find(j), j);
	}
	build(v);
	return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 11 ms 1260 KB Output is correct
7 Correct 264 ms 22252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 11 ms 1260 KB Output is correct
7 Correct 264 ms 22252 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 11 ms 1260 KB Output is correct
13 Correct 255 ms 22252 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 0 ms 364 KB Output is correct
16 Correct 5 ms 748 KB Output is correct
17 Correct 118 ms 12140 KB Output is correct
18 Correct 0 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 65 ms 5868 KB Output is correct
21 Correct 260 ms 22252 KB Output is correct
22 Correct 260 ms 22124 KB Output is correct
23 Correct 273 ms 22124 KB Output is correct
24 Correct 258 ms 22152 KB Output is correct
25 Correct 107 ms 12140 KB Output is correct
26 Correct 106 ms 12140 KB Output is correct
27 Correct 274 ms 22124 KB Output is correct
28 Correct 259 ms 22252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 11 ms 1260 KB Output is correct
9 Correct 258 ms 22124 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 11 ms 1260 KB Output is correct
13 Correct 260 ms 22124 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 6 ms 748 KB Output is correct
17 Correct 120 ms 12140 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 68 ms 5868 KB Output is correct
22 Correct 260 ms 22124 KB Output is correct
23 Correct 257 ms 22252 KB Output is correct
24 Correct 269 ms 22124 KB Output is correct
25 Correct 112 ms 12396 KB Output is correct
26 Correct 108 ms 12140 KB Output is correct
27 Correct 258 ms 22124 KB Output is correct
28 Correct 269 ms 22124 KB Output is correct
29 Correct 112 ms 12268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 65 ms 5868 KB Output is correct
5 Correct 259 ms 22380 KB Output is correct
6 Correct 264 ms 22252 KB Output is correct
7 Correct 276 ms 22124 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 65 ms 5868 KB Output is correct
10 Correct 261 ms 22124 KB Output is correct
11 Correct 259 ms 22120 KB Output is correct
12 Correct 268 ms 22252 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 72 ms 5868 KB Output is correct
17 Correct 258 ms 22124 KB Output is correct
18 Correct 260 ms 22140 KB Output is correct
19 Correct 258 ms 22124 KB Output is correct
20 Correct 258 ms 22124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 11 ms 1260 KB Output is correct
7 Correct 264 ms 22252 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 11 ms 1260 KB Output is correct
13 Correct 255 ms 22252 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 0 ms 364 KB Output is correct
16 Correct 5 ms 748 KB Output is correct
17 Correct 118 ms 12140 KB Output is correct
18 Correct 0 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 65 ms 5868 KB Output is correct
21 Correct 260 ms 22252 KB Output is correct
22 Correct 260 ms 22124 KB Output is correct
23 Correct 273 ms 22124 KB Output is correct
24 Correct 258 ms 22152 KB Output is correct
25 Correct 107 ms 12140 KB Output is correct
26 Correct 106 ms 12140 KB Output is correct
27 Correct 274 ms 22124 KB Output is correct
28 Correct 259 ms 22252 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 0 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 11 ms 1260 KB Output is correct
37 Correct 258 ms 22124 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 512 KB Output is correct
40 Correct 11 ms 1260 KB Output is correct
41 Correct 260 ms 22124 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 6 ms 748 KB Output is correct
45 Correct 120 ms 12140 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 68 ms 5868 KB Output is correct
50 Correct 260 ms 22124 KB Output is correct
51 Correct 257 ms 22252 KB Output is correct
52 Correct 269 ms 22124 KB Output is correct
53 Correct 112 ms 12396 KB Output is correct
54 Correct 108 ms 12140 KB Output is correct
55 Correct 258 ms 22124 KB Output is correct
56 Correct 269 ms 22124 KB Output is correct
57 Correct 112 ms 12268 KB Output is correct
58 Correct 0 ms 364 KB Output is correct
59 Correct 1 ms 364 KB Output is correct
60 Correct 5 ms 748 KB Output is correct
61 Correct 119 ms 12268 KB Output is correct
62 Correct 1 ms 364 KB Output is correct
63 Correct 1 ms 364 KB Output is correct
64 Correct 1 ms 364 KB Output is correct
65 Correct 66 ms 5996 KB Output is correct
66 Correct 109 ms 12140 KB Output is correct
67 Correct 108 ms 12140 KB Output is correct
68 Correct 105 ms 12140 KB Output is correct
69 Correct 111 ms 12268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 11 ms 1260 KB Output is correct
7 Correct 264 ms 22252 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 11 ms 1260 KB Output is correct
13 Correct 255 ms 22252 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 0 ms 364 KB Output is correct
16 Correct 5 ms 748 KB Output is correct
17 Correct 118 ms 12140 KB Output is correct
18 Correct 0 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 65 ms 5868 KB Output is correct
21 Correct 260 ms 22252 KB Output is correct
22 Correct 260 ms 22124 KB Output is correct
23 Correct 273 ms 22124 KB Output is correct
24 Correct 258 ms 22152 KB Output is correct
25 Correct 107 ms 12140 KB Output is correct
26 Correct 106 ms 12140 KB Output is correct
27 Correct 274 ms 22124 KB Output is correct
28 Correct 259 ms 22252 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 0 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 11 ms 1260 KB Output is correct
37 Correct 258 ms 22124 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 512 KB Output is correct
40 Correct 11 ms 1260 KB Output is correct
41 Correct 260 ms 22124 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 6 ms 748 KB Output is correct
45 Correct 120 ms 12140 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 68 ms 5868 KB Output is correct
50 Correct 260 ms 22124 KB Output is correct
51 Correct 257 ms 22252 KB Output is correct
52 Correct 269 ms 22124 KB Output is correct
53 Correct 112 ms 12396 KB Output is correct
54 Correct 108 ms 12140 KB Output is correct
55 Correct 258 ms 22124 KB Output is correct
56 Correct 269 ms 22124 KB Output is correct
57 Correct 112 ms 12268 KB Output is correct
58 Correct 0 ms 364 KB Output is correct
59 Correct 0 ms 364 KB Output is correct
60 Correct 0 ms 364 KB Output is correct
61 Correct 65 ms 5868 KB Output is correct
62 Correct 259 ms 22380 KB Output is correct
63 Correct 264 ms 22252 KB Output is correct
64 Correct 276 ms 22124 KB Output is correct
65 Correct 1 ms 364 KB Output is correct
66 Correct 65 ms 5868 KB Output is correct
67 Correct 261 ms 22124 KB Output is correct
68 Correct 259 ms 22120 KB Output is correct
69 Correct 268 ms 22252 KB Output is correct
70 Correct 1 ms 364 KB Output is correct
71 Correct 1 ms 364 KB Output is correct
72 Correct 1 ms 364 KB Output is correct
73 Correct 72 ms 5868 KB Output is correct
74 Correct 258 ms 22124 KB Output is correct
75 Correct 260 ms 22140 KB Output is correct
76 Correct 258 ms 22124 KB Output is correct
77 Correct 258 ms 22124 KB Output is correct
78 Correct 0 ms 364 KB Output is correct
79 Correct 1 ms 364 KB Output is correct
80 Correct 5 ms 748 KB Output is correct
81 Correct 119 ms 12268 KB Output is correct
82 Correct 1 ms 364 KB Output is correct
83 Correct 1 ms 364 KB Output is correct
84 Correct 1 ms 364 KB Output is correct
85 Correct 66 ms 5996 KB Output is correct
86 Correct 109 ms 12140 KB Output is correct
87 Correct 108 ms 12140 KB Output is correct
88 Correct 105 ms 12140 KB Output is correct
89 Correct 111 ms 12268 KB Output is correct
90 Correct 1 ms 364 KB Output is correct
91 Correct 1 ms 364 KB Output is correct
92 Correct 8 ms 748 KB Output is correct
93 Correct 113 ms 12392 KB Output is correct
94 Correct 0 ms 364 KB Output is correct
95 Correct 0 ms 364 KB Output is correct
96 Correct 1 ms 364 KB Output is correct
97 Correct 27 ms 3308 KB Output is correct
98 Correct 107 ms 12140 KB Output is correct
99 Correct 107 ms 12140 KB Output is correct
100 Correct 109 ms 12140 KB Output is correct
101 Correct 112 ms 12416 KB Output is correct
102 Correct 114 ms 12268 KB Output is correct
103 Correct 119 ms 13420 KB Output is correct
104 Correct 128 ms 13420 KB Output is correct
105 Correct 117 ms 13420 KB Output is correct