답안 #903302

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
903302 2024-01-11T06:56:32 Z ByeWorld 슈퍼트리 잇기 (IOI20_supertrees) C++14
21 / 100
227 ms 24344 KB
#include "supertrees.h"
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define lb lower_bound
using namespace std;
const int MAXN = 1e3+10;
const double SMALL = 1e-6;
typedef pair<int,int> pii;
typedef pair<pii,int> ipii;

int n;
bool tag[MAXN], done[MAXN];
vector <vector<int>> adj;
vector <int> cc[MAXN];

void bd(int x, int y){
	adj[x][y] = 1; adj[y][x] = 1;
}

struct DSU {
	int par[MAXN], siz[MAXN];
	void bd(){
		for(int i=0; i<n; i++){
			par[i] = i; siz[i] = 1;
			cc[i].pb(i);
		}
	}
	int f(int x){
		if(x == par[x]) return x;
		return par[x] = f(par[x]);
	}
	bool con(int x, int y){
		return f(x) == f(y);
	}
	void mer(int x, int y){
		if(con(x, y)) return;
		x = f(x); y = f(y);
		if(siz[x] > siz[y]) swap(x, y);
		par[x] = y; siz[y] += siz[x];
		for(auto in : cc[x]) cc[y].pb(in);
	}
} A;

int construct(vector<vector<int>> p) {
	n = p.size();
	vector <int> te(n);
	for(int i=0; i<n; i++) adj.pb(te);
	A.bd();

	for(int i = 0; i < n; i++) {
		if(done[i]) continue;
		for(int x=0; x<n; x++) tag[x] = 0;

		vector <int> vec; vec.pb(i); tag[i] = 1;
		for(int j=i+1; j < n; j++){
			if(p[i][j] == 1){
				vec.pb(j); tag[j] = 1;
			}	
		}
		//for(auto in : vec) cout << in << "pp\n";
		for(auto in : vec){
			//cout << in << " in\n";
			done[in] = 1;
			for(int x=0; x<n; x++){
				if(tag[x] && p[in][x] != 1) return 0; //harusnya 1
				if(!tag[x] && p[in][x] == 1) return 0;
			}
		}
		for(int i=0; i+1<vec.size(); i++){ // build
			bd(vec[i], vec[i+1]);
			A.mer(vec[i], vec[i+1]);
		}
	}
	// for(int i=0; i<n; i++){
	// 	for(int j=0; j<n; j++) cout << adj[i][j] << ' ';
	// 	cout << '\n';
	// }

	for(int i=0; i<n; i++) done[i] = 0;
	for(int i = 0; i < n; i++) {
		if(done[A.f(i)]) continue;
		for(int x=0; x<n; x++) tag[x] = 0;

		vector <int> vec; vec.pb(i); tag[i] = 1;
		for(int j=i+1; j < n; j++){
			if(p[i][j] == 2){
				vec.pb(j); tag[j] = 1;
			}	
		}

		if(vec.size() == 1) continue;
		//if(vec.size() == 2) return 0;

		// for(auto x : vec){
		// 	for(auto y : vec){
		// 		if(x==y) continue; 
		// 		if(A.con(x, y)) return 0;
		// 	}
		// }
		//for(auto in : vec) cout << in << "pp\n";
		for(auto in : vec){
			//cout << in << " in\n";
			done[A.f(in)] = 1;
			// for(int x=0; x<n; x++){
			// 	if(x==in) continue;
			// 	if(tag[x] && p[in][x] != 2) return 0; //harusnya 1
			// 	if(!tag[x] && p[in][x] == 2) return 0;
			// }
		}
		for(int i=0; i+1<vec.size(); i++){ // build
			bd(vec[i], vec[i+1]);
		}
		bd(vec[0], vec.back());
	}

	for(int i=0; i<n; i++) adj[i][i] = 0;
	build(adj);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:72:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |   for(int i=0; i+1<vec.size(); i++){ // build
      |                ~~~^~~~~~~~~~~
supertrees.cpp:113:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  113 |   for(int i=0; i+1<vec.size(); i++){ // build
      |                ~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 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 344 KB Output is correct
6 Correct 7 ms 1368 KB Output is correct
7 Correct 221 ms 24100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 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 344 KB Output is correct
6 Correct 7 ms 1368 KB Output is correct
7 Correct 221 ms 24100 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 7 ms 1372 KB Output is correct
13 Correct 177 ms 23988 KB Output is correct
14 Correct 1 ms 496 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 4 ms 964 KB Output is correct
17 Correct 96 ms 14288 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 41 ms 6384 KB Output is correct
21 Correct 177 ms 24012 KB Output is correct
22 Correct 197 ms 23972 KB Output is correct
23 Correct 192 ms 23976 KB Output is correct
24 Correct 174 ms 24120 KB Output is correct
25 Correct 99 ms 14160 KB Output is correct
26 Correct 69 ms 14164 KB Output is correct
27 Correct 171 ms 24216 KB Output is correct
28 Correct 163 ms 24072 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 344 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 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 46 ms 6436 KB Output is correct
5 Correct 166 ms 24144 KB Output is correct
6 Correct 227 ms 24092 KB Output is correct
7 Correct 191 ms 24056 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 41 ms 6376 KB Output is correct
10 Correct 175 ms 24344 KB Output is correct
11 Correct 168 ms 24152 KB Output is correct
12 Correct 179 ms 24080 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Incorrect 41 ms 6428 KB Too many ways to get from 0 to 352, should be 2 found no less than 3
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 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 344 KB Output is correct
6 Correct 7 ms 1368 KB Output is correct
7 Correct 221 ms 24100 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 7 ms 1372 KB Output is correct
13 Correct 177 ms 23988 KB Output is correct
14 Correct 1 ms 496 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 4 ms 964 KB Output is correct
17 Correct 96 ms 14288 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 41 ms 6384 KB Output is correct
21 Correct 177 ms 24012 KB Output is correct
22 Correct 197 ms 23972 KB Output is correct
23 Correct 192 ms 23976 KB Output is correct
24 Correct 174 ms 24120 KB Output is correct
25 Correct 99 ms 14160 KB Output is correct
26 Correct 69 ms 14164 KB Output is correct
27 Correct 171 ms 24216 KB Output is correct
28 Correct 163 ms 24072 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 344 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 344 KB Output is correct
2 Correct 1 ms 344 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 344 KB Output is correct
6 Correct 7 ms 1368 KB Output is correct
7 Correct 221 ms 24100 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 7 ms 1372 KB Output is correct
13 Correct 177 ms 23988 KB Output is correct
14 Correct 1 ms 496 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 4 ms 964 KB Output is correct
17 Correct 96 ms 14288 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 41 ms 6384 KB Output is correct
21 Correct 177 ms 24012 KB Output is correct
22 Correct 197 ms 23972 KB Output is correct
23 Correct 192 ms 23976 KB Output is correct
24 Correct 174 ms 24120 KB Output is correct
25 Correct 99 ms 14160 KB Output is correct
26 Correct 69 ms 14164 KB Output is correct
27 Correct 171 ms 24216 KB Output is correct
28 Correct 163 ms 24072 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 344 KB Output is correct
32 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -