Submission #720655

#TimeUsernameProblemLanguageResultExecution timeMemory
720655ToxtaqConnecting Supertrees (IOI20_supertrees)C++17
11 / 100
177 ms22032 KiB
#ifndef SUPERTREES_H_INCLUDED #define SUPERTREES_H_INCLUDED #include "supertrees.h" #include<bits/stdc++.h> using namespace std; struct DSU{ vector<int>par; DSU(int n){ par.assign(n, -1); } int FindRep(int u){ if(par[u] < 0)return u; return par[u] = FindRep(par[u]); } void Union(int u, int v){ u = FindRep(u); v = FindRep(v); if(u == v)return; if(par[u] > par[v])swap(u, v); par[u] += par[v]; par[v] = u; } bool IsConnected(int u, int v){ u = FindRep(u); v = FindRep(v); return (u == v); } }; void build(vector<vector<int>>b); int construct(vector<vector<int>>p){ int n = p.size(); vector<vector<int>>ans(n, vector<int>(n)); DSU dsu1(n); vector<int>oneortwo(n); for(int i = 0;i < n;++i){ int cnt = 0; for(int j = 0;j < n;++j){ if(i != j && p[i][j])dsu1.Union(i, j); cnt += (p[i][j] == 1); } if(cnt == 1)oneortwo[i] = 2; else oneortwo[i] = 1; } vector<bool>chosen(n); for(int i = 0;i < n;++i){ int par = dsu1.FindRep(i); if(chosen[i])continue; vector<int>ones, twos; for(int j = 0;j < n;++j){ int node = dsu1.FindRep(j); if(dsu1.FindRep(j) == par){ chosen[j] = 1; if(oneortwo[j] == 2)twos.push_back(j); else ones.push_back(j); } } // cout << i << ": \n"; // cout << "ones: "; // for(int j : ones)cout << j << " "; // cout << "\ntwos: "; // for(int j : twos)cout << j << " "; // cout << '\n'; for(int j = 1;j < ones.size();++j){ ans[ones[j - 1]][ones[j]] = 1; ans[ones[j]][ones[j - 1]] = 1; } for(int j = 1;j < twos.size();++j){ ans[twos[j - 1]][twos[j]] = 1; ans[twos[j]][twos[j - 1]] = 1; } if(!ones.size() && (int)twos.size() > 1){ ans[twos[0]][twos.back()] = ans[twos.back()][twos[0]] = 1; } else if(ones.size() && (int)twos.size() > 1){ ans[ones.back()][twos[0]] = 1; ans[twos[0]][ones.back()] = 1; ans[twos.back()][ones.back()] = 1; ans[ones.back()][twos.back()] = 1; } } // for(int i = 0;i < n;++i){ // for(int j = i + 1;j < n;++j){ // if(ans[i][j])cout << i << ", " << j << '\n'; // } // } build(ans); return 1; } #endif // SUPERTREES_H_INCLUDED

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:50:17: warning: unused variable 'node' [-Wunused-variable]
   50 |             int node = dsu1.FindRep(j);
      |                 ^~~~
supertrees.cpp:63:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |         for(int j = 1;j < ones.size();++j){
      |                       ~~^~~~~~~~~~~~~
supertrees.cpp:67:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |         for(int j = 1;j < twos.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...