QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#345177 | #7883. Takeout Delivering | oath | TL | 1707ms | 17304kb | C++14 | 2.1kb | 2024-03-06 12:56:00 | 2024-03-06 12:56:01 |
Judging History
answer
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
typedef pair<int, int> PII;
const int N = 1e6 + 10;
int dist[N];
int st[N];
int n, m;
int p[N];
struct edge
{
int a, b ,w ;
bool operator < (const edge &W) const
{
return w < W.w;
}
}edges[N*2];
int find(int x)
{
if(x != p[x]) p[x] = find(p[x]);
return p[x];
}
signed main()
{
cin >> n >> m;
int res = 0x7f7f7f7f;
for(int i = 0; i < m; i++)
{
int x, y, z;
cin >> x >> y >> z;
if(x == 1 && y == n) res = min(res, z);
edges[i] = {x, y, z};
}
sort(edges, edges + m);
for(int i = 1; i <= n; i++) p[i] = i;
//cout << res << endl;
std::vector<edge> ans;
for(int i = 0; i < m ;i++)
{
int a = edges[i].a, b = edges[i].b, w =edges[i].w;
int pa = find(a), pb = find(b);
int t = p[pa];
if(pa != pb)
{
p[pa] = pb;
}
int a1 = find(1), a2 = find(n);
if(a1 == a2)
{
ans.push_back(edges[i]);
p[pa] = t;
st[i] = 1;
}
}
int cnt = ans.size();
//cout << << endl;
/*for(int i = 0; i <ans.size(); i++){
int a = ans[i].a, b = ans[i].b, w =ans[i].w;
cout << a << ' ' << b << ' ' << w << endl;
}*/
for(int i = 1; i <= n; i++) p[i] = i;
for(int i = 0; i < m ;i++)
{
if(st[i]) continue;
int a = edges[i].a, b = edges[i].b, w =edges[i].w;
int pa = find(a), pb = find(b);
int t = p[pa];
if(pa != pb)
{
p[pa] = pb;
}
for(int j = 0; j < cnt;j++){
int sa = ans[j].a, sb = ans[j].b, sw =ans[j].w;
int psa = find(sa), psb = find(sb);
t = p[psa];
if(psa != psb)
{
p[psa] = psb;
}
int a1 = find(1), a2 = find(n);
if(a1 == a2)
{
res = min(res, w + sw);
p[psa] = t;
cnt = j;
}
}
}
cout << res <<endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7680kb
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: 203ms
memory: 11896kb
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: 1707ms
memory: 15476kb
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: 0
Accepted
time: 174ms
memory: 17304kb
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...
output:
725564985
result:
ok 1 number(s): "725564985"
Test #5:
score: 0
Accepted
time: 205ms
memory: 15716kb
input:
300000 299999 19784 19785 438457172 153297 239456 192671538 153297 202254 645947104 9640 9641 583410541 153297 221084 490232940 32210 32211 838809517 153297 171896 625627853 153297 216946 683286844 110843 110844 690710575 153297 176413 983037656 74908 74909 375017711 67676 67677 695121437 153297 196...
output:
1999992880
result:
ok 1 number(s): "1999992880"
Test #6:
score: 0
Accepted
time: 208ms
memory: 11888kb
input:
300000 299999 130662 244000 579178004 167657 294630 753914681 61924 61925 165841675 113560 113561 979316325 151574 218075 973289843 1224 1225 230803236 133441 133442 806726301 167309 249456 853031541 120245 120246 688705252 142688 217826 692299631 106114 106115 735998084 123268 123269 749737073 1208...
output:
1999989691
result:
ok 1 number(s): "1999989691"
Test #7:
score: -100
Time Limit Exceeded
input:
300000 299999 54474 108948 971770803 11077 22155 470962125 115359 230718 373029049 124472 248944 865510218 11958 23917 100575860 130349 260698 582886291 17563 35127 697131917 54427 108854 274252758 51546 103092 198620066 100126 200252 154524070 14994 29988 528701437 147502 295004 531813162 42285 845...