Submission #300226

#TimeUsernameProblemLanguageResultExecution timeMemory
300226fpc_coderConnecting Supertrees (IOI20_supertrees)C++17
21 / 100
249 ms22392 KiB
#include <bits/stdc++.h> #include "supertrees.h" using namespace std; int construct(vector<vector<int>> p) { vector<vector<int>> b(p.size(), vector<int>(p.size(), 0)); int n = (int) p.size(); vector<int> par(n, -1); vector<bool> vis(n, false); bool subtask3 = false; for (int i = 0; i < n; i++) { if (*max_element(p[i].begin(), p[i].end()) == 2) { subtask3 = true; break; } } if (!subtask3) { for (int i = 0; i < n; i++) { if (vis[i]) continue; par[i] = i; for (int j = 0; j < n; j++) { if (i == j) continue; if (p[i][j]) { if (vis[j]) return 0; vis[j] = true; b[i][j] = b[j][i] = 1; par[j] = i; } } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i == j) continue; if (par[i] == par[j] && p[i][j] == 0) return 0; if (par[i] != par[j] && p[i][j] == 1) return 0; } } build(b); return 1; } else { for (int i = 0; i < n; i++) { if (vis[i]) continue; par[i] = i; int cur = i; for (int j = 0; j < n; j++) { if (i == j) continue; if (p[i][j]) { if (vis[j]) return 0; vis[j] = true; b[cur][j] = b[j][cur] = 1; par[j] = i; cur = j; } } if (b[i][cur]) return 0; b[i][cur] = b[cur][i] = 1; } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i == j) continue; if (par[i] == par[j] && p[i][j] == 0) return 0; if (par[i] != par[j] && p[i][j] == 2) return 0; } } build(b); 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...