Submission #306437

#TimeUsernameProblemLanguageResultExecution timeMemory
306437giorgikobConnecting Supertrees (IOI20_supertrees)C++14
Compilation error
0 ms0 KiB
#include "supertrees.h" #include <vector> #include<bits/stdc++.h> #define ll long long #define ff first #define ss second #define pb push_back using namespace std; const int N = 1e3+5; vector<int>c[N]; int cnt = 0; int fix[N]; vector<int>chain; void dfs(int x,vector<vector<int>>&p){ fix[x] = 1; //cout << x << endl; c[cnt].pb(x); for(int i = 0; i < n; i++){ if(fix[i]) continue; if(p[x][i]){ dfs(i,p); } } } void dfs1(int x,vector<vector<int>>&p){ fix[x] = 1; //c[cnt].pb(x); chain.pb(x); //cout << x << endl; for(int i = 0; i < n; i++){ //cout << fix[i] << " "; if(fix[i]) continue; if(p[x][i] == 1){ dfs1(i,p); } } //cout << endl; } bool check(vector<int>&v){ for(int i = 0; i < v.size(); i++){ for(int j = 0; j < v.size(); j++){ if(p[v[i]][v[j]] == 2){ return 0; } } } return 1; } void cr(int x,int y,vector<vector<int>>&v){ v[x][y] = 1; v[y][x] = 1; } int construct(std::vector<std::vector<int>> p) { int n = p.size(); for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ if(p[i][j] == 3){ return 0; } } } //cout << "done 1" << endl; for(int i = 0; i < n; i++){ if(fix[i]) continue; cnt++;//cout << i << endl; dfs(i,p); } //cout << "done 2" << endl; for(int i = 0; i < n; i++) fix[i] = 0; for(int i = 1; i <= cnt; i++){ for(int j = 0; j < c[i].size(); j++){ for(int t = 0; t < c[i].size(); t++){ if(p[c[i][j]][c[i][t]] == 0){ return 0; } } } } //cout << cnt << endl; //cout << "done 3" << endl; //cout << cnt << endl; //vector<int>v; vector<vector<int>>answer(n,vector<int>(n,0)); vector<int>cyc; for(int i = 1; i <= cnt; i++){ //cout << c[i].size() << endl; for(int j = 0; j < c[i].size(); j++){ int x = c[i][j]; //cout << fix[x] << " " << x << " <<---"<< endl; if(fix[x]) continue; //cout << x << endl; chain.clear(); dfs1(x,p); //for(auto x : chain) cout << x << " "; cout << endl; if(check(chain) == 0){ return 0; } for(int t = 0; t+1 < chain.size(); t++){ int x = chain[t]; int y = chain[t+1]; cr(x,y,answer); } cyc.pb(chain[0]); } if(cyc.size() > 1) for(int i = 0; i < cyc.size(); i++){ int x = cyc[i]; int y = cyc[(i+1)%(int)cyc.size()]; cr(x,y,answer); } cyc.clear(); } //cout << "done 4" << endl; build(answer); return 1; }

Compilation message (stderr)

supertrees.cpp: In function 'void dfs(int, std::vector<std::vector<int> >&)':
supertrees.cpp:22:24: error: 'n' was not declared in this scope
   22 |     for(int i = 0; i < n; i++){
      |                        ^
supertrees.cpp: In function 'void dfs1(int, std::vector<std::vector<int> >&)':
supertrees.cpp:36:24: error: 'n' was not declared in this scope
   36 |     for(int i = 0; i < n; i++){
      |                        ^
supertrees.cpp: In function 'bool check(std::vector<int>&)':
supertrees.cpp:48:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     for(int i = 0; i < v.size(); i++){
      |                    ~~^~~~~~~~~~
supertrees.cpp:49:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |         for(int j = 0; j < v.size(); j++){
      |                        ~~^~~~~~~~~~
supertrees.cpp:50:16: error: 'p' was not declared in this scope
   50 |             if(p[v[i]][v[j]] == 2){
      |                ^
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:83:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |         for(int j = 0; j < c[i].size(); j++){
      |                        ~~^~~~~~~~~~~~~
supertrees.cpp:84:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |             for(int t = 0; t < c[i].size(); t++){
      |                            ~~^~~~~~~~~~~~~
supertrees.cpp:99:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   99 |         for(int j = 0; j < c[i].size(); j++){
      |                        ~~^~~~~~~~~~~~~
supertrees.cpp:110:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  110 |             for(int t = 0; t+1 < chain.size(); t++){
      |                            ~~~~^~~~~~~~~~~~~~
supertrees.cpp:118:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  118 |         for(int i = 0; i < cyc.size(); i++){
      |                        ~~^~~~~~~~~~~~