Submission #1291665

#TimeUsernameProblemLanguageResultExecution timeMemory
1291665gustavo_dConnecting Supertrees (IOI20_supertrees)C++20
21 / 100
103 ms26252 KiB
#include "supertrees.h" #include <bits/stdc++.h> using namespace std; #define sz(v) (int)(v).size() const int MAXN = 1000; vector<int> adj[MAXN]; vector<pair<int, int>> eds; bool vis[MAXN]; vector<int> comp; void dfs(int v) { vis[v] = true; comp.push_back(v); for (int viz : adj[v]) { if (vis[viz]) continue; dfs(viz); } } int construct(vector<vector<int>> paths) { int n = sz(paths); for (int i=0; i<n; i++) { for (int j=0; j<n; j++) { if (i == j) continue; if (paths[i][j] == 0) continue; adj[i].push_back(j); } } for (int i=0; i<n; i++) { if (vis[i]) continue; comp.clear(); dfs(i); for (int u : comp) { for (int v : comp) { if (paths[u][v] == 0) { // cerr << u << ' ' << v << " together\n"; return 0; } } } if (sz(comp) == 1) continue; vector<int> g1, g2; for (int viz : adj[i]) { if (paths[i][viz] == 1) g1.push_back(viz); else g2.push_back(viz); } if (sz(g1) > 0) { if (paths[g1[0]][i] == 1) g1.push_back(i); else g2.push_back(i); } else { g2.push_back(i); } // cout << "componente\n"; // for (int v : g1) cout << v << ' '; // cout << '\n'; // for (int v : g2) cout << v << ' '; // cout << '\n'; // verify for (int v : g1) { for (int u : g1) { if (u == v) continue; if (paths[u][v] == 2) { // cerr << 11 << ' ' << u << ' ' << v << '\n'; return 0; } } for (int u : g2) { if (paths[u][v] == 1) { // cerr << 12 << ' ' << u << ' ' << v << '\n'; return 0; } } } for (int v : g2) { for (int u : g2) { if (u == v) continue; if (paths[u][v] == 1) { // cerr << 22 << ' ' << u << ' ' << v << '\n'; return 0; } } } for (int j=1; j<sz(g2); j++) { eds.emplace_back(g2[j-1], g2[j]); } for (int j=1; j<sz(g1); j++) { eds.emplace_back(g1[j-1], g1[j]); } if (!g1.empty() and !g2.empty()) { eds.emplace_back(g1[0], g2[0]); eds.emplace_back(g1[0], g2.back()); } } vector<vector<int>> ans(n, vector<int> (n, 0)); // cerr << sz(eds) << '\n'; for (auto [u, v] : eds) { // cerr << u << ' ' << v << '\n'; ans[u][v] = ans[v][u] = 1; } build(ans); return 1; }
#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...