Submission #718723

#TimeUsernameProblemLanguageResultExecution timeMemory
718723baojiaopisuConnecting Supertrees (IOI20_supertrees)C++14
Compilation error
0 ms0 KiB
#include "supertrees.h"
#include<bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;

#define fi first
#define se second
#define left BAO
#define right ANH
#define pb push_back
#define pf push_front
#define mp make_pair
#define ins insert
#define btpc __builtin_popcount
#define btclz __builtin_clz

#define sz(x) (int)(x.size());
#define all(x) x.begin(), x.end()
#define debug(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int d4x[4] = {1, 0, -1, 0}; int d4y[4] = {0, 1, 0, -1};
int d8x[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int d8y[8] = {1, 1, 0, -1, -1, -1, 0, 1};

template<class X, class Y>
    bool minimize(X &x, const Y &y) {
        if (x > y)
        {
            x = y;
            return true;
        }
        return false;
    }
template<class X, class Y>
    bool maximize(X &x, const Y &y) {
        if (x < y)
        {
            x = y;
            return true;
        }
        return false;
    }

const int MOD = 1e9 + 7; //998244353

template<class X, class Y>
	void add(X &x, const Y &y) {
		x = (x + y);
		if(x >= MOD) x -= MOD;
	}

template<class X, class Y> 
	void sub(X &x, const Y &y) {
		x = (x - y);
		if(x < 0) x += MOD;
	}

/* Author : Le Ngoc Bao Anh, 12A5, LQD High School for Gifted Student*/

const ll INF = 1e9;
const int N = 1e5 + 10;

int par[N];
bool ok[N];
int curr[N];
int find_par(int u) {
	if(par[u] < 0) return u;
	par[u] = find_par(par[u]);
	return par[u];
}
bool merge(int u, int v) {
	u = find_par(u), v = find_par(v);
	if(u == v) return false;
	if(par[u] > par[v]) swap(u, v);
	par[u] += par[v];
	par[v] = u;
	return true;
}

int construct(vector<vector<int>> p) {
	int n = p.size();
	vector<vector<int>> ans(n, vector<int>(n, 0));

	for(int i = 0; i < n; i++) par[i] = -1;
	for(int i = 0; i < n; i++) {
		if(p[i][i] != 1) return 0;
		for(int j = 0; j < n; j++) {
			if(p[i][j] > 2) return 0;
			if(p[i][j] == 1) {
				if(merge(i, j)) ans[i][j] = ans[j][i] = 1;
			}
		}
	}

	for(int i = 0; i < n; i++) {
		for(int j = i + 1; j < n; j++) {
			if(find_par(i) == find_par(j) && p[i][j] != 1) return 0;
		}
	}

	for(int i = 0; i < n; i++) curr[i] = -1;
	for(int i = 0; i < n; i++) {
		if(find_par(i) == i && !ok[i]) {
			vector<int> root;
			root.pb(i);
			for(int j = i + 1; j < n; j++) {
				if(find_par(j) == j && p[i][j] == 2) {
					root.pb(j);
				}
			}

			vector<int> node;	
			for(auto x : root) curr[x] = i, ok[x] = true;
			for(int j = 0; j < n; j++) if(curr[find_par(j)] == i) node.pb(j);

			if(root.size() == 2) return 0;
			if(root.size() > 1) {
				for(int j = 0; j < root.size(); j++) {
					int u = root[j];
					int v = root[(j + 1) % root.size()];
					ans[u][v] = ans[v][u] = true;
				}
			}

			for(int i = 0; i < root.size(); i++) {
				for(int j = i + 1; j < root.size(); j++) {
					if(p[root[i]][root[j]] != 2) return 0;
				}
			}

			for(int j = 0; j < node.size(); j++) {
				for(int k = j + 1; k < node.size(); k++) {
					int u = node[j];
					int v = node[k];
					if(find_par(u) != find_par(v) && p[u][v] != 2) {
						return 0;
					}
				}
			}

			for(int j = 0; j < node.size(); j++) {
				for(int k = j + 1; k < node.size(); k++) {
					int u = node[j];
					int v = node[k];
					merge(u, v);
				}
			}
		}
	}

	for(int i = 0; i < n; i++) {
		for(int j = i + 1; j < n; j++) {
			if(find_par(i) != find_par(j) && p[u][v] > 0) return 0;
		}
	}

	build(ans);
	return 1;
}

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:128:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  128 |     for(int j = 0; j < root.size(); j++) {
      |                    ~~^~~~~~~~~~~~~
supertrees.cpp:135:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  135 |    for(int i = 0; i < root.size(); i++) {
      |                   ~~^~~~~~~~~~~~~
supertrees.cpp:136:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  136 |     for(int j = i + 1; j < root.size(); j++) {
      |                        ~~^~~~~~~~~~~~~
supertrees.cpp:141:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  141 |    for(int j = 0; j < node.size(); j++) {
      |                   ~~^~~~~~~~~~~~~
supertrees.cpp:142:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  142 |     for(int k = j + 1; k < node.size(); k++) {
      |                        ~~^~~~~~~~~~~~~
supertrees.cpp:151:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  151 |    for(int j = 0; j < node.size(); j++) {
      |                   ~~^~~~~~~~~~~~~
supertrees.cpp:152:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  152 |     for(int k = j + 1; k < node.size(); k++) {
      |                        ~~^~~~~~~~~~~~~
supertrees.cpp:163:39: error: 'u' was not declared in this scope
  163 |    if(find_par(i) != find_par(j) && p[u][v] > 0) return 0;
      |                                       ^
supertrees.cpp:163:42: error: 'v' was not declared in this scope
  163 |    if(find_par(i) != find_par(j) && p[u][v] > 0) return 0;
      |                                          ^