Submission #431944

# Submission time Handle Problem Language Result Execution time Memory
431944 2021-06-17T17:34:43 Z Blistering_Barnacles Connecting Supertrees (IOI20_supertrees) C++14
0 / 100
1 ms 332 KB
#include "supertrees.h"
#include<bits/stdc++.h>
using namespace std;
typedef int ll;
vector<vector<ll> >ans,v,w;
vector<pair<ll,ll> >op;
ll n,p1[1009],p2[1009];
ll gp1(ll z)
{
    if(p1[z]==z)
        return z;
    return p1[z]=gp1(p1[z]);
}
ll gp2(ll z)
{
    if(p2[z]==z)
        return z;
    return p2[z]=gp2(p2[z]);
}
void mrg1(ll x,ll y)
{
    x=gp1(x),y=gp1(y);
    if(x==y)
        return;
    if(v[y].size()>v[x].size())
        swap(x,y);
    p1[y]=x;
    for(auto z:v[y])
        v[x].push_back(z);
}
void mrg2(ll x,ll y)
{
    x=gp2(x),y=gp2(y);
    if(x==y)
        return;
    p2[y]=x;
}
int construct(vector<vector<int> > pp)
{
    n=pp.size();
    v.resize(n);
    w.resize(n);
    ans.resize(n);
 
    for(ll i=0; i<n; i++)
        ans[i].resize(n);
 
    for(ll i=0; i<n; i++)
        p1[i]=p2[i]=i, v[i].push_back(i);
 
    for(ll i=0; i<n; i++)
        for(ll j=0; j<n; j++)
        {
            if(i==j)
                continue;
            if(pp[i][j]==3)
                return 0;
            if(pp[i][j]==1)
                mrg1(i,j);
            else if(pp[i][j]==2)
                mrg2(i,j);
        }
 
    for(ll i=0; i<n; i++)
    {
        if(p1[i]!=i)
            continue;
        ll x=gp2(i);
        w[x].push_back(i);
        for(ll j=1; j<v[i].size(); j++)
            ans[i][v[i][j]]=ans[v[i][j]][i]=1;
    }
    for(ll i=0; i<n; i++)
    {
        if(p2[i]!=i)
            continue;
        for(ll j=0; j<w[i].size()-1; j++)
            ans[w[i][j]][w[i][j+1]]=ans[w[i][j+1]][w[i][j]]=1;
        ans[w[i][0]][w[i].back()]=ans[w[i].back()][w[i][0]]=1;
    }
    for(ll i=0; i<n; i++)
        for(ll j=0; j<n; j++)
        {
            if(i==j)
                continue;
            ll x=gp1(i),y=gp1(j);
            if(x==y&&pp[i][j]!=1)
                return 0;
            ll xx=gp2(i),yy=gp2(j);
            if(xx==yy&&pp[i][j]==0)
                return 0;
        }
    for(ll i=0; i<n; i++)
        ans[i][i]=0;
    build(ans);
    return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:70:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |         for(ll j=1; j<v[i].size(); j++)
      |                     ~^~~~~~~~~~~~
supertrees.cpp:77:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |         for(ll j=0; j<w[i].size()-1; j++)
      |                     ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Runtime error 1 ms 332 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Runtime error 1 ms 332 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 288 KB Output is correct
4 Incorrect 0 ms 204 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Runtime error 1 ms 332 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Runtime error 1 ms 332 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Runtime error 1 ms 332 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -