QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#207798 | #6560. Broken Minimum Spanning Tree | Freeuni1# | WA | 0ms | 3796kb | C++14 | 1.9kb | 2023-10-08 20:41:48 | 2023-10-08 20:41:49 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n, m, k;
vector<array<int, 4> > v, v1;
vector<array<int, 2> > w[2222];
int d[2222], ok[3333];
vector<array<int, 2> > ans;
int gpar(int a) {
if (d[a] == a) return a;
return d[a] = gpar(d[a]);
}
bool dsu(int a, int b) {
a = gpar(a);
b = gpar(b);
if (a == b) {
return false;
}
d[a] = b;
return true;
}
int dfs(int idx, int par, int tar, int ans) {
if (idx == tar) {
return ans;
}
//cout << idx << "< >" << tar << endl;
for (auto it: w[idx]) {
if (it[0] == par) {
continue;
}
//cout << it[1] << "!!";
if (ans == -1 && ok[it[1]] && it[1] >= n-1) {
int pas = dfs(it[0], idx, tar, it[1]);
if (pas != -1) {
return pas;
}
} else if (ok[it[1]]) {
int pas = dfs(it[0], idx, tar, ans);
if (pas != -1) {
return pas;
}
}
}
return -1;
}
main() {
cin >> n >> m;
for (int i = 0; i < m; i ++) {
int a, s, h;
cin >> a >> s >> h;
v.push_back({h, i, a, s});
v1.push_back({h, i, a, s});
w[a].push_back({s, i});
w[s].push_back({a, i});
}
sort(v.begin(), v.end());
for (int i = 1; i <= n; i ++) {
d[i] = i;
}
for (int i = 0; i < m; i ++) {
if (dsu(v[i][2], v[i][3])) {
ok[v[i][1]] = 1;
}
}
int j = 0;
for (int i = 0; i < m; i ++) {
if (!ok[i]) {
ans.push_back({i, 0});
}
}
cout << ans.size() << endl;
for (int i = 0; i < ans.size(); i ++) {
ans[i][1] = dfs(v1[ans[i][0]][2], -1, v1[ans[i][0]][3], -1);
cout << ans[i][0]+1 << " " << ans[i][1] + 1 << endl;
ok[ans[i][0]] = 1;
ok[ans[i][1]] = 0;
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3728kb
input:
4 4 1 2 10 2 3 3 3 4 1 1 4 4
output:
1 1 4
result:
ok correct!
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3796kb
input:
6 8 1 2 10 2 3 10 3 4 10 4 5 10 5 6 10 6 1 10 1 3 1 4 6 1
output:
3 2 7 5 8 6 0
result:
wrong answer Integer parameter [name=b] equals to 0, violates the range [1, 8]