QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#357659 | #8136. Rebellious Edge | squishybanana# | WA | 155ms | 3820kb | C++23 | 1.4kb | 2024-03-19 07:20:52 | 2024-03-19 07:20:52 |
Judging History
answer
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
using ll = long long;
template<typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;
void solve() {
int n, m; cin >> n >> m;
vector<vector<pair<int, ll>>> adj(n);
int badU, badV, badW;
for( int i = 0 ; i < m; i++) {
int u, v; cin >> u >> v;
u--;v--;
ll w; cin >> w;
adj[u].push_back({v, w});
if (u > v) {
badU = u;
badV = v;
badW = w;
}
}
vector<bool> vis(n);
minpq<pair<ll, int>> q;
ll out = 0;
q.push({0, 0});
while (q.size()) {
auto [w, i] = q.top();
q.pop();
if (vis[i]) continue;
out += w;
vis[i] = true;
for (auto [j, w] : adj[i]) {
if (j < i) continue;
if (!vis[j]) {
q.push({w, j});
}
}
}
vis.assign(n, 0);
while (q.size()) q.pop();
ll cur = badW;
// find cheapest edge going into badU
ll cost = 1e18;
for (int i = 0; i < n; i++) {
for (auto [to, cos] : adj[i]) {
if (to == badU) cost = min(cost, cos);
}
}
vis[badV] = true;
cur += cost;
q.push({0, 0});
q.push({0, badU});
while (q.size()) {
auto [w, i] = q.top();
q.pop();
if (vis[i]) continue;
cur += w;
vis[i] = true;
for (auto [j, w] : adj[i]) {
if (!vis[j]) {
q.push({w, j});
}
}
}
out = min(out, cur);
cout << out << endl;
}
int main() {
int t; cin >> t;
while (t--) solve();
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3584kb
input:
3 5 6 1 2 4 1 3 2 2 3 0 3 4 1 4 5 1 5 2 1 4 4 1 2 4 1 3 6 1 4 8 4 2 1000000 3 3 1 2 100 2 1 10 2 3 1000
output:
5 18 1100
result:
ok 3 number(s): "5 18 1100"
Test #2:
score: -100
Wrong Answer
time: 155ms
memory: 3820kb
input:
50000 4 5 2 4 998973548 2 3 501271695 4 1 778395982 1 4 32454891 1 2 757288934 4 5 1 4 720856669 2 3 665098951 3 4 407461517 2 1 866914401 1 2 457859826 4 5 1 2 75288664 1 4 624893594 3 2 458973866 2 4 769074655 2 3 834773751 4 5 2 3 237060634 2 4 297307882 3 4 200383586 1 2 42856502 3 1 16574713 4 ...
output:
810850873 1530420294 1534956009 454018933 888212051 853527901 1590145024 858095911 1034153425 793861088 605832428 1051598350 612891589 1265994009 517769091 1831713742 1556463491 93634961 920380117 984886788 1696503797 1002892611 1512611979 941700550 1515267731 749783488 1119549778 248623355 14011662...
result:
wrong answer 1st numbers differ - expected: '1291015520', found: '810850873'