Submission #302863

#TimeUsernameProblemLanguageResultExecution timeMemory
302863Jarif_RahmanConnecting Supertrees (IOI20_supertrees)C++17
40 / 100
277 ms24824 KiB
#include "supertrees.h" #include <bits/stdc++.h> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; vector<vector<int>> v; vector <vector<int>> dsu1; vector <int> dsu2; void unite(int a, int b){ if(dsu2[a] == dsu2[b]) return; int x = dsu2[a], y = dsu2[b]; if(dsu1[x].size() < dsu1.size()){ while(!dsu1[x].empty()){ int ss = dsu1[x].back(); dsu1[x].pop_back(); dsu2[ss] = y; dsu1[y].pb(ss); } } else{ while(!dsu1[y].empty()){ int ss = dsu1[y].back(); dsu1[y].pop_back(); dsu2[ss] = x; dsu1[x].pb(ss); } } } int construct(vector<vector<int>> p){ v.clear(); dsu1.clear(); dsu2.clear(); int n = p.size(); v = vector<vector<int>>(n, vector<int>(n, 0)); dsu1 = vector<vector<int>>(n); dsu2 = vector<int>(n); for(int i = 0; i < n ; i++) dsu1[i].pb(i); for(int i = 0; i < n; i++) dsu2[i] = i; vector <int> zot(3, 0); for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if(i != j) zot[p[i][j]]++; for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if(p[i][j] != 0) unite(i, j); bool bl = 1; for(auto sth: dsu1){ if(sth.size() < 2) continue; if(sth.size() == 2){ if(zot[1] == 0){ bl = 0; break; } else continue; } for(int i = 0; i < sth.size(); i++) for(int j = 0; j < sth.size(); j++){ if(i == j) continue; if(p[sth[i]][sth[j]] == 0){ bl = 0; break; } } } if(!bl) return 0; for(auto sth: dsu1){ if(sth.size() < 2) continue; for(int i = 0; i < sth.size() - 1; i++){ v[sth[i]][sth[i+1]] = 1; v[sth[i+1]][sth[i]] = 1; } if(zot[1] == 0){ v[sth[0]][sth[sth.size() - 1]] = 1; v[sth[sth.size() - 1]][sth[0]] = 1; } } build(v); return 1; }

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:55:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         for(int i = 0; i < sth.size(); i++) for(int j = 0; j < sth.size(); j++){
      |                        ~~^~~~~~~~~~~~
supertrees.cpp:55:62: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         for(int i = 0; i < sth.size(); i++) for(int j = 0; j < sth.size(); j++){
      |                                                            ~~^~~~~~~~~~~~
supertrees.cpp:66:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |         for(int i = 0; i < sth.size() - 1; i++){
      |                        ~~^~~~~~~~~~~~~~~~
#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...