Submission #603767

#TimeUsernameProblemLanguageResultExecution timeMemory
603767lcjConnecting Supertrees (IOI20_supertrees)C++17
56 / 100
244 ms22064 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

#include "supertrees.h"

#define con(a, b) answer[a][b] = 1;answer[b][a] = 1;

int construct(vector<vector<int>> p) {
	int n = p.size();
    vector<vector<int>> answer(n, vector<int>(n, 0));
    vector<vector<int>> groups;
    vector<bool> assigned(n, 0);
    for (int i = 0; i < n; i++)
    {
        if (assigned[i]) continue;
        vector<int> cgroup;
        vector<bool> ingroup(n, 0);
        for (int j = 0; j < n; j++)
        {
            if (p[i][j] == 0) continue;
            if (assigned[j]) {
                return 0;
            }
            ingroup[j] = 1;
            cgroup.push_back(j);
            assigned[j] = 1;
        }
        for (int j : cgroup) {
            for (int k = 0; k < n; k++)
            {
                if (ingroup[k] != (bool)p[j][k]) {
                    return 0;
                }
            }
        }
        groups.push_back(cgroup);
    }
    for (auto &g : groups) {
        vector<vector<int>> branches;
        vector<bool> br(n, 0);
        for (int i : g) {
            if (br[i]) continue;
            vector<int> branch;
            vector<bool> inbranch(n, 0);
            for (int j : g) {
                if (p[i][j] == 2 && i != j) continue;
                if (br[j]) return 0;
                inbranch[j] = 1;
                branch.push_back(j);
                br[j] = 1;
            }
            for (int j : branch) {
                for (int k : g) {
                    if (inbranch[k] != (p[j][k] == 1)) {
                        return 0;
                    }
                }
            }
            branches.push_back(branch);
        }
        for (int i = 0; i < branches.size(); i++)
        {
            if (branches.size() != 1) {
                con(branches[i][0], branches[(i+1)%branches.size()][0])
            }
            for (int j = 0; j < branches[i].size()-1; j++)
            {
                con(branches[i][j], branches[i][j+1])
            }
        }
        
    }
	build(answer);
	return 1;
}

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:66:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |         for (int i = 0; i < branches.size(); i++)
      |                         ~~^~~~~~~~~~~~~~~~~
supertrees.cpp:71:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |             for (int j = 0; j < branches[i].size()-1; 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...