QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#272410 | #7883. Takeout Delivering | ucup-team1001# | TL | 240ms | 32912kb | C++20 | 2.3kb | 2023-12-02 17:11:14 | 2023-12-02 17:11:14 |
Judging History
answer
#include "bits/stdc++.h"
#pragma GCC optimize(3)
#define ll long long
const int inf = 2100000000;
using namespace std;
#define IOS ios::sync_with_stdio(0),cin.tie(0);
#define irep(i, l, r) for(int i = (l); i <= (r); ++ i)
array<int, 3> e[1000009];
const int N = 300099;
int fa[N], sz[N];
inline int find(int x){
if(fa[x] == x)return x;
fa[x] = find(fa[x]);
return fa[x];
}
void solve() {
int n, m;
cin >> n >> m;
vector<int>a(n, inf), b(n, inf);
// vector<int>fa(n);
irep(i, 0, m - 1){
int u, w, v;
cin >> u >>v >>w;
e[i] = {w, u - 1, v - 1};
}
irep(i, 0, n - 1)
fa[i] = i;
sort(e, e + m);
int ans = inf;
a[0] = 0, b[n - 1] = 0;
vector<vector<int>>it(n);
auto merge = [&](int x,int y, int tag)->void{
x = find(x), y = find(y);
if(x == y)return;
if(x == find(0)){
for(int i : it[y]){
a[i] = tag;
}
}
if(y == find(0)){
for(int i :it[x]){
a[i] = tag;
}
}
if(x == find(n - 1)){
for(int i : it[y]){
b[i] = tag;
}
}
if(y == find(n - 1)){
for(int i :it[x]){
b[i] = tag;
}
}
if(sz[x] < sz[y]){
for(int ii : it[x]){
it[y].emplace_back(ii);
}
it[x].clear();
it[x].shrink_to_fit();
sz[y] += sz[x];
fa[x] = y;
}
else{
for(int ii : it[y]){
it[x].emplace_back(ii);
}
it[y].clear();
it[y].shrink_to_fit();
sz[x] += sz[y];
fa[y] = x;
}
};
irep(i, 0, n - 1){
sz[i] = i, it[i].emplace_back(i);
}
for(int i = 0; i < m; ++ i){
auto [w, u, v] = e[i];
merge(u, v, w);
}
for(int i = 0; i < m; ++ i){
auto [w, u, v] = e[i];
if (min(max(a[u], b[v]), max(a[v], b[u])) > w)continue;
ans = min({ans, max(a[u], b[v]) + w, max(a[v], b[u]) + w});
}
cout << ans;
}
int main(){
IOS
int t = 1;
while (t--)solve();
}
/*
* 3 2
1 2 1000000000
2 3 1000000000
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5560kb
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: 126ms
memory: 31828kb
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: 0
Accepted
time: 240ms
memory: 32912kb
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:
1989898633
result:
ok 1 number(s): "1989898633"
Test #4:
score: -100
Time Limit Exceeded
input:
300000 299999 1 118488 989720257 1 181002 810258689 1 254222 172925351 1 176703 737330574 1 218306 941887568 1 105741 645573853 1 188490 794789787 1 273997 91455946 1 214929 293300204 1 127289 600097406 1 30589 330284120 1 128954 532459734 1 163729 627033607 1 24073 718818252 1 41571 755054850 1 560...