# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1087035 | SulA | Connecting Supertrees (IOI20_supertrees) | C++17 | 128 ms | 32292 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "supertrees.h"
#include <iostream>
#include <vector>
using namespace std;
vector<int> adj[1000], comp;
bool visited[1000];
void dfs(int u) {
comp.push_back(u);
visited[u] = -true;
for (int v: adj[u]) if (!visited[v]) {
dfs(v);
}
}
int construct(vector<vector<int>> p) {
int n = p.size(), mx = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
mx = max(mx, p[i][j]);
if (p[i][j] != 0) {
adj[i].push_back(j);
adj[j].push_back(i);
}
}
}
vector<vector<int>> adj(n, vector<int>(n, 0));
for (int i = 0; i < n; i++) if (!visited[i]) {
comp.clear();
dfs(i);
for (int j = 0; j < comp.size() - 1; j++) {
adj[ comp[j] ][ comp[j+1] ] = adj[ comp[j+1] ][ comp[j] ] = 1;
}
if (mx == 2) {
if (comp.size() < 3) return 0;
adj[comp.front()][comp.back()] = adj[comp.back()][comp.front()] = 1;
}
}
build(adj);
return 1;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |