Submission #431258

#TimeUsernameProblemLanguageResultExecution timeMemory
431258MOUF_MAHMALATConnecting Supertrees (IOI20_supertrees)C++14
0 / 100
1 ms204 KiB
#include "supertrees.h"
#include<bits/stdc++.h>
using namespace std;
typedef int ll;
vector<vector<ll> >v,w;
vector<pair<ll,ll> >op;
ll n,p[1009];
bool b[1009];
ll gp(ll z)
{
    if(p[z]==z)
        return z;
    return p[z]=gp(p[z]);
}
void mrg(ll x,ll y)
{
    if(w[y].size()>w[x].size())
        swap(x,y);
    p[y]=x;
    for(auto z:w[y])
        w[x].push_back(z);
}
int construct(vector<vector<int> > pp)
{
    n=pp.size();
    v.resize(n);
    w.resize(n);
    
    for(ll i=0; i<n; i++)
        v[i].resize(n);
        
    for(ll i=0; i<n; i++)
        p[i]=i,w[i].push_back(i);
        
    for(ll i=0; i<n; i++)
        for(ll j=0; j<n; j++)
        {
            if(i==j||pp[i][j]==0)
                continue;
            ll x=gp(i),y=gp(j);
            if(x==y)
                continue;
            mrg(x,y);
        }
    for(ll i=0; i<n; i++)
        for(ll j=0; j<n; j++)
        {
            if(pp[i][j]==0||p[i]!=i)
                continue;
            if(w[i].size()<=2)
                return 0;
            for(ll k=0; k<w[i].size(); k++)
                op.push_back({w[i][k],w[i][(k+1)%n]});
        }
    for(ll i=0; i<n; i++)
        for(ll j=0; j<n; j++)
        {
            if(pp[i][j])
                continue;
            ll x=gp(i),y=gp(j);
            if(x==y)
                return 0;
        }
    for(auto z:op)
        v[z.first][z.second]=v[z.second][z.first]=1;
    build(v);
    return 1;
}

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:52:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |             for(ll k=0; k<w[i].size(); k++)
      |                         ~^~~~~~~~~~~~
#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...