Submission #1183452

#TimeUsernameProblemLanguageResultExecution timeMemory
1183452swishy123Connecting Supertrees (IOI20_supertrees)C++20
40 / 100
137 ms22176 KiB
#include <iostream> #include <algorithm> #include <vector> #include <random> #include <chrono> #include <set> #include <map> #include <stack> #include <functional> #include <iomanip> #include <queue> #include <cassert> #include <complex> #include <cstring> #include <memory> #include <bitset> #include <sstream> #include <cmath> #include <numeric> #include <numbers> #include <fstream> #include "supertrees.h" using namespace std; #ifndef template #ifndef define #define ll long long #define ld long double #define pl pair<ll, ll> #define pi pair<int, int> #define nl cout << '\n'; #define x first #define y second #define cbit(x) __builtin_popcountll(x) #define uid(a, b) uniform_int_distribution<ll>(a, b)(rng) #define siz(x) (int)x.size() #endif #ifndef print void print(size_t x) {cout << x << ' ';} void print(int x) {cout << x << ' ';} void print(long long x) {cout << x << ' ';} void print(float x) {cout << x << ' ';} void print(long double x) {cout << x << ' ';} void print(char x) {cout << x << ' ';} void print(const char* x) {cout << x << ' ';} void print(bool x) {cout << x << ' ';} void print(string &x) {cout << x << ' ';} template<typename T, typename V> void print(pair<T, V> &p) {print(p.x); print(p.y);} template<typename T> void print(vector<T> v) {for (int i = 0; i < v.size(); i++) print(v[i]);} template<typename T> void print(vector<vector<T>> v) { for (int i = 0; i < v.size(); i++){ for (int j = 0; j < v[i].size(); j++) print(v[i][j]); nl; } } template <typename T, typename... V> void print(T t, V&&... v) {print(t); print(v...);} #endif #ifndef read void read(int &x) {cin >> x;} void read(long long &x) {cin >> x;} void read(unsigned &x) {cin >> x;} void read(unsigned long long &x) {cin >> x;} void read(float &x) {cin >> x;} void read(long double &x) {cin >> x;} void read(char &x) {cin >> x;} void read(string &x) {cin >> x;} void read(bool &x) {cin >> x;} template<typename T> void read(vector<T> &v) { for (int i = 0; i < v.size(); i++) read(v[i]); } template <typename T, typename... V> void read(T &t, V&... v) {read(t); read(v...);} #endif mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template<class T> bool maxi(T& a, const T& b) { return a < b ? a = b, 1 : 0; } template<class T> bool mini(T& a, const T& b) { return a > b ? a = b, 1 : 0; } template<class... Args> auto vec(size_t n, Args&&... args) { if constexpr(sizeof...(args) == 1) return vector(n, args...); else return vector(n, vec(args...)); } #endif using namespace std; const ll inf = 1e15; const ll def = 1e7+1; const ll mod = 998244353; int construct(vector<vector<int>> p) { int n = p.size(); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++){ if (p[i][j] == 3 || p[i][j] != p[j][i] || p[i][i] != 1) return 0; } auto res = vec(n, n, 0); auto marked = vec(n, 0); for (int i = 0; i < n; i++){ if (marked[i]) continue; vector<int> cmp; auto yesking = vec(n, 0); bool cycle = 0; for (int j = 0; j < n; j++){ if (p[i][j]){ marked[j] = 1; if (p[i][j] == 2) cycle = 1; cmp.push_back(j); yesking[j] = 1; } } for (int u : cmp){ for (int v = 0; v < n; v++){ if ((p[u][v] > 0) != yesking[v]) return 0; } } if (cycle){ vector<int> cmp1, cmp2, cmp3; for (int u : cmp){ vector<int> crr; for (int v = 0; v < n; v++){ if (p[u][v] == 1) crr.push_back(v); } if (crr.size() == 1) cmp2.push_back(u); else{ if (!cmp1.size()) cmp1 = crr; else if (crr != cmp1) cmp3 = crr; } } for (int o = 0; o < 2; o++){ for (int u : cmp1){ for (int v : cmp1){ if (p[u][v] != 1) return 0; } for (int v : cmp2){ if (p[u][v] != 2) return 0; } for (int v : cmp3){ if (p[u][v] != 2) return 0; } } swap(cmp1, cmp3); } if (cmp2.size() + cmp1.size() + cmp3.size() <= 2) return 0; if (!cmp2.size()) return 0; for (int j = 0; j < cmp2.size() - 1; j++){ int u = cmp2[j], v = cmp2[j + 1]; res[u][v] = res[v][u] = 1; } for (int j = 0; j < cmp1.size(); j++){ int u = cmp1[j], v; if (j == cmp1.size() - 1) v = cmp2.front(); else v = cmp1[j + 1]; res[u][v] = res[v][u] = 1; } for (int j = 0; j < cmp3.size(); j++){ int u = cmp3[j], v; if (j == 0) v = cmp2.back(); else v = cmp3[j - 1]; res[u][v] = res[v][u] = 1; } if (cmp1.size() && cmp3.size()) res[cmp1.back()][cmp3.front()] = res[cmp3.front()][cmp1.back()] = 1; else if (cmp1.size()) res[cmp1.back()][cmp2.back()] = res[cmp2.back()][cmp1.back()] = 1; else if (cmp3.size()) res[cmp2.front()][cmp3.front()] = res[cmp3.front()][cmp2.front()] = 1; else res[cmp2.front()][cmp2.back()] = res[cmp2.back()][cmp2.front()] = 1; } else{ for (int j = 0; j < cmp.size() - 1; j++){ int u = cmp[j], v = cmp[j + 1]; res[u][v] = res[v][u] = 1; } } } for (int i = 0; i < n; i++) res[i][i] = 0; build(res); return 1; } // void solve(){ // int n; // read(n); // auto p = vec(n, n, 0); // read(p); // if (construct(p)) // print("Answer found!"); // else // print("Not found"); // } // /* // */ // int32_t main(){ // ios_base::sync_with_stdio(0); // cin.tie(0); cout.tie(0); // if (ifstream("input.txt").good()){ // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // } // int t; // t = 1; // while (t--){ // solve(); // nl; // } // }
#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...