제출 #638687

#제출 시각아이디문제언어결과실행 시간메모리
638687_petar_b슈퍼트리 잇기 (IOI20_supertrees)C++14
0 / 100
1239 ms1971704 KiB
#include "supertrees.h"
#include <bits/stdc++.h>
#define MAXN 1010

using namespace std;

int graph[MAXN], graph_count = 1, krak[MAXN];

int dfs(int node, vector<vector<int>> p)
{
    graph[node] = graph_count;
    int r = 0;
    for (int i = 0; i < p.size(); i++) if (p[node][i])
    {
        if (graph[i] != 0 && graph[i] < graph[node] || p[node][i] == 3) return 1;
        if (graph[i] == 0) r = dfs(i, p);
    }
    return r;
}

int construct(std::vector<std::vector<int>> p) {
	int n = p.size();
	std::vector<std::vector<int>> answer;
	for (int i = 0; i < n; i++) {
		std::vector<int> row;
		row.resize(n, 0);
		answer.push_back(row);
	}
	//
	for (int i = 0; i < n; i++) if (graph[i] == 0)
    {
        int r = dfs(i, p);
        if (r) return 0;
        graph_count++;
    }
    //
    vector<vector<int>> kraci;
    vector<int> empt; kraci.push_back(empt);
    vector<vector<int>> ciklusi;
    ciklusi.resize(graph_count);
    for (int i = 0 ; i < n; i++)
    {
        bool all2 = true, all0 = true;
        for (int j = 0; j < n; j++) if (j != i)
        {
            if (p[i][j] == 2) all0 = false;
            if (p[i][j] == 1 && graph[i] == graph[j])
            {
                all2 = false;
                all0 = false;
                if (krak[i] == 0)
                {
                    krak[i] = krak[j];
                }
                else if (krak[j] != 0 && krak[i] != krak[j])
                    return 0;
            }
        }
        if (all0)
            ;
        else if (all2)
        {
            ciklusi[graph[i]].push_back(i);
        }
        else
        {
            if (krak[i] == 0)
            {
                empt.push_back(i);
                kraci.push_back(empt);
                krak[i] = kraci.size() - 1;
                empt.clear();
            }
            else
                kraci[krak[i]].push_back(i);
        }
    }
    vector<int> first;
    first.resize(graph_count, -1);
    vector<int> last;
    last.resize(graph_count, -1);
    for (int i = 1; i < graph_count; i++) if (!ciklusi[i].empty())
    {
        first[i] = ciklusi[i][0];
        last[i] = ciklusi[i][0];
        for (int j = 1; j < ciklusi[i].size(); j++)
        {
            answer[last[i]][ciklusi[i][j]] = 1;
            answer[ciklusi[i][j]][last[i]] = 1;
            last[i] = ciklusi[i][j];
        }
    }
    for (int i = 1; i < kraci.size(); i++)
    {
        int elm = kraci[i][0];
        if (first[graph[elm]] == -1)
        {
            first[graph[elm]] = elm;
            last[graph[elm]] = elm;
        }
        else
        {
            answer[last[graph[elm]]][elm] = 1;
            answer[elm][last[graph[elm]]] = 1;
            last[graph[elm]] = elm;
        }
        for (int j = 1; j < kraci[i].size(); j++)
        {
            answer[kraci[i][j-1]][kraci[i][j]] = 1;
            answer[kraci[i][j]][kraci[i][j-1]] = 1;
        }
    }
    for (int i = 1; i < graph_count; i++)
        if (first[i] != last[i])
        {
            answer[first[i]][last[i]] = 1;
            answer[last[i]][first[i]] = 1;
        }
	build(answer);
	return 1;
}

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

supertrees.cpp: In function 'int dfs(int, std::vector<std::vector<int> >)':
supertrees.cpp:13:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     for (int i = 0; i < p.size(); i++) if (p[node][i])
      |                     ~~^~~~~~~~~~
supertrees.cpp:15:27: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   15 |         if (graph[i] != 0 && graph[i] < graph[node] || p[node][i] == 3) return 1;
      |             ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:86:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |         for (int j = 1; j < ciklusi[i].size(); j++)
      |                         ~~^~~~~~~~~~~~~~~~~~~
supertrees.cpp:93:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |     for (int i = 1; i < kraci.size(); i++)
      |                     ~~^~~~~~~~~~~~~~
supertrees.cpp:107:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  107 |         for (int j = 1; j < kraci[i].size(); j++)
      |                         ~~^~~~~~~~~~~~~~~~~
supertrees.cpp:113:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  113 |     for (int i = 1; i < graph_count; i++)
      |     ^~~
supertrees.cpp:119:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  119 |  build(answer);
      |  ^~~~~
#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...