Submission #308995

#TimeUsernameProblemLanguageResultExecution timeMemory
308995tjdgus4384Connecting Supertrees (IOI20_supertrees)C++14
Compilation error
0 ms0 KiB
#include<bits/stdc++.h>
#include "supertrees.h"
using namespace std;
vector<int> graph[1001], trees[1001];
vector<vector<int> > b, P;
vector<int> v[1001];
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;
        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());
    for(int i = 0;i < p.size();i++){
        b[i].resize(p.size());
        for(int j = 0;j < p.size();j++){
            if(i == j) continue;
            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;
            make_tree(graph[i][j]);
            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;
        }
        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;
        }
    }
    build(b);
    return 1;
}

int main(){
    int n;
    scanf("%d", &n);
    vector<vector<int> > p(n);
    for(int i = 0;i < n;i++){
        p[i].resize(n);
        for(int j = 0;j < n;j++){
            scanf("%d", &p[i][j]);
        }
    }
    printf("%d", construct(p));
    return 0;
}

Compilation message (stderr)

supertrees.cpp: In function 'void dfs(int, int)':
supertrees.cpp:11:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     for(int i = 0;i < v[x].size();i++){
      |                   ~~^~~~~~~~~~~~~
supertrees.cpp: In function 'void make_tree(int)':
supertrees.cpp:19:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for(int i = 0;i < v[x].size();i++){
      |                   ~~^~~~~~~~~~~~~
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:32:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     for(int i = 0;i < p.size();i++){
      |                   ~~^~~~~~~~~~
supertrees.cpp:34:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |         for(int j = 0;j < p.size();j++){
      |                       ~~^~~~~~~~~~
supertrees.cpp:40:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for(int i = 0;i < p.size();i++){
      |                   ~~^~~~~~~~~~
supertrees.cpp:45:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for(int i = 0;i < p.size();i++) visited[i] = false;
      |                   ~~^~~~~~~~~~
supertrees.cpp:48:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |         for(int j = 0;j < graph[i].size();j++){
      |                       ~~^~~~~~~~~~~~~~~~~
supertrees.cpp:55:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         for(int j = 0;j < nv.size() - 1;j++){
      |                       ~~^~~~~~~~~~~~~~~
supertrees.cpp: In function 'int main()':
supertrees.cpp:71:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   71 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
supertrees.cpp:76:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   76 |             scanf("%d", &p[i][j]);
      |             ~~~~~^~~~~~~~~~~~~~~~
/tmp/cc1NK66K.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccu3H2zb.o:supertrees.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status