QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#658416 | #7883. Takeout Delivering | Zlin05 | WA | 68ms | 10832kb | C++23 | 1.6kb | 2024-10-19 16:47:25 | 2024-10-19 16:47:26 |
Judging History
answer
//
// Created by Zlin on 2024/10/19.
//
#include "bits/stdc++.h"
using namespace std;
typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
const int N = 3e5 + 5;
const ll inf = 1e17;
int n, m;
ll cnt;
struct edge {
int u, v, val;
bool operator<(const edge &x) const {
return val < x.val;
}
};
int f[N];
int find(int u) { return f[u] == u ? u : f[u] = find(f[u]); }
bool merge(int x, int y) {
int fx = find(x), fy = find(y);
if (fx == fy) return false;
--cnt;
f[fx] = fy;
return true;
}
vector<edge> all;
inline void Zlin() {
cin >> n >> m;
for (int i = 1, u, v, val; i <= m; i++) {
cin >> u >> v >> val;
all.push_back({u, v, val});
}
sort(all.begin(), all.end());
for (int i = 1; i <= n; i++) f[i] = i;
int top1 = 0, top2 = 0, x, y, val;
cnt = n;
for (edge it: all) {
x = it.u, y = it.v, val = it.val;
if (merge(x, y)) {
if (val > top1) {
top2 = top1;
top1 = val;
} else if (val > top2) {
top2 = val;
}
}
if (cnt == 1) break;
}
cout << top1 + top2 << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
int ttt = 1;
// cin >> ttt;
while (ttt--) Zlin();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3700kb
input:
4 6 1 2 2 1 3 4 1 4 7 2 3 1 2 4 3 3 4 9
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: 0
Accepted
time: 68ms
memory: 10832kb
input:
300000 299999 80516 80517 597830404 110190 110191 82173886 218008 218009 954561262 250110 250111 942489774 66540 66541 156425292 34947 34948 239499776 273789 273790 453201232 84428 84429 439418398 98599 98600 326095035 55636 55637 355015760 158611 158612 684292473 43331 43332 43265001 171621 171622 ...
output:
1999991697
result:
ok 1 number(s): "1999991697"
Test #3:
score: -100
Wrong Answer
time: 65ms
memory: 10416kb
input:
300000 299999 207226 231742 414945003 84591 210444 175968953 46327 51582 612565723 18773 141119 82562646 76139 286963 762958587 131867 224820 928900783 215240 216181 405340417 144725 290878 195350550 267216 268752 846015171 31413 255927 389339642 45219 147512 489502910 113391 215402 555706684 53359 ...
output:
1999989072
result:
wrong answer 1st numbers differ - expected: '1989898633', found: '1999989072'