제출 #398415

#제출 시각아이디문제언어결과실행 시간메모리
398415iulia13슈퍼트리 잇기 (IOI20_supertrees)C++14
0 / 100
325 ms389140 KiB
#include <iostream>
#include <vector>
#include "supertrees.h"
using namespace std;
#define pb push_back
const int nmax = 1005;
vector <int> comp;
vector <int> comp2;
vector <int> ciclu;
vector <int> g[nmax];
vector <int> G[nmax];
int viz[nmax], viz2[nmax];
void dfs(int nod)
{
    comp.pb(nod);
    viz[nod] = 1;
    for (auto x : g[nod])
        if (!viz[x])
            dfs(x);
}
void dfs2(int nod)
{
    comp2.pb(nod);
    viz2[nod] = 1;
    for (auto x : G[nod])
        if (!viz2[x])
            dfs2(x);
}/*
void build(vector < vector <int> > ans)
{
    int n = ans.size();
    for (int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++)
            cout << ans[i][j] << " ";
        cout << endl;
    }
}*/
int construct (vector < vector <int> > p)
{
    int n = p.size();
    vector<vector<int>> ans;
    ans.resize(n);
    int i, j;
    for (i = 0; i < n; i++)
    {
        ans[i].resize(n);
        for (j = i + 1; j < n; j++)
        {
            if (p[i][j] == 3)
                return 0;
            if (p[i][j])
            {
                g[i].pb(j);
                g[j].pb(i);
            }
        }
    }
    for (int iii = 0; iii < n; iii++)
    {
        if (viz[iii])
            continue;
        ciclu.clear();
        comp.clear();
        dfs(iii);
        int x = comp.size();
        for (i = 0; i < x; i++)
            for (j = 1 + i; j < x; j++)
            {
                int ii = comp[i];
                int jj = comp[j];
                if (!p[ii][jj])
                    return 0;
                if (p[ii][jj] == 1)
                {
                    G[ii].pb(jj);
                    G[jj].pb(ii);
                }
            }
        for (int ii = 0; ii < x; ii++)
        {
            i = comp[ii];
            if (viz2[i])
                continue;
            comp2.clear();
            dfs2(i);
            int x2 = comp2.size();
            for (i = 0; i < x2 - 1; i++)
            {
                int a = comp[i];
                int b = comp[i + 1];
                ans[a][b] = 1;
                ans[b][a] = 1;
            }
            ciclu.pb(comp2[0]);
        }
        int x2 = ciclu.size();
        if (x2 == 2)
            return 0;
        if (x2 < 2)
            continue;
        for (i = 0; i < x2 - 1; i++)
        {
            ans[ciclu[i]][ciclu[i + 1]] = 1;
            ans[ciclu[i + 1]][ciclu[i]] = 1;
        }
        x2--;
        ans[ciclu[0]][ciclu[x2]] = 1;
        ans[ciclu[x2]][ciclu[0]] = 1;
    }
    build(ans);
}/*
int main()
{
    int n, i, j;
    cin >> n;
    vector <vector <int>> p;
    p.resize(n);
    for (i = 0; i < n; i++)
        p[i].resize(n);
    for (i = 0; i < n; i++)
        for (j = 0; j < n; j++)
            cin >> p[i][j];
    construct(p);
    return 0;
}*/

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

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:42:25: warning: control reaches end of non-void function [-Wreturn-type]
   42 |     vector<vector<int>> ans;
      |                         ^~~
#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...