Submission #603752

#TimeUsernameProblemLanguageResultExecution timeMemory
603752lcjConnecting Supertrees (IOI20_supertrees)C++17
0 / 100
1 ms212 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;
        for (int j = 0; j < n; j++)
        {
            if (p[i][j] == 0) continue;
            if (assigned[j]) {
                return 0;
            }
            cgroup.push_back(j);
            assigned[j] = 1;
        }
        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;
            for (int j : g) {
                if (p[i][j] == 2) continue;
                if (br[i]) return 0;
                branch.push_back(j);
                br[j] = 1;
            }
            branches.push_back(branch);
        }
        for (int i = 0; i < branches.size(); i++)
        {
            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:47:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         for (int i = 0; i < branches.size(); i++)
      |                         ~~^~~~~~~~~~~~~~~~~
supertrees.cpp:50:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |             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...