Submission #771515

# Submission time Handle Problem Language Result Execution time Memory
771515 2023-07-03T05:43:14 Z ono_de206 Connecting Supertrees (IOI20_supertrees) C++14
19 / 100
226 ms 22124 KB
#include "supertrees.h"
#include<bits/stdc++.h>
using namespace std;

#define in insert
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second

// #define int long long
 
typedef long long ll;
typedef vector<int> vi;
typedef set<int> si;
typedef multiset<int> msi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

const int mxn = 1010;
int par[mxn];

int get(int x) {
	return (x == par[x] ? x : par[x] = get(par[x]));
}

void unite(int x, int y) {
	x = get(x); y = get(y);
	if(x == y) return;
	par[y] = x;
}

void setDsu(int n) {
	for(int i = 0; i < n; i++) {
		par[i] = i;
	}
}

int construct(vector<vector<int>> p) {
	int n = p.size();
	vector<vector<int>> answer(n, vector<int>(n));
	//1
	setDsu(n);
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			if(p[i][j] != 0) {
				unite(i, j);
			}
		}
	}
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			if(get(i) == get(j) && p[i][j] == 0) {
				return 0;
			}
		}
	}
	//2
	setDsu(n);
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			if(p[i][j] == 1) {
				unite(i, j);
			}
		}
	}
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			if(get(i) == get(j) && p[i][j] == 2) {
				return 0;
			}
		}
	}
	//3
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			if(p[i][j] == 3) {
				return 0;
			}
		}
	}
	//----------
	auto link = [&](int x, int y) -> void {
		if(x == y) return;
		answer[x][y] = answer[y][x] = 1;
	};
	vector<int> vis(n);
	for(int i = 0; i < n; i++) {
		if(vis[i]) continue;
		vector<int> line{i};
		vis[i] = 1;
		for(int j = i + 1; j < n; j++) {
			if(get(i) == get(j)) line.pb(j), vis[j] = 1;
		}
		set<int> s;
		for(int j = 0; j < n; j++) {
			if(p[i][j] == 2) {
				s.in(get(j));
			}
		}
		s.in(i);
		if(s.size() == 2) {
			return 0;
		}
		line.pb(line[0]);
		for(int j = 0; j + 1 < line.size(); j++) {
			link(line[j], line[j + 1]);
		}
		int ls = *s.rbegin();
		for(int x : s) {
			link(x, ls);
			ls = x;
		}
	}
	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:107:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  107 |   for(int j = 0; j + 1 < line.size(); j++) {
      |                  ~~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Too many ways to get from 0 to 2, should be 1 found no less than 2
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Too many ways to get from 0 to 2, should be 1 found no less than 2
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 8 ms 1172 KB Output is correct
9 Correct 156 ms 21960 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 1108 KB Output is correct
13 Correct 226 ms 22124 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 72 ms 12040 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 41 ms 5664 KB Output is correct
22 Correct 171 ms 22120 KB Output is correct
23 Correct 159 ms 21960 KB Output is correct
24 Correct 198 ms 22064 KB Output is correct
25 Correct 70 ms 12036 KB Output is correct
26 Correct 64 ms 12052 KB Output is correct
27 Correct 165 ms 21996 KB Output is correct
28 Correct 199 ms 22072 KB Output is correct
29 Correct 71 ms 12036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Too many ways to get from 1 to 4, should be 1 found no less than 2
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Too many ways to get from 0 to 2, should be 1 found no less than 2
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Too many ways to get from 0 to 2, should be 1 found no less than 2
4 Halted 0 ms 0 KB -