Submission #318355

#TimeUsernameProblemLanguageResultExecution timeMemory
318355NintsiChkhaidzeConnecting Supertrees (IOI20_supertrees)C++14
40 / 100
274 ms22244 KiB
#include "supertrees.h" #include <iostream> #include <vector> #define pb push_back using namespace std; vector<vector<int>> answer; vector <int> row,cycle; int par[1005]; bool f[1005]; int construct(vector<vector<int>> p) { int n = p.size(),a=0,b=0; for(int i=0;i<n;i++){ row.clear(); for (int j=0;j<n;j++){ if (p[i][j] == 2) a=1; if (p[i][j] == 1 && i!=j) b=1; if (p[i][j] == 3) return 0; if (p[i][i] != 1) return 0; row.pb(0); } answer.pb(row); } for(int i=0;i<n;i++) par[i]=i; for (int i=0;i<n;i++){ if (f[i]) continue; for (int j=0;j<n;j++){ if (p[i][j] == 1 && i!=j){ f[j]=1; par[j] = i; answer[i][j]=answer[j][i]=1; } } } for(int i=0;i<n;i++) f[i]=0; if (a == 0){ for (int i=0;i<n;i++){ for (int j=0;j<n;j++){ if (par[i] == par[j] && p[i][j] != 1) return 0; if (par[i] != par[j] && p[i][j] != 0) return 0; } } } for(int i=0;i<n;i++){ if (f[i]) continue; row.clear(); for (int j=0;j<n;j++) if (p[i][j] == 2) f[j] = 1,row.pb(j); int cur = i; cycle.clear(); cycle.pb(i); par[i] = i; for (int j=0;j<row.size();j++){ cycle.pb(row[j]); par[row[j]] = i; answer[row[j]][cur] = answer[cur][row[j]] = 1; cur = row[j]; } if (row.size()==0) continue; if (row.size() == 1) {return 0;} answer[i][cur] = answer[cur][i] = 1; } if (a==1 && b==0){ for (int i=0;i<n;i++) for (int j=i+1;j<n;j++){ if (par[i] == par[j] && p[i][j]!=2) return 0; if (par[i]!=par[j] && p[i][j]!=0) return 0; } } build(answer); return 1; } /* 6 1 2 2 0 0 0 2 1 2 0 0 0 2 2 1 0 0 0 0 0 0 1 2 2 0 0 0 2 1 2 0 0 0 2 2 1 */

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:54:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         for (int j=0;j<row.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...