제출 #1232748

#제출 시각아이디문제언어결과실행 시간메모리
1232748zeeman01슈퍼트리 잇기 (IOI20_supertrees)C++20
11 / 100
112 ms22376 KiB
#include<bits/stdc++.h>
#include "supertrees.h"
#include <vector>
using namespace std;
vector<int> one , two;
int ek , dui , uttor , par[10001] , vis[1001];

vector<int> adj[10001];

int construct(vector<vector<int>> p) {
    uttor = 1;
    int n = p.size();
    one.clear();
    two.clear();
    for( int z = 0; z < n; z++ ) {
        ek = 0;
        dui = 0;
        for( int y = 0; y < n; y++ ) {
            if( y != z ) {
                if( p[z][y] == 1 ) ek++;
                else if( p[z][y] == 2 ) dui++;
                else uttor = -1;
            }

        }
        if( ek > 0 || dui > 0  ) {
            if( ek > 0 ) one.push_back(z);
            if(dui > 0 ) two.push_back(z);
        } 
    }
    vector<vector<int>> ans;
    for( int z = 0; z < n; z++ ) {
        vector<int> lmao(n , 0);
        ans.push_back(lmao);
    }

    for( int z = 0; z < n; z++ ) {
        par[z] = z;
        adj[z] = {z};
        vis[z] = 0;
    }
    for( int z = 0; z < (int)one.size(); z++ ) {
        if( vis[one[z]] == 0 ) {
            vis[one[z]] = 1;
            for( int y = 0; y < n; y++ ) {
                if( y != one[z] ) {
                    if( p[one[z]][y] == 1 ) {
                        vis[y] = 1;
                        par[y] = -1;
                        ans[one[z]][y] = 1;
                        ans[y][one[z]] = 1;
                        for( int x = 0; x < n; x++ ) {
                            if( x != one[z] && x != y ) {
                                if( p[one[z]][x] != p[y][x] ) uttor = -1;
                            }
                        }
                    }
                }
            }
        }
    }

    for( int z = 0; z < dui; z++ ) {
        if( par[two[z]] != -1 && vis[two[z]] != 2 ) {
            int koita = 0;
            int here = two[z];
            vis[here] = 2;
            for( int y = 0; y < n; y++ ) {
                if( p[here][y] == 2 && vis[y] != 2 ) {
                    ans[here][y] = 1;
                    ans[y][here] = 1;
                    for( int x = 0; x < n; x++ ) {
                        if( x != here && x != y ) {
                            if( min( p[here][x] , p[y][x] ) == 0 && max( p[here][x] , p[y][x] ) > 0 ) {
                                uttor = -1;
                            }
                        }
                    }
                    here = y;
                    vis[here] = 2;
                    koita++;
                }
            }
            if( koita < 2 ) uttor = -1;
            ans[here][two[z]] = 1;
            ans[two[z]][here] = 1;
        }
    }

    if( uttor == 1 ) {
    build(ans);
    return 1;
    }
    else return 0;
}
#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...