제출 #300741

#제출 시각아이디문제언어결과실행 시간메모리
300741IgorI슈퍼트리 잇기 (IOI20_supertrees)C++17
96 / 100
306 ms22264 KiB
#include <bits/stdc++.h>

using namespace std;

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)

void build(vector<vector<int> > b) ;

void build(vector<vector<int> > b) ;

int Root(int x, vector<int> &root)
{
    if (x == root[x]) return x;
    return root[x] = Root(root[x], root);
}

void Merge(int v, int u, vector<int> &root, vector<int> &sz)
{
    v = Root(v, root), u = Root(u, root);
    if (v == u) return;
    if (sz[v] > sz[u]) swap(v, u);
    sz[u] += sz[v];
    root[v] = u;
}

int construct(vector<vector<int> > p)
{
    int n = p.size();
    vector<int> root(n), sz(n);
    for (int i = 0; i < n; i++) root[i] = i, sz[i] = 1;
    int t = 0;
    forn(i, n)
    {
        forn(j, n)
        {
            if (p[i][j])
            {
                Merge(i, j, root, sz);
            }
        }
    }
    forn(i, n)
    {
        forn(j, n)
        {
            if (Root(i, root) == Root(j, root) && p[i][j] == 0)
            {
                return 0;
            }
        }
    }
    vector<vector<int> > b(n, vector<int>(n));
    forn(i, n)
    {
        vector<int> L;
        forn(j, n)
        {
            if (Root(j, root) == i)
            {
                L.push_back(j);
            }
        }
        vector<int> root2(L.size()), sz2(L.size());
        iota(root2.begin(), root2.end(), 0);
        fill(sz2.begin(), sz2.end(), 1);
        for (int a = 0; a < L.size(); a++)
        {
            for (int b = 0; b < L.size(); b++)
            {
                if (p[L[a]][L[b]] == 1)
                {
                    Merge(a, b, root2, sz2);
                }
            }
        }
        for (int a = 0; a < L.size(); a++)
        {
            for (int b = 0; b < L.size(); b++)
            {
                if (p[L[a]][L[b]] == 2 && Root(a, root2) == Root(b, root2))
                    return 0;
            }
        }
        vector<vector<int> > z(L.size());
        for (int a = 0; a < L.size(); a++)
        {
            z[Root(a, root2)].push_back(L[a]);
        }
        vector<int> q;
        for (int j = 0; j < z.size(); j++)
        {
            if (z[j].size()) q.push_back(z[j][0]);
            for (int e = 0; e + 1 < z[j].size(); e++)
            {
                b[z[j][e]][z[j][e + 1]] = 1;
                b[z[j][e + 1]][z[j][e]] = 1;
            }
        }
        if (q.size() == 2)
        {
            return 0;
        }
        if (q.size() > 2)
        for (int i = 0; i < q.size(); i++)
        {
            b[q[i]][q[(i + 1) % q.size()]] = 1;
            b[q[(i + 1) % q.size()]][q[i]] = 1;
        }
    }
    build(b);
    return 1;
}

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

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:5:29: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    5 | #define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
      |                             ^
supertrees.cpp:32:5: note: in expansion of macro 'forn'
   32 |     forn(i, n)
      |     ^~~~
supertrees.cpp:5:29: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    5 | #define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
      |                             ^
supertrees.cpp:34:9: note: in expansion of macro 'forn'
   34 |         forn(j, n)
      |         ^~~~
supertrees.cpp:5:29: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    5 | #define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
      |                             ^
supertrees.cpp:42:5: note: in expansion of macro 'forn'
   42 |     forn(i, n)
      |     ^~~~
supertrees.cpp:5:29: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    5 | #define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
      |                             ^
supertrees.cpp:44:9: note: in expansion of macro 'forn'
   44 |         forn(j, n)
      |         ^~~~
supertrees.cpp:5:29: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    5 | #define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
      |                             ^
supertrees.cpp:53:5: note: in expansion of macro 'forn'
   53 |     forn(i, n)
      |     ^~~~
supertrees.cpp:5:29: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    5 | #define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
      |                             ^
supertrees.cpp:56:9: note: in expansion of macro 'forn'
   56 |         forn(j, n)
      |         ^~~~
supertrees.cpp:66:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |         for (int a = 0; a < L.size(); a++)
      |                         ~~^~~~~~~~~~
supertrees.cpp:68:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |             for (int b = 0; b < L.size(); b++)
      |                             ~~^~~~~~~~~~
supertrees.cpp:76:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |         for (int a = 0; a < L.size(); a++)
      |                         ~~^~~~~~~~~~
supertrees.cpp:78:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |             for (int b = 0; b < L.size(); b++)
      |                             ~~^~~~~~~~~~
supertrees.cpp:85:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |         for (int a = 0; a < L.size(); a++)
      |                         ~~^~~~~~~~~~
supertrees.cpp:90:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |         for (int j = 0; j < z.size(); j++)
      |                         ~~^~~~~~~~~~
supertrees.cpp:93:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |             for (int e = 0; e + 1 < z[j].size(); e++)
      |                             ~~~~~~^~~~~~~~~~~~~
supertrees.cpp:104:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  104 |         for (int i = 0; i < q.size(); i++)
      |                         ~~^~~~~~~~~~
supertrees.cpp:31:9: warning: unused variable 't' [-Wunused-variable]
   31 |     int t = 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...