Submission #813001

# Submission time Handle Problem Language Result Execution time Memory
813001 2023-08-07T12:36:56 Z OrazB Connecting Supertrees (IOI20_supertrees) C++14
0 / 100
1 ms 340 KB
#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
#define ll long long int
#define pii pair <int, int>
#define pb push_back
#define ff first
#define ss second

const int N = 1e3+5;
int T, vis[N][N], cur[N], tp[N];
set<int> A[N], B[N];

int F1(int n, int i, vector<vector<int>> p, vector<vector<int>> b){
	if (A[cur[i]].find(i) != A[cur[i]].end()) return p[tp[i]] == p[i];
	for (int j = 0; j < n; j++){
		if (i == j) continue;
		if (vis[cur[i]][j] != (p[i][j] == 0)) return 0;
		if (p[i][j] == 1){
			tp[j] = i;
			A[cur[i]].insert(j);
			B[cur[i]].erase(j);
			b[i][j] = b[j][i] = 1;
		}
	}
	return 1;
}

void F2(int n, int i, vector<vector<int>> p, vector<vector<int>> b){
	++T;
	B[T].insert(i);
	for (int j = 0; j < n; j++){
		if (i == j) continue;
		if (p[i][j] == 0) vis[T][j] = 1;
		else{
			cur[j] = T;
			if (p[i][j] == 1){
				tp[j] = i;
				A[T].insert(j);
				b[i][j] = b[j][i] = 1;
			}else B[T].insert(j);
		}
	}
}

// void build(vector<vector<int>> p){
// 	int n = p.size();
// 	for (int i = 0; i < n; i++){
// 		for (int j = 0; j < n; j++) cout << p[i][j] << " ";
// 		cout << '\n';
// 	}
// }

int construct(vector<vector<int>> p){
	int n = p.size();
	vector<vector<int>> b(n, vector<int>(n));
	for (int i = 0; i < n; i++){
		if (count(all(p[i]), 3)) return 0; 
		if (cur[i]){
			int x = F1(n, i, p, b);
			if (!x) return 0;
		}else F2(n, i, p, b);
	}
	for (int i = 1; i <= T; i++){
		if (B[i].size() <= 1) continue;
		int lst = *B[i].rbegin();
		for (auto j : B[i]){
			b[lst][j] = b[j][lst] = 1;
			lst = j;
		}
	}
	build(b);
	return 1;

}

// int main ()
// {
// 	ios::sync_with_stdio(false);
// 	cin.tie(0);
// 	int n;
// 	cin >> n;
// 	vector<vector<int>> p(n, vector<int>(n));
// 	for (int i = 0; i < n; i++){
// 		for (int j = 0; j < n; j++) cin >> p[i][j];
// 	}
// 	cout << construct(p);
// }	
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 0 ms 340 KB Too few ways to get from 0 to 1, should be 1 found 0
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 0 ms 340 KB Too few ways to get from 0 to 1, should be 1 found 0
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Incorrect 0 ms 340 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 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Incorrect 0 ms 340 KB Too few ways to get from 1 to 2, should be 1 found 0
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 0 ms 340 KB Too few ways to get from 0 to 1, should be 1 found 0
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 0 ms 340 KB Too few ways to get from 0 to 1, should be 1 found 0
3 Halted 0 ms 0 KB -