# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
760583 | 2023-06-17T21:43:31 Z | raysh07 | Connecting Supertrees (IOI20_supertrees) | C++17 | 1 ms | 212 KB |
#include "supertrees.h" #include <vector> #include <bits/stdc++.h> using namespace std; const int N = 1001; int root[N]; vector <int> adj[N]; bool vis[N]; vector <int> comp; int find(int x){ if (root[x] == x) return x; return root[x] = find(root[x]); } void unite(int x, int y){ x = find(x); y = find(y); if (x == y) return; root[x] = y; } void dfs(int u){ vis[u] = true; comp.push_back(u); for (auto v : adj[u]){ if (!vis[v]) dfs(v); } } int construct(vector<vector<int>> p) { int n = p.size(); vector<vector<int>> ans(n, vector<int>(n, 0)); for (int i = 0; i < n; i++) root[i] = i; for (int i = 0; i < n; i++){ for (int j = i + 1; j < n; j++){ if (p[i][j] == 1) unite(i, j); if (p[i][j] == 3) return 0; } } for (int i = 0; i < n; i++){ if (find(i) != i){ ans[i][find(i)] = ans[find(i)][i] = 1; } } for (int i = 0; i < n; i++){ for (int j = i + 1; j < n; j++){ if (p[i][j] == 2 && find(i) == i && find(j) == j) { adj[i].push_back(j); adj[j].push_back(i); } } } for (int i = 0; i < n; i++){ if (vis[i] || find(i) != i) continue; comp.clear(); dfs(i); if (comp.size() == 2) return 0; for (int j = 0; j < comp.size() - 1; j++){ ans[comp[j]][comp[j + 1]] = ans[comp[j + 1]][comp[j]] = 1; } ans[comp[0]][comp.back()] = ans[comp.back()][comp[0]] = 1; } build(ans); return 1; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 212 KB | b[0][0] is not 0 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 212 KB | b[0][0] is not 0 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 212 KB | b[0][0] is not 0 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 212 KB | b[0][0] is not 0 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 212 KB | b[0][0] is not 0 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 212 KB | b[0][0] is not 0 |
2 | Halted | 0 ms | 0 KB | - |