Submission #733979

#TimeUsernameProblemLanguageResultExecution timeMemory
733979ismayilConnecting Supertrees (IOI20_supertrees)C++17
100 / 100
252 ms23816 KiB
#include "supertrees.h" #include <bits/stdc++.h> using namespace std; const int MAX = 1e3 + 3; struct DSU{ int par[MAX]; int find(int u){ if(par[u] < 0) return u; return par[u] = find(par[u]); } bool unite(int u, int v){ u = find(u), v = find(v); if(u == v) return false; if(par[u] > par[v]) swap(u, v); par[u] += par[v]; par[v] = u; return true; } DSU(){ memset(par, -1, sizeof(par)); } }; int construct(vector<vector<int>> p) { for(auto i : p) for(auto j : i) if(j == 3) return 0; DSU dsu1, dsu2; int n = p.size(); vector<vector<int>> answer(n, vector<int>(n, 0)); int mark[n] = {0}; for (int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ if(p[i][j] == 0 && dsu1.find(i) == dsu1.find(j)) return 0; if(p[i][j] != 1) continue; if(dsu1.unite(i, j)){ answer[i][j] = answer[j][i] = 1; } } } for (int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ if(p[dsu1.find(i)][dsu1.find(j)] == 2){ dsu2.unite(dsu1.find(i), dsu1.find(j)); } } } for (int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ if(dsu2.find(dsu1.find(i)) == dsu2.find(dsu1.find(j)) && p[dsu1.find(i)][dsu1.find(j)] == 0) return 0; } } vector<int> comp[n]; for(int i = 0; i < n; i++){ if(mark[dsu1.find(i)]) continue; mark[dsu1.find(i)] = 1; comp[dsu2.find(dsu1.find(i))].push_back(dsu1.find(i)); } for(auto &v : comp){ if(v.size() == 2) return 0; if(v.size() < 2) continue; for(int j = 0; j < v.size() - 1; j++) answer[v[j]][v[j + 1]] = answer[v[j + 1]][v[j]] = 1; answer[v[v.size() - 1]][v[0]] = answer[v[0]][v[v.size() - 1]] = 1; } build(answer); return 1; }

Compilation message (stderr)

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