Submission #838046

# Submission time Handle Problem Language Result Execution time Memory
838046 2023-08-26T06:21:06 Z caganyanmaz Connecting Supertrees (IOI20_supertrees) C++17
19 / 100
160 ms 24208 KB
#include <bits/stdc++.h>
#include "supertrees.h"
//#define DEBUGGING
#ifdef DEBUGGING
#include "../debug.h"
#else
#define debug(x...) void(42)
#endif
using namespace std;
constexpr static int MXN = 1e3 + 5;
struct Node
{
	int head, tail, size, nxt;
	Node(int i) : head(i), tail(i), size(1), nxt(-1) {}
	Node() : Node(-1) {}
};
Node node[MXN];

void merge(int a, int b);
int construct(vector<vector<int>> p)
{
	int n = p.size();
	vector<vector<int>> answer(n, vector<int>(n));
	for (int i = 0; i < n; i++) 
		node[i] = Node(i);
	for (int i = 0; i < n; i++)
		for (int j = i+1; j < n; j++)
			if (p[i][j] == 2 && node[i].head != node[j].head)
				merge(node[i].head, node[j].head);
	for (int i = 0; i < n; i++)
		for (int j = i+1; j < n; j++)
			if (!p[i][j] && node[i].head == node[j].head)
				return 0;
	for (int i = 0; i < n; i++)
	{
		if (node[i].head != i || node[i].size == 1)
			continue;
		debug(i, node[i].size);
		if (node[i].size == 2)
			return 0;
		for (int j = i; node[j].nxt != -1; j = node[j].nxt)
		{
			debug(j, node[j].nxt);
			answer[j][node[j].nxt] = answer[node[j].nxt][j] = 1;
		}
		debug(node[i].tail, i);
		answer[i][node[i].tail] = answer[node[i].tail][i] = 1;
	}
	build(answer);
	return 1;
}
void merge(int a, int b)
{
	if (node[a].size < node[b].size) swap(a, b);
	node[a].size += node[b].size;
	node[node[a].tail].nxt = b;
	node[a].tail = node[b].tail;
	for (;b!=-1;b=node[b].nxt)
		node[b].head = a;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 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 212 KB Output is correct
2 Incorrect 0 ms 212 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 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 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 7 ms 1236 KB Output is correct
9 Correct 151 ms 23968 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 6 ms 1236 KB Output is correct
13 Correct 153 ms 23964 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 312 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 74 ms 14012 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 316 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 39 ms 6244 KB Output is correct
22 Correct 150 ms 23952 KB Output is correct
23 Correct 151 ms 24020 KB Output is correct
24 Correct 157 ms 23944 KB Output is correct
25 Correct 60 ms 14084 KB Output is correct
26 Correct 67 ms 14016 KB Output is correct
27 Correct 148 ms 23996 KB Output is correct
28 Correct 160 ms 24208 KB Output is correct
29 Correct 64 ms 14032 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 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 212 KB Output is correct
2 Incorrect 0 ms 212 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 212 KB Output is correct
2 Incorrect 0 ms 212 KB Too few ways to get from 0 to 1, should be 1 found 0
3 Halted 0 ms 0 KB -