Submission #771129

#TimeUsernameProblemLanguageResultExecution timeMemory
771129OrazBConnecting Supertrees (IOI20_supertrees)C++17
100 / 100
200 ms28488 KiB
#include <bits/stdc++.h> #include "supertrees.h" using namespace std; #define N 100005 #define pb push_back vector<int> vec[N]; int construct(vector<vector<int>> p){ int n = p.size(); vector<vector<int>> b(n, vector<int>(n, 0)); vector<int> vis(n, 0), ok(n, 0); int cnt = 0; for (int i = 0; i < n; i++){ if (vis[i]){ if (p[i] != vec[vis[i]]) return 0; continue; } cnt++; for (int j = 0; j < n; j++){ if (p[i][j] == 3) return 0; if (p[i][j] and i != j){ if (p[i][j] == 1){ b[i][j] = b[j][i] = 1; vis[j] = cnt; } } vec[cnt].pb(p[i][j]); } } for (int i = 0; i < n; i++){ if (vis[i] or ok[i]) continue; deque<int> v; ok[i] = 1; for (int j = 0; j < n; j++){ if (p[i][j] == 2 and !vis[j]){ ok[j] = 1; v.pb(j); } } if (!v.size()) continue; if (v.size() == 1) return 0; v.push_front(i); for (int j = 0; j < (int)v.size(); j++){ for (int k = j+1; k < (int)v.size(); k++) if (p[v[j]][v[k]] != 2) return 0; for (int k = 0; k < n; k++){ if (p[v[j]][k] == 2 and !ok[k] and !vis[k]) return 0; } } b[v[0]][v.back()] = b[v.back()][v[0]] = 1; for (int j = 1; j < (int)v.size(); j++){ b[v[j-1]][v[j]] = b[v[j]][v[j-1]] = 1; } } // for (int i = 0; i < n; i++){ // for (int j = 0; j < n; j++) cout << b[i][j] << ' '; // cout << '\n'; // } build(b); return 1; } // int main () // { // int n; // cin >> n; // vector<vector<int>> p(n, vector<int>(n)); // for (int i = 0; i < n; i++){ // for (int j = 0; j < n; j++) cin >> p[i][j]; // } // int x = 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...