Submission #697847

#TimeUsernameProblemLanguageResultExecution timeMemory
697847boris_mihovConnecting Supertrees (IOI20_supertrees)C++17
46 / 100
201 ms24084 KiB
#include "supertrees.h"
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>

typedef long long llong;
const int MAXN = 1000 + 10;
const int INF  = 1e9;

bool used[MAXN];
int inComp[MAXN];
std::vector <std::vector <int>> b;

inline void addEdge(int x, int y)
{
    b[x][y] = 1;
    b[y][x] = 1;
}

int construct(std::vector <std::vector <int>> p) 
{
	int n = p.size();
    b.resize(n);

	for (int i = 0 ; i < n ; ++i)
    {
        b[i].resize(n, 0);
        for (int j = 0 ; j < n ; ++j)
        {
            if (p[i][j] == 3)
            {
                return 0;
            }
        }
    }

    std::fill(inComp, inComp + n, -1);
    for (int i = 0 ; i < n ; ++i)
    {
        if (inComp[i] != -1) continue;
        std::vector <int> stick;
        stick.push_back(i);
        inComp[i] = i;

        for (int j = 0 ; j < n ; ++j)
        {
            if (i == j || p[i][j] != 1) continue;
            stick.push_back(j);
            inComp[j] = i;
        }

        for (int j = 1 ; j < stick.size() ; ++j)
        {
            addEdge(stick[j - 1], stick[j]);
        }
    }

    for (int i = 0 ; i < n ; ++i)
    {
        if (used[inComp[i]]) 
        {
            continue;
        }

        std::vector <int> cycle;
        used[inComp[i]] = true;
        cycle.push_back(i);

        for (int j = 0 ; j < n ; ++j)
        {
            if (used[inComp[j]] || p[i][j] != 2) continue;
            cycle.push_back(inComp[j]);
            used[inComp[j]] = true;
        }

        if (cycle.size() == 2) return 0;
        if (cycle.size() == 1) continue;
        for (int j = 1 ; j < (int)cycle.size() ; ++j)
        {
            addEdge(cycle[j - 1], cycle[j]);
        }

        addEdge(i, cycle.back());
    }

    build(b);
	return 1;
}

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:54:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         for (int j = 1 ; j < stick.size() ; ++j)
      |                          ~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...