Submission #300290

#TimeUsernameProblemLanguageResultExecution timeMemory
300290aljasdlasConnecting Supertrees (IOI20_supertrees)C++14
96 / 100
270 ms26360 KiB
#include "supertrees.h" #include <bits/stdc++.h> using namespace std; bool possible = true; vector<vector<int>> b; int n; bitset<1005> vis; bitset<1005> onevis; bitset<1005> isOne; vector<vector<int>> components; int compNum[1005]; vector<vector<int>> onecomponents; int onecompNum[1005]; vector<vector<int>> p; void dfs(int u) { // << u << " "; vis[u] = 1; compNum[u] = components.size(); components.back().push_back(u); for(int v = 0; v < n; v++) if(!vis[v] && p[u][v]) dfs(v); } void onedfs(int u) { onevis[u] = 1; onecompNum[u] = onecomponents.size(); onecomponents.back().push_back(u); for(int v = 0; v < n; v++) if(!onevis[v] && p[u][v] == 1) onedfs(v); } int construct(vector<vector<int>> p_) { p = p_; n = p.size(); for (int i = 0; i < n; i++) { vector<int> row; row.resize(n); b.push_back(row); } vis.reset(); for(int i = 0; i < n; i++) { if(!vis[i]) { components.push_back(vector<int>(0)); // << "Comp " << components.size() << ": "; dfs(i); // << endl; } } for(int i = 0; i < n; i++) { if(!onevis[i]) { onecomponents.push_back(vector<int>(0)); // << "Comp " << components.size() << ": "; onedfs(i); // << endl; if(onecomponents.back().size() == 1) { onecompNum[i] = 0; onecomponents.pop_back(); } } } for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) { if(compNum[i] == compNum[j] && p[i][j] == 0) return 0; else if(compNum[i] != compNum[j] && p[i][j] > 0) return 0; if(onecompNum[i] == onecompNum[j] && onecompNum[i] != 0 && p[i][i] != 1) return 0; } for(auto &v: components) { isOne.reset(); if(v.size() == 1) continue; vector<int> is[3]; for(auto &x: v) if(onecompNum[x] == 0) is[2].push_back(x); for(auto &x: v) { if(onecompNum[x] > 0) { auto &w = onecomponents[onecompNum[x]-1]; for(int i = 0; i+1 < w.size(); i++) { b[w[i]][w[i+1]] = 1; b[w[i+1]][w[i]] = 1; } is[2].push_back(w.back()); for(auto y: w) onecompNum[y] = -1; } } // << "Is 1: "; for(auto x: is[1]) cerr << x << " "; cerr << endl; // << "Is 2: "; for(auto x: is[2]) cerr << x << " "; cerr << endl; if(is[2].size() == 2) return 0; if(is[2].size() > 2) { for(int i = 1; i < is[2].size(); i++) { b[is[2][i-1]][is[2][i]] = 1; b[is[2][i]][is[2][i-1]] = 1; } b[is[2][is[2].size()-1]][is[2][0]] = 1; b[is[2][0]][is[2][is[2].size()-1]] = 1; } } if(!possible) return 0; build(b); return 1; }

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:97:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   97 |     for(int i = 0; i+1 < w.size(); i++) {
      |                    ~~~~^~~~~~~~~~
supertrees.cpp:114:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  114 |    for(int i = 1; i < is[2].size(); 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...