Submission #837101

#TimeUsernameProblemLanguageResultExecution timeMemory
837101JustAmethystConnecting Supertrees (IOI20_supertrees)C++17
0 / 100
1120 ms2053868 KiB
#include "supertrees.h" #include <bits/stdc++.h> #define sz(x) (int)(x.size()) using namespace std; vector<int> a, b; vector<vector<int>> answer; vector<int> done; // void build(vector<vector<int>> ans) { // for (auto x : ans) { // for (auto y : x) { // cout << y << " "; // } // cout << "\n"; // } // } bool check1(int x, int n, vector<vector<int>> p) { int c = 0; for (int i = 0; i < n; ++i) { if (p[x][i] == 1) { if (done[i] != 1) return 0; ++c; } } return (c == sz(a)); } bool check2(int x, int n, vector<vector<int>> p) { int c = 1; for (int i = 0; i < n; ++i) { if (i != x) { if (p[x][i] == 2) { // if (done[i] != 2) { // cout << "here - " << x << " " << i << "\n"; // return 0; // } ++c; } } } // cout << "c = " << c << "\n"; return (c == (sz(a) + sz(b))); } void place(int x, int n, vector<vector<int>> p) { bool y = 0; int z = 0; done[x] = 3; for (int i = 0; i < n; ++i) { if (i != x && p[x][i]) { if (p[x][i] == 1) { // cout << x << " " << i << "\n"; y = 1; } if (done[i] == 0) place(i, n, p); } if (p[x][i] == 0) ++z; } if (z == n-1) return; if (y) { a.push_back(x); done[x] = 1; } else { b.push_back(x); done[x] = 2; } } int construct(vector<vector<int>> p) { int n = p.size(); for (int i = 0; i < n; i++) { done.push_back(0); vector<int> row; row.resize(n); answer.push_back(row); } for (int i = 0; i < n; ++i) { if (done[i] == 0) place(i, n, p); else continue; // if (done[i] == 1) cout << check1(i, n, p) << " - 1\n"; // else cout << check2(i, n, p) << " - 2\n"; if (done[i] == 3) continue; if (sz(b) <= 2 && sz(a) == 0) { // cout << 2 << "\n"; return 0; } for (int j = 1; j < sz(a); ++j) { answer[0][j] = 1; answer[j][0] = 1; } if (sz(a) && sz(b)) { answer[a[0]][b[0]] = 1; answer[b[0]][a[0]] = 1; answer[a[0]][b[sz(b)-1]] = 1; answer[b[sz(b)-1]][a[0]] = 1; } for (int j = 0; j < sz(b)-1; ++j) { answer[b[j]][b[j+1]] = 1; answer[b[j+1]][b[j]] = 1; } a.clear(); b.clear(); // for (auto x : done) cout << x << " "; // for (auto x : a) cout << x << " "; // cout << "\n"; // for (auto x : b) cout << x << " "; // cout << "\n"; } // for (int i = 1; i < n; ++i) { // answer[0][i] = 1; // answer[i][0] = 1; // } build(answer); return 1; } // int main() { // int n, a; // cin >> n; // vector<vector<int>> p; // for (int i = 0; i < n; ++i) { // p.push_back({}); // for (int j = 0; j < n; ++j) { // cin >> a; // p[i].push_back(a); // } // } // construct(p); // }
#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...