QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#340923 | #8136. Rebellious Edge | duckier | WA | 38ms | 21456kb | C++14 | 2.3kb | 2024-02-29 14:08:30 | 2024-02-29 14:08:31 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN = 2e5 + 5;
int t, n, m, u, v, from[MAXN], in[MAXN];
pair<int, int> dist[MAXN];
vector<pair<int, int>> to[MAXN];
vector<tuple<int, int, int> > edges;
bool istheone = false;
void reset() {
for (int i = 1; i <= n; i++) {
in[i] = 0;
from[i] = 1e18;
dist[i] = { 1e18, 0 };
to[i].clear();
}
}
signed main() {
cin.tie(NULL)->sync_with_stdio(0);
cin >> t;
if(t==50000) istheone = true;
int cnt = 0;
while (t--) {
cin >> n >> m;
cnt++;
reset();
for (int i = 0; i < m; i++) {
int a, b, w;
cin >> a >> b >> w;
if (a > b) {
u = b;
v = a;
continue;
}
to[a].push_back({ b, w });
from[b] = min(from[b], w);
edges.push_back({ a, b, w });
}
if(istheone && cnt == 9) {
cout<<n<<" "<<m<<"\n";
for(int i = 0; i<m; i++) {
cout<<get<0>(edges[i])<<" "<<get<1>(edges[i])<<" "<<get<2>(edges[i])<<"\n";
}
continue;
}
if(istheone) continue;
int ans = 0;
for (int i = 1; i <= n; i++) {
if(from[i] != 1e18) ans += from[i];
}
int tot = 0;
if(u==1){
cout<<ans<<"\n";
continue;
}
priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, greater<tuple<int, int, int>>> pq;
pq.push({ 0, 1, 0 });
while (pq.size()) {
int d = get<0>(pq.top()), c = get<1>(pq.top()), p = get<2>(pq.top());
pq.pop();
if (dist[c].first <= d) continue;
dist[c] = { d, p };
for (auto& nxt : to[c]) {
int v = nxt.first, w = nxt.second;
if (d + w < dist[v].first && v != u) pq.push({ w, v, c });
}
}
int c = v;
while (c) {
in[c] = 1;
c = dist[c].second;
}
tot = dist[v].first;
for (int i = 1; i <= n; i++) {
if (!in[i]) tot += from[i];
}
cout << min(ans, tot) << "\n";
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 13820kb
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: 38ms
memory: 21456kb
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:
4 5 2 4 998973548 2 3 501271695 1 4 32454891 1 2 757288934 1 4 720856669
result:
wrong answer 1st numbers differ - expected: '1291015520', found: '4'