제출 #309004

#제출 시각아이디문제언어결과실행 시간메모리
309004tjdgus4384Connecting Supertrees (IOI20_supertrees)C++14
21 / 100
279 ms34208 KiB
#include<bits/stdc++.h>
#include "supertrees.h"
using namespace std;
vector<int> graph[1001], trees[1001];
vector<vector<int> > b, P, newp;
vector<int> v[1001];
vector<int> sametree;
bool visited[1001];

void dfs(int x, int cnt){
    graph[cnt].push_back(x);
    for(int i = 0;i < v[x].size();i++){
        if(visited[v[x][i]]) continue;
        visited[v[x][i]] = true;
        dfs(v[x][i], cnt);
    }
}

void make_tree(int x){
    for(int i = 0;i < v[x].size();i++){
        if(visited[v[x][i]]) continue;
        if(P[x][v[x][i]] != 1) continue;
        visited[v[x][i]] = true;
        sametree.push_back(v[x][i]);
        make_tree(v[x][i]);
        b[x][v[x][i]] = 1;
        b[v[x][i]][x] = 1;
    }
}

int construct(vector<vector<int> > p){
    P = p;
    b.resize(p.size());
    newp.resize(p.size());
    for(int i = 0;i < p.size();i++){
        b[i].resize(p.size());
        newp[i].resize(p.size());
        for(int j = 0;j < p.size();j++){
            if(i == j) continue;
            if(p[i][j]) v[i].push_back(j);
        }
    }
    int cnt = 0;
    for(int i = 0;i < p.size();i++){
        if(visited[i]) continue;
        visited[i] = true;
        dfs(i, cnt); cnt++;
    }
    for(int i = 0;i < p.size();i++) visited[i] = false;
    for(int i = 0;i < cnt;i++){
        vector<int> nv;
        for(int j = 0;j < graph[i].size();j++){
            if(visited[graph[i][j]]) continue;
            visited[graph[i][j]] = true;
            sametree.push_back(graph[i][j]);
            make_tree(graph[i][j]);
            for(int x1 = 0;x1 < sametree.size();x1++){
                for(int x2 = 0;x2 < sametree.size();x2++){
                    if(x1 == x2) continue;
                    newp[sametree[x1]][sametree[x2]] = newp[sametree[x2]][sametree[x1]] = 1;
                }
            }
            sametree.clear();
            nv.push_back(graph[i][j]);
        }
        if(nv.size() <= 1) continue;
        for(int j = 0;j < nv.size() - 1;j++){
            b[nv[j]][nv[j+1]] = 1;
            b[nv[j+1]][nv[j]] = 1;
        }
        for(int x1 = 0;x1 < nv.size();x1++){
            for(int x2 = 0;x2 < graph[i].size();x2++){
                if(nv[x1] == graph[i][x2]) continue;
                if(newp[nv[x1]][graph[i][x2]]) continue;
                newp[nv[x1]][graph[i][x2]] = newp[graph[i][x2]][nv[x1]] = p[nv[0]][nv[1]];
            }
        }
        b[nv[0]][nv.back()] = 1;
        b[nv.back()][nv[0]] = 1;
        if(p[nv[0]][nv[1]] == 3 && nv.size() >= 4){
            b[nv[0]][nv[2]] = b[nv[2]][nv[0]] = 1;
        }
    }
    for(int i = 0;i < p.size();i++){
        for(int j = 0;j < p.size();j++){
            if(i == j) continue;
            if(p[i][j] != newp[i][j]) return 0;
        }
    }
    build(b);
    return 1;
}

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

supertrees.cpp: In function 'void dfs(int, int)':
supertrees.cpp:12:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for(int i = 0;i < v[x].size();i++){
      |                   ~~^~~~~~~~~~~~~
supertrees.cpp: In function 'void make_tree(int)':
supertrees.cpp:20:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for(int i = 0;i < v[x].size();i++){
      |                   ~~^~~~~~~~~~~~~
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:35:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     for(int i = 0;i < p.size();i++){
      |                   ~~^~~~~~~~~~
supertrees.cpp:38:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |         for(int j = 0;j < p.size();j++){
      |                       ~~^~~~~~~~~~
supertrees.cpp:44:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |     for(int i = 0;i < p.size();i++){
      |                   ~~^~~~~~~~~~
supertrees.cpp:49:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |     for(int i = 0;i < p.size();i++) visited[i] = false;
      |                   ~~^~~~~~~~~~
supertrees.cpp:52:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |         for(int j = 0;j < graph[i].size();j++){
      |                       ~~^~~~~~~~~~~~~~~~~
supertrees.cpp:57:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |             for(int x1 = 0;x1 < sametree.size();x1++){
      |                            ~~~^~~~~~~~~~~~~~~~~
supertrees.cpp:58:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |                 for(int x2 = 0;x2 < sametree.size();x2++){
      |                                ~~~^~~~~~~~~~~~~~~~~
supertrees.cpp:67:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |         for(int j = 0;j < nv.size() - 1;j++){
      |                       ~~^~~~~~~~~~~~~~~
supertrees.cpp:71:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |         for(int x1 = 0;x1 < nv.size();x1++){
      |                        ~~~^~~~~~~~~~~
supertrees.cpp:72:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |             for(int x2 = 0;x2 < graph[i].size();x2++){
      |                            ~~~^~~~~~~~~~~~~~~~~
supertrees.cpp:84:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |     for(int i = 0;i < p.size();i++){
      |                   ~~^~~~~~~~~~
supertrees.cpp:85:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |         for(int j = 0;j < p.size();j++){
      |                       ~~^~~~~~~~~~
#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...