제출 #591183

#제출 시각아이디문제언어결과실행 시간메모리
591183SirCovidThe19th슈퍼트리 잇기 (IOI20_supertrees)C++17
56 / 100
203 ms22092 KiB
#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;

#define FOR(i, x, y) for (int i = x; i < y; i++)

int construct(vector<vector<int>> p){
    int n = p.size();
    FOR(i, 0, n) FOR(j, 0, n) if (p[i][j] == 3) return 0;

    vector<vector<int>> ans(n, vector<int>(n, 0));
    bool vis[n] = {}; 
    int par[n]; iota(par, par + n, 0);

    function<int(int)> get = [&](int i){
        return i == par[i] ? i : par[i] = get(par[i]);
    };
    auto merge = [&](int a, int b){
        par[get(a)] = get(b);
    };
    FOR(src, 0, n) if (!vis[src]){
        bool incmp[n] = {}; vector<int> cmp; 
        FOR(i, 0, n) if (p[src][i])
            cmp.push_back(i), incmp[i] = 1;
    
        for (int i : cmp) for (int j : cmp) 
            if (p[i][j] == 1) merge(i, j);
            
        for (int i : cmp){ //check
            if (vis[i]) return 0;
            FOR(j, 0, n)
                if (p[i][j] and !incmp[j]) return 0;
            for (int j : cmp)
                if (!((get(i) == get(j) and p[i][j] == 1) or (get(i) != get(j) and p[i][j] == 2)))
                    return 0;
        }
        for (int i : cmp) vis[i] = 1;

        bool use[n] = {}; vector<int> head;
        for (int i : cmp){
            int c = get(i);
            if (!use[c]) head.push_back(c), use[c] = 1;
            if (i != c) ans[i][c] = ans[c][i] = 1;
        }
        FOR(i, 0, head.size()){
            int a = head[i];
            int b = head[(i + 1) % head.size()];
            if (a != b) ans[a][b] = ans[b][a] = 1;
        }
        if (!head.size()) return 0; //cannot have cycle of length 2
    }
    build(ans);
    return 1;
}

컴파일 시 표준 에러 (stderr) 메시지

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:5:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    5 | #define FOR(i, x, y) for (int i = x; i < y; i++)
......
   45 |         FOR(i, 0, head.size()){
      |             ~~~~~~~~~~~~~~~~~           
supertrees.cpp:45:9: note: in expansion of macro 'FOR'
   45 |         FOR(i, 0, head.size()){
      |         ^~~
#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...