Submission #301187

# Submission time Handle Problem Language Result Execution time Memory
301187 2020-09-17T17:30:23 Z M4mou Connecting Supertrees (IOI20_supertrees) C++17
0 / 100
1 ms 384 KB
#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;

#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define inf 1000000000
#define sz(x) (ll)x.size()
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef long long ll;
typedef unsigned long long ull;
typedef  double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair< int , pii> piii;
typedef pair<int,bool> pib;
typedef vector<pii> vii;
typedef vector<pib> vib;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<string,string> pss;
typedef vector<pss> vss;
typedef pair<ld , ld> pdd;
typedef vector<ld> vd;
typedef vector<vector<pib>> vvib;
typedef vector<piii> viii;
typedef vector<viii> vviii;
typedef vector<bool> vb;
typedef pair<pii , bool> piib;
typedef vector<pair<pii , bool>> viib;
const int MOD = 1e9 + 7; //998244353;
const int MAXN = 100005;

int n;
struct UnionFind{
public:
    vi par;
    UnionFind(){
        for(int i = 0;i<n;i++)par[i] = i;
    }
    void init(){
        for(int i = 0;i<n;i++)par[i] = i;
    }
    int findset(int x){
        if(par[x] == x)return x;
        return par[x] = findset(par[x]);
    }
    void Union(int x , int y){
        x = findset(x);
        y = findset(y);
        if(x != y){
            par[x] = y;
        }
    }
};

UnionFind components;
UnionFind branches;

vvi ans;
bool v[1005];
int construct(vvi p){
    assert(true);
    n = p.size();
    ans.assign(n ,vi(n ,0));
    components.init();
    branches.init();
    memset(v , 0 , 1005);
    for(int i = 0;i<n;i++){
        for(int j = 0;j<n;j++){
            if(p[i][j] == 3)return 0;
            if(p[i][j] >= 1)components.Union(i, j);
            if(p[i][j] == 1)branches.Union(i,j);
        }
    }

    for(int i = 0;i<n;i++){
        for(int j = 0;j<n;j++){
            if(p[i][j] == 0){
                if(components.findset(i) == components.findset(j))return 0;
            }
            if(p[i][j] == 2 && branches.findset(i) == branches.findset(j))return 0;
        }
    }

    for(int i = 0;i<n;i++){
        int x = branches.findset(i);
        if(v[x])continue;
        vi res;

        for(int j = 0;j<n;j++){
            if(branches.findset(j) == x)res.pb(j);
        }
        v[x] = 1;
        if(res.size() <= 1)continue;
        for(int j = 0;j<res.size()-1;j++){
            ans[res[j]][res[j+1]] = 1;
            ans[res[j+1]][res[j]] = 1;
        }
    }
    memset(v , 0 , 1005);
    for(int i = 0;i<n;i++){
        int x = components.findset(i);
        if(v[x])continue;
        v[x] = 1;
        vi res;
        for(int j = 0;j<n;j++){
            int y = branches.findset(j);
            if(components.findset(y) == x)res.pb(y);
        }
        if(res.size() <= 1)continue;
        for(int j = 0;j<res.size()-1;j++){
            ans[res[j]][res[j+1]] = 1;
            ans[res[j+1]][res[j]] = 1;
        }
        ans[res.front()][res.back()] = 1;
        ans[res.back()][res.front()] = 1;
    }
    build(ans);

    return 1;
}

//NEVER GIVE UP
//LONG LONG

Compilation message

supertrees.cpp: In function 'int construct(vvi)':
supertrees.cpp:101:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |         for(int j = 0;j<res.size()-1;j++){
      |                       ~^~~~~~~~~~~~~
supertrees.cpp:117:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  117 |         for(int j = 0;j<res.size()-1;j++){
      |                       ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 384 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 384 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 384 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 384 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 384 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 384 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -