QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#388694 | #7995. 图 | mzyx | Compile Error | / | / | C++14 | 2.3kb | 2024-04-13 18:14:37 | 2024-04-13 18:14:38 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct DSU {
std::vector<int> f;
DSU() {}
DSU(int n) {
init(n);
}
void init(int n) {
f.resize(n);
std::iota(f.begin(), f.end(), 0);
}
int find(int x) {
while (x != f[x]) {
x = f[x] = f[f[x]];
}
return x;
}
bool same(int x, int y) {
return find(x) == find(y);
}
bool merge(int x, int y) {
x = find(x);
y = find(y);
if (x == y) {
return false;
}
f[y] = x;
return true;
}
};
void solve() {
int n;
cin >> n;
vector<vector<int>> e(n, vector<int>(n));
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> e[i][j];
}
}
vector<array<int, 3>> s;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
s.push_back({e[i][j], i, j});
}
}
sort(s.begin(), s.end());
vector<vector<int>> ans(n, vector<int>(n));
DSU dsu(n);
vector<int> adj[n];
for (auto [_, x, y] : s) {
if (dsu.merge(x, y)) {
ans[x][y] = ans[y][x] = 1;
adj[x].push_back(y);
adj[y].push_back(x);
}
}
vector dist(n, vector<int>(n)); // pp -> p -> u
function<void(int, int, int)> dfs = [&](int u, int p, int pp) -> void {
for (auto v : adj[u]) {
if (v == p) {
continue;
}
if (p != -1 && pp != -1) {
dist[u][pp] = dist[pp][u] = e[u][p] + e[p][pp];
}
dfs(v, u, p);
}
};
dfs(0, -1, -1);
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (!ans[i][j] && dist[i][j] > e[i][j]) {
ans[i][j] = 1;
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cout << ans[i][j];
}
cout << "\n";
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
詳細信息
answer.code: In function ‘void solve()’: answer.code:67:15: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions] 67 | for (auto [_, x, y] : s) { | ^ answer.code:75:12: error: missing template arguments before ‘dist’ 75 | vector dist(n, vector<int>(n)); // pp -> p -> u | ^~~~ answer.code: In lambda function: answer.code:83:17: error: ‘dist’ was not declared in this scope 83 | dist[u][pp] = dist[pp][u] = e[u][p] + e[p][pp]; | ^~~~ answer.code: In function ‘void solve()’: answer.code:93:31: error: ‘dist’ was not declared in this scope 93 | if (!ans[i][j] && dist[i][j] > e[i][j]) { | ^~~~