Submission #482860

# Submission time Handle Problem Language Result Execution time Memory
482860 2021-10-26T15:45:22 Z jalsol Connecting Supertrees (IOI20_supertrees) C++17
0 / 100
1 ms 204 KB
#ifdef LOCAL
#include "local.h"
#else
#include <bits/stdc++.h>
#define debug(...)
#define DB(...)
#endif

using namespace std;

const bool __initialization = []() {
    cin.tie(nullptr)->sync_with_stdio(false);
    cout << setprecision(12) << fixed;
    return true;
}();

using ll = long long;
using ld = long double;

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

#define For(i, l, r) for (int i = (l); i <= (r); ++i)
#define Ford(i, r, l) for (int i = (r); i >= (l); --i)
#define Rep(i, n) For (i, 0, (n) - 1)
#define Repd(i, n) Ford (i, (n) - 1, 0)
#define Fe(...) for (auto __VA_ARGS__)

template <class C> inline int isz(const C& c) { return static_cast<int>(c.size()); }
template <class T> inline bool chmin(T& a, const T& b) { return (a > b) ? a = b, true : false; }
template <class T> inline bool chmax(T& a, const T& b) { return (a < b) ? a = b, true : false; }

constexpr ld eps = 1e-9;
constexpr int inf = 1e9;
constexpr ll linf = 1e18;

// =============================================================================

#include "supertrees.h"

constexpr int maxn = 3e5 + 5;

vector<vector<int>> ans;
vector<int> par;
vector<int> deg;

int find(int x) {
    return (par[x] < 0) ? x : (par[x] = find(par[x]));
}

bool merge(int u, int v) {
    u = find(u), v = find(v);
    if (u == v) return false;

    if (par[v] < par[u]) swap(u, v);
    par[u] += par[v];
    par[v] = u;
    return true;
}

bool same(int u, int v) {
    return find(u) == find(v);
}

int construct(vector<vector<int>> req) {
	int n = req.size();
    ans.assign(n, vector<int>(n));
    par.assign(n, -1);
    deg.assign(n, 0);

    Rep (i, n) {
        For (j, i + 1, n - 1) {
            if (!req[i][j]) continue;

            if (merge(i, j)) {
                ans[i][j] = ans[j][i] = 1;
                ++deg[i], ++deg[j];
            }
        }
    }

    Rep (i, n) {
        For (j, i + 1, n - 1) {
            if (!req[i][j]) continue;

            if (same(i, j) && deg[i] == 1 && deg[j] == 1) {
                ans[i][j] = ans[j][i] = 1;
            }
        }
    }

    Rep (i, n) {
        For (j, i + 1, n - 1) {
            if (!!req[i][j] != same(i, j)) {
                return 0;
            }
        }
    }

	build(ans);
	return 1;
}

// does oj.uz allow IOI-style scoring?
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 0 ms 204 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 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 0 ms 204 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 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Incorrect 0 ms 204 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 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 0 ms 204 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 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 0 ms 204 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 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Too many ways to get from 0 to 2, should be 1 found no less than 2
4 Halted 0 ms 0 KB -