QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#584619#8136. Rebellious Edgeucup-team3519#WA 58ms3556kbC++201.7kb2024-09-23 15:50:322024-09-23 15:50:33

Judging History

你现在查看的是最新测评结果

  • [2024-09-23 15:50:33]
  • 评测
  • 测评结果:WA
  • 用时:58ms
  • 内存:3556kb
  • [2024-09-23 15:50:32]
  • 提交

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;
    }  
    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();
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3544kb

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: 58ms
memory: 3556kb

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:

1532700134
1793417137
1534956009
577225018
1484057993
1541095843
2339169587
1519781575
1016272662
727214725
605832428
1200115937
1107806599
1265994009
1116032856
1678219738
1610587072
551605121
960978736
955789238
1658558476
1002892611
1782589409
1890488892
1863906917
301878233
2097949028
1024594453...

result:

wrong answer 1st numbers differ - expected: '1291015520', found: '1532700134'