QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#584633 | #8136. Rebellious Edge | ucup-team3519# | WA | 48ms | 3784kb | C++14 | 1.8kb | 2024-09-23 15:57:50 | 2024-09-23 15:57:51 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define V vector
#define pb push_back
#define all0(x) (x).begin(), (x).end()
#define all0(x) (x).begin() + 1, (x).end()
#define fi first
#define se second
typedef pair<int, int> pi;
typedef long long LL;
const LL INFLL = 8e18 + 1000;
const int MN = 2e5 + 10;
int f[MN], siz[MN];
int par(int x) {
if(x == f[x]) return x;
return f[x] = par(f[x]);
}
void mer(int a, int b) {
a = par(a), b = par(b);
if(a == b) return ;
f[a] = b;
siz[b] += siz[a];
}
void ini(int n) {
for(int i = 1; i <= n; i++) {
f[i] = i, siz[i] = 1;
}
}
void solve() {
int n, m; cin >> n >> m;
int a = -1, b;
int c;
V<array<int, 3>> E;
for(int i = 1; i <= m; i++) {
int x, y; cin >> x >> y;
int w; cin >> w;
if(x < y) E.pb({x, y, w});
else if(x != y && y != 1) a = y, b = x, c = w;
}
sort(all0(E), [&](array<int, 3> a, array<int, 3> b) {
return a[2] > b[2];
});
LL ans = INFLL;
ini(n);
LL cur = 0;
int cnt = 0;
for(auto [x, y, w] : E) {
if(par(x) != par(y)) {
mer(x, y), cur += w, cnt++;
}
}
if(cnt == n - 1) {
ans = min(ans, cur);
}
if(a != -1) {
ini(n);
LL cur = c;
int cnt = 0;
for(auto [x, y, w] : E) {
if(par(y) == par(a)) swap(x, y);
if(par(x) != par(y) && !(par(x) == par(a) && (par(y) == par(b) || par(y) == par(1)))) {
mer(x, y), cur += w, cnt++;
}
}
if(cnt == n - 2) {
ans = min(ans, cur);
}
}
cout << ans << endl;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t = 1;
cin >> t;
while(t--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3784kb
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: 48ms
memory: 3536kb
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:
2257534177 1843815446 1679137070 577225018 1484057993 1708570766 2567005573 1648624744 1034153425 793861088 605832428 1200115937 1548359945 1636369163 1116032856 1899616226 1756229474 572354390 990107642 1435190797 2039835263 1002892611 2338525983 1890488892 1937057770 1022052668 2331748605 11437330...
result:
wrong answer 1st numbers differ - expected: '1291015520', found: '2257534177'