Submission #597003

# Submission time Handle Problem Language Result Execution time Memory
597003 2022-07-15T11:21:33 Z inventiontime Connecting Supertrees (IOI20_supertrees) C++17
21 / 100
232 ms 24012 KB
#include "supertrees.h"

#include <bits/stdc++.h>
using namespace std;

#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define re resize
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define loop(i, n) for(int i = 0; i < n; i++)
#define loop1(i, n) for(int i = 1; i <= n; i++)
#define print(x) cout << #x << ": " << x << endl << flush

typedef long long ll;
typedef vector<int> vi;
typedef array<int, 2> ii;
typedef array<int, 3> ti;
typedef vector<ii> vii;
typedef vector<ti> vti;
typedef priority_queue<int> pq;

template<class T> bool ckmin(T&a, T b) { bool B = a > b; a = min(a, b); return B; }
template<class T> bool ckmax(T&a, T b) { bool B = a < b; a = max(a, b); return B; }

const int inf = 1e17;
//const int maxn = ;

struct ufds {

	vi par;

	ufds(int n): par(n+1, -1) {}

	int find(int a) {
		while(par[a] >= 0)
			a = par[a];
		return a;
	}

	int size(int a) {
		return -par[find(a)];
	}

    bool disjoint(int a, int b) {
        a = find(a);
        b = find(b);
        return !(a == b);
    }

	bool merge(int a, int b) {
		a = find(a);
		b = find(b);
		if(a == b) return false;
		if(-par[a] < -par[b]) 
			swap(a, b);
		par[a] += par[b];
		par[b] = a;
		return true;
	}

	bool query(int a, int b) {
		a = find(a);
		b = find(b);
		return a == b;
	}

};

int construct(vector<vi> p) {

	int n = p.size();
    ufds ufds(n);

    bool possible = true;

    loop(i, n) loop(j, n) {
        if(p[i][j] == 1)
            ufds.merge(i, j);
    }

    loop(i, n) loop(j, n) {
        if(p[i][j] != 1) if(!ufds.disjoint(i, j))
            possible = false;
    }

    if(!possible) return 0;

	vector<vi> ans(n, vi(n));
    loop(i, n) if(ufds.find(i) == i) {
        loop(j, n) {
            if(!ufds.disjoint(j, i)) if(i != j) {
                ans[i][j] = 1;
                ans[j][i] = 1;
            }
        }
    }
	build(ans);

	return 1;

}

Compilation message

supertrees.cpp:27:17: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+17' to '2147483647' [-Woverflow]
   27 | const int inf = 1e17;
      |                 ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 9 ms 1212 KB Output is correct
7 Correct 175 ms 23912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 9 ms 1212 KB Output is correct
7 Correct 175 ms 23912 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 296 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1236 KB Output is correct
13 Correct 168 ms 23936 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 4 ms 664 KB Output is correct
17 Correct 88 ms 10032 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 41 ms 6256 KB Output is correct
21 Correct 167 ms 23892 KB Output is correct
22 Correct 232 ms 23984 KB Output is correct
23 Correct 169 ms 23924 KB Output is correct
24 Correct 157 ms 24000 KB Output is correct
25 Correct 75 ms 10096 KB Output is correct
26 Correct 93 ms 10108 KB Output is correct
27 Correct 172 ms 23924 KB Output is correct
28 Correct 165 ms 24012 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 Correct 1 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 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 0 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 9 ms 1212 KB Output is correct
7 Correct 175 ms 23912 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 296 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1236 KB Output is correct
13 Correct 168 ms 23936 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 4 ms 664 KB Output is correct
17 Correct 88 ms 10032 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 41 ms 6256 KB Output is correct
21 Correct 167 ms 23892 KB Output is correct
22 Correct 232 ms 23984 KB Output is correct
23 Correct 169 ms 23924 KB Output is correct
24 Correct 157 ms 24000 KB Output is correct
25 Correct 75 ms 10096 KB Output is correct
26 Correct 93 ms 10108 KB Output is correct
27 Correct 172 ms 23924 KB Output is correct
28 Correct 165 ms 24012 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Incorrect 1 ms 212 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 9 ms 1212 KB Output is correct
7 Correct 175 ms 23912 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 296 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1236 KB Output is correct
13 Correct 168 ms 23936 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 4 ms 664 KB Output is correct
17 Correct 88 ms 10032 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 41 ms 6256 KB Output is correct
21 Correct 167 ms 23892 KB Output is correct
22 Correct 232 ms 23984 KB Output is correct
23 Correct 169 ms 23924 KB Output is correct
24 Correct 157 ms 24000 KB Output is correct
25 Correct 75 ms 10096 KB Output is correct
26 Correct 93 ms 10108 KB Output is correct
27 Correct 172 ms 23924 KB Output is correct
28 Correct 165 ms 24012 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Incorrect 1 ms 212 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -