QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#402655 | #7415. Fast Spanning Tree | 24bot | WA | 3ms | 16124kb | C++14 | 1.6kb | 2024-05-01 09:23:58 | 2024-05-01 09:23:59 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 5;
const int INF = 1e9 + 5;
int n, m;
int a[N], fa[N], use[N];
vector<int> ans;
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
struct Edge {
int u, v, c;
} e[N];
priority_queue<int, vector<int>, greater<int>> todo;
#define pii pair<int, int>
priority_queue<pii, vector<pii>, greater<pii>> q[N];
inline void add(int i) {
if (use[i]) return;
int x = find(e[i].u), y = find(e[i].v);
if (x == y) return;
if (a[x] + a[y] >= e[i].c) return todo.push(i), void();
q[x].emplace((e[i].c - a[x] + a[y] + 1) / 2, i);
q[y].emplace((e[i].c - a[y] + a[x] + 1) / 2, i);
}
inline void merge(int i) {
int u = find(e[i].u), v = find(e[i].v);
if (u == v) return; ans.push_back(i); use[i] = 1;
if (q[u].size() > q[v].size()) swap(u, v);
fa[u] = v; a[v] = min(INF, a[u] + a[v]);
while (q[u].size()) {
auto it = q[u].top(); q[u].pop();
if (a[v] >= it.first) add(it.second);
else q[v].push(it);
}
while (q[v].size()) {
auto it = q[v].top(); q[v].pop();
if (a[v] >= it.first) add(it.second);
else { q[v].push(it); break; }
}
}
int main(void) {
ios::sync_with_stdio(0);
cin >> n >> m;
for (int i = 1; i <= n; ++i) cin >> a[i], fa[i] = i;
for (int i = 1; i <= m; ++i) cin >> e[i].u >> e[i].v >> e[i].c, add(i);
while (!todo.empty()) {
int i = todo.top(); todo.pop();
merge(i);
}
cout << ans.size() << "\n";
for (int i : ans) cout << i << " "; cout << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 16124kb
input:
5 5 1 4 3 4 0 4 5 5 3 1 1 2 5 2 4 3 1 4 1 4
output:
4 2 3 4 1
result:
wrong answer 4th numbers differ - expected: '1', found: '4'