Submission #301827

# Submission time Handle Problem Language Result Execution time Memory
301827 2020-09-18T08:37:44 Z SOIVIEONE Connecting Supertrees (IOI20_supertrees) C++14
0 / 100
5 ms 5536 KB
#include "supertrees.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;

int ota[222222], bobo[222222];
int find(int x)
{
    return (ota[x] == x ? x : ota[x] = find(ota[x]));
}

void unite(int x, int y)
{
    x = find(x);
    y = find(y);
    ota[y] = x;
}

int find2(int x)
{
    return (bobo[x] == x ? x : bobo[x] = find2(bobo[x]));
}
vector<int> v[222222];
void unite2(int x, int y)
{
    x = find2(x);
    y = find2(y);
    bobo[y] = x;
}

int construct(std::vector<std::vector<int>> p) {
	int n = p.size();
	std::vector<std::vector<int>> a;
	for (int i = 0; i < n; i++) {
		std::vector<int> row;
		row.resize(n);
		a.push_back(row);
	}
	for(int i = 0; i < n; i ++)
        ota[i] = i;
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j ++)
        {
            if(p[i][j] == 1)
            {
                unite(i, j);
            }
        }
    }

    for(int i = 0; i < n; i ++)
    {
        for(int j = 0; j < n; j ++)
        {
            int foo = find(i), hoo = find(j);
            if(p[i][j] == 2)
            {
                unite2(foo, hoo);
            }
        }
    }
    for(int i = 0; i < n; i ++)
    for(int j = 0; j < n; j ++)
    {
        if(p[i][j] == 3)
            return 0;
        int boboi = find2(i), boboj = find2(j);
        int otai = find(i), otaj = find(j);
        if(otai == otaj && p[i][j] != 1)
            return 0;
        if(otai != otaj && p[i][j] == 1)
            return 0;
        if(boboi == boboj && p[i][j] == 2)
            return 0;
        if(boboi != boboj && p[i][j] != 2)
            return 0;
        if(otai == otaj)
        {
            if(otai != i)
                a[i][otai] = a[otai][i] = 1;
        }
    }
    vector<int> dead(n + 1, 0);
    for(int i = 0; i < n; i ++)
    {
        int o = find(i);
        if(dead[o])
            continue;
        v[bobo[o]].push_back(o);
    }
    for(auto it : v)
    {
        for(int j = 1; j < it.size(); j ++)
        {
            a[it[j]][it[j-1]] = a[it[j-1]][it[j]] = 1;
        }
    }
	build(a);
	return 1;
}
/*
5
1 0 0 1 1
0 1 1 0 0
0 1 1 0 0
1 0 0 1 1
1 0 0 1 1
*/

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:94:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |         for(int j = 1; j < it.size(); j ++)
      |                        ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5504 KB Output is correct
2 Incorrect 4 ms 5504 KB b[0][0] is not 0
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5504 KB Output is correct
2 Incorrect 4 ms 5504 KB b[0][0] is not 0
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 5536 KB Too many ways to get from 0 to 1, should be 0 found no less than 1
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 5504 KB Too many ways to get from 0 to 1, should be 0 found no less than 1
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5504 KB Output is correct
2 Incorrect 4 ms 5504 KB b[0][0] is not 0
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5504 KB Output is correct
2 Incorrect 4 ms 5504 KB b[0][0] is not 0
3 Halted 0 ms 0 KB -