Submission #1051368

# Submission time Handle Problem Language Result Execution time Memory
1051368 2024-08-10T05:24:55 Z pcc Connecting Supertrees (IOI20_supertrees) C++17
21 / 100
142 ms 26196 KB
#include "supertrees.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;

const int mxn = 1010;

struct DSU{
	int dsu[mxn],sz[mxn];
	DSU(){
		iota(dsu,dsu+mxn,0);
		fill(sz,sz+mxn,1);
	}
	int root(int k){
		return k == dsu[k]?k:dsu[k] = root(dsu[k]);
	}
	void onion(int a,int b){
		a = root(a),b = root(b);
		if(a == b)return;
		if(sz[a]<sz[b])swap(a,b);
		dsu[b] = a;
		sz[a] += sz[b];
	}
};

/*
std::vector<std::vector<int>> answer(n,vector<int>(n,0));
build(answer);
return 1;
*/

DSU chain,cyc;
int N;
vector<vector<int>> ans;
vector<vector<int>> tar;
vector<int> v[mxn];

void add_edge(int a,int b){
	assert(a != b);
	ans[a][b] = ans[b][a] = 1;
}

bool check(){
	for(int i = 0;i<N;i++){
		for(int j = 0;j<N;j++){
			if(tar[i][j] == 0){
				if(chain.root(i) == chain.root(j))return false;
			}
			else if(tar[i][j] == 1){
				if(chain.root(i) != chain.root(j))return false;
			}
		}
	}
	return true;
}

int construct(std::vector<std::vector<int>> vvv) {
	tar = vvv;
	N = tar.size();
	for(int i = 0;i<N;i++){
		for(int j = 0;j<N;j++){
			if(tar[i][j] == 1)chain.onion(i,j);
		}
	}
	ans = vector<vector<int>>(N,vector<int>(N,0));
	for(int i = 0;i<N;i++){
		v[chain.root(i)].push_back(i);
	}
	for(int i = 0;i<N;i++){
		for(int j = 1;j<v[i].size();j++){
			add_edge(v[i][j-1],v[i][j]);
		}
	}
	if(!check())return 0;
	build(ans);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:70:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |   for(int j = 1;j<v[i].size();j++){
      |                 ~^~~~~~~~~~~~
# Verdict Execution time Memory 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 0 ms 348 KB Output is correct
6 Correct 5 ms 1372 KB Output is correct
7 Correct 125 ms 26100 KB Output is correct
# Verdict Execution time Memory 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 0 ms 348 KB Output is correct
6 Correct 5 ms 1372 KB Output is correct
7 Correct 125 ms 26100 KB Output is correct
8 Correct 0 ms 600 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 4 ms 1372 KB Output is correct
13 Correct 97 ms 26176 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 1116 KB Output is correct
17 Correct 61 ms 16192 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 28 ms 6748 KB Output is correct
21 Correct 98 ms 25940 KB Output is correct
22 Correct 97 ms 26004 KB Output is correct
23 Correct 103 ms 25936 KB Output is correct
24 Correct 142 ms 26196 KB Output is correct
25 Correct 44 ms 16212 KB Output is correct
26 Correct 41 ms 16208 KB Output is correct
27 Correct 106 ms 26032 KB Output is correct
28 Correct 94 ms 26084 KB Output is correct
# Verdict Execution time Memory 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 -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Incorrect 1 ms 348 KB Too few ways to get from 0 to 1, should be 2 found 0
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 0 ms 348 KB Output is correct
6 Correct 5 ms 1372 KB Output is correct
7 Correct 125 ms 26100 KB Output is correct
8 Correct 0 ms 600 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 4 ms 1372 KB Output is correct
13 Correct 97 ms 26176 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 1116 KB Output is correct
17 Correct 61 ms 16192 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 28 ms 6748 KB Output is correct
21 Correct 98 ms 25940 KB Output is correct
22 Correct 97 ms 26004 KB Output is correct
23 Correct 103 ms 25936 KB Output is correct
24 Correct 142 ms 26196 KB Output is correct
25 Correct 44 ms 16212 KB Output is correct
26 Correct 41 ms 16208 KB Output is correct
27 Correct 106 ms 26032 KB Output is correct
28 Correct 94 ms 26084 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 -
# Verdict Execution time Memory 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 0 ms 348 KB Output is correct
6 Correct 5 ms 1372 KB Output is correct
7 Correct 125 ms 26100 KB Output is correct
8 Correct 0 ms 600 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 4 ms 1372 KB Output is correct
13 Correct 97 ms 26176 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 1116 KB Output is correct
17 Correct 61 ms 16192 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 28 ms 6748 KB Output is correct
21 Correct 98 ms 25940 KB Output is correct
22 Correct 97 ms 26004 KB Output is correct
23 Correct 103 ms 25936 KB Output is correct
24 Correct 142 ms 26196 KB Output is correct
25 Correct 44 ms 16212 KB Output is correct
26 Correct 41 ms 16208 KB Output is correct
27 Correct 106 ms 26032 KB Output is correct
28 Correct 94 ms 26084 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 -