Submission #1148916

#TimeUsernameProblemLanguageResultExecution timeMemory
1148916zhasynConnecting Supertrees (IOI20_supertrees)C++20
0 / 100
1 ms328 KiB
#include "supertrees.h" #include <bits/stdc++.h> #define pb push_back #define pf push_front using namespace std; #define F first #define S second typedef long long ll; #define pii pair <int, int> #define pll pair <ll, ll> typedef long double ld; const ll N = 1000 + 100, M = 4096 + 10, len = 21, inf = 1e18; const ll mod = 1e9 + 7; vector <int> q[N]; vector<vector<int>> ans; vector <int> c; bool was[N]; void dfs(int v){ was[v] = true; c.pb(v); for(auto u : q[v]){ if(was[u] == true) continue; dfs(u); } } // void build(vector<vector<int>> p){ // for(auto u : p){ // for(auto v : u){ // cout << v << " "; // } // cout << endl; // } // } int construct(vector<vector<int>> p) { int n = p.size(); bool can = true; for (int i = 0; i < n; i++) { vector<int> row; row.resize(n); ans.push_back(row); } for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ if(i == j) continue; if(p[i][j] == 2) q[i].pb(j); } } //cout << "was\n"; for(int i = 0; i < n; i++){ if(was[i] == false){ dfs(i); if((int)c.size() == 1) continue; for(int j = 1; j < (int)c.size(); j++){ ans[c[j]][c[j - 1]] = ans[c[j - 1]][c[j]] = 1; } ans[(int)c.size() - 1][0] = ans[0][(int)c.size() - 1] = 1; for(int j = 0; j < (int)c.size(); j++){ for(int k = 0; k < (int)c.size(); k++){ if(p[c[j]][c[k]] == 0) can = false; } } //cout << "was\n"; c.clear(); } } if(can) build(ans); return can; } // int main() { // ios::sync_with_stdio(false); // cin.tie(NULL); // vector<vector<int>> p; // int n; // cin >> n; // for(int i = 0, x; i < n; i++){ // vector <int >cur; // for(int j = 0; j < n; j++){ // cin >> x; // cur.pb(x); // } // p.pb(cur); // } // construct(p); // return 0; // }
#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...