Submission #413058

#TimeUsernameProblemLanguageResultExecution timeMemory
413058losmi247Connecting Supertrees (IOI20_supertrees)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
typedef long long ll;
const int N = 1005;

int n;
int p[N][N];





void build(vector <vector<int>> b){
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(i == j && b[i][j] != 0){
                cout << "WA1" << endl;
                exit(0);
            }
            if(b[i][j] != b[j][i]){
                cout << "WA2" << endl;
                exit(0);
            }
        }
    }

    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            cout << b[i][j] << " ";
        }
        cout << endl;
    }
}





int linija(){
    vector <vector<int>> ans;
    for(int i = 1; i <= n; i++){
        vector <int> fg;
        for(int j = 1; j <= n; j++){
            if(j == i+1 || j == i-1) fg.push_back(1);
            else fg.push_back(0);
        }
        ans.push_back(fg);
    }
    build(ans);
    return 1;
}

bool visited[N];
vector <int> sad;
void dfs(int x){
    visited[x] = 1;
    sad.push_back(x);
    for(int j = 1; j <= n; j++){
        if(p[x][j] && !visited[j]) dfs(j);
    }
}

int drvo(){
    vector <vector<int>> ans;
    for(int i = 0; i < n; i++){
        vector <int> sta(n,0);
        ans.push_back(sta);
    }

    for(int i = 1; i <= n; i++){
        if(visited[i]) continue;
        sad.clear();
        dfs(i);
        for(int j = 0; j < sad.size()-1; j++){
            ans[sad[j]][sad[j+1]] = ans[sad[j+1]][sad[j]] = 1;
        }
    }

    build(ans);
    return 1;
}

int construct(vector <vector<int>> nz){
    n = nz.size();
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            p[i][j] = nz[i-1][j-1];
        }
    }

    bool prvi = 0;
    for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) prvi |= (p[i][j] != 1);
    if(!prvi){
        return linija();
    }

    bool drugi = 1;
    for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) if(p[i][j] >= 2) drugi = 0;
    if(drugi){
        return drvo();
    }
}

Compilation message (stderr)

supertrees.cpp: In function 'int drvo()':
supertrees.cpp:75:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |         for(int j = 0; j < sad.size()-1; j++){
      |                        ~~^~~~~~~~~~~~~~
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:103:1: warning: control reaches end of non-void function [-Wreturn-type]
  103 | }
      | ^
/usr/bin/ld: /tmp/cc5nBdt3.o: in function `build(std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >)':
grader.cpp:(.text+0x320): multiple definition of `build(std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >)'; /tmp/cci8r6J3.o:supertrees.cpp:(.text+0x0): first defined here
collect2: error: ld returned 1 exit status