QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#681984 | #7883. Takeout Delivering | WedonotLikeStudying# | WA | 93ms | 28928kb | C++23 | 3.0kb | 2024-10-27 13:20:34 | 2024-10-27 13:20:36 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(a,b,c) for(int a=(b);a<=(c);a++)
#define per(a,b,c) for(int a=(b);a>=(c);a--)
#define ll long long
#define vi vector<int>
#define pb emplace_back
using namespace std;
template<class T>inline void read(T &x) {
T f=1; x=0; char s=getchar();
while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}
x*=f;
}
const int N=3e5;
const int M=1e6;
struct Edge {
int u,v,w;
}e[M+5],ed[M*2+5];
inline bool cmp(Edge a,Edge b) {
return a.w<b.w;
}
int head[N+5],ecnt,Mx;
inline void adde(int u,int v,int w) {
ed[++ecnt].v=v;
ed[ecnt].w=w;
ed[ecnt].u=head[u];
head[u]=ecnt;
}
inline void add(int u,int v,int w) { adde(u,v,w); adde(v,u,w); }
int bcj[N+5];
inline int find(int x) { return (bcj[x]==x)?(x):(bcj[x]=find(bcj[x])); }
int n,m,d1[N+5],d2[N+5],Ans,ans;
inline void dfs1(int x,int fa) {
for(int i=head[x],v;i;i=ed[i].u) {
v=ed[i].v;
if(v==fa) continue;
d1[v]=max(d1[x],ed[i].w);
dfs1(v,x);
}
}
inline void dfs2(int x,int fa) {
for(int i=head[x],v;i;i=ed[i].u) {
v=ed[i].v;
if(v==fa) continue;
d2[v]=max(d2[x],ed[i].w);
dfs2(v,x);
}
}
int Mx1,Mx2;
inline void dfs3(int x,int fa) {
if(x==n) {
Ans=Mx1+Mx2;
return;
}
for(int i=head[x],v;i;i=ed[i].u) {
v=ed[i].v;
if(v==fa) continue;
int tmp1=Mx1,tmp2=Mx2;
if(ed[i].w>=Mx1) Mx2=Mx1,Mx1=ed[i].w;
else if(ed[i].w>=Mx2) Mx2=ed[i].w;
dfs3(v,x);
Mx1=tmp1; Mx2=tmp2;
}
}
inline int chk(int x1,int y1,int x2,int y2) {
if(x1>y1) swap(x1,y1);
if(x2>y2) swap(x2,y2);
return (x1==x2)&&(y1==y2);
}
inline void solve() {
read(n); read(m);
rep(i,1,m) {
read(e[i].u);
read(e[i].v);
read(e[i].w);
}
sort(e+1,e+m+1,cmp);
rep(i,1,n) bcj[i]=i;
for(int i=1,j=0;i<=m;i=j+1) {
j=i;
while((j<m)&&(e[j+1].w==e[j].w)) j++;
int tag=0;
if(find(1)!=find(n)) {
rep(k,i,j) if(chk(find(1),find(n),find(e[k].u),find(e[k].v))) tag=1;
}
if(tag) {
dfs1(1,0); dfs2(n,0);
int Tmp=0x7fffffff;
rep(k,i,j) if(chk(find(1),find(n),find(e[k].u),find(e[k].v))) {
int x=find(e[k].u),y=find(e[k].v);
if(x==find(1)) x=e[k].u,y=e[k].v;
else x=e[k].v,y=e[k].u;
if(Tmp>(e[k].w+max(d1[x],d2[y]))) Tmp=e[k].w+max(d1[x],d2[y]);
}
Ans=Tmp;
rep(k,i,j) if(chk(find(1),find(n),find(e[k].u),find(e[k].v))) {
int x=find(e[k].u),y=find(e[k].v);
if(x==find(1)) x=e[k].u,y=e[k].v;
else x=e[k].v,y=e[k].u;
if(Tmp==(e[k].w+max(d1[x],d2[y]))) {
x=find(e[k].u); y=find(e[k].v);
bcj[x]=y;
add(e[k].u,e[k].v,e[k].w);
Mx=k;
break;
}
}
}
rep(k,i,j) {
int x=find(e[k].u),y=find(e[k].v);
if(x==y) continue;
Mx=max(Mx,k);
add(e[k].u,e[k].v,e[k].w);
bcj[x]=y;
}
}
dfs1(1,0);
dfs2(n,0);
rep(i,1,m) if((min(e[i].u,e[i].v)==1)&&(max(e[i].u,e[i].v)==n)) Ans=min(Ans,e[i].w);
rep(i,Mx+1,m) Ans=min(Ans,e[i].w+min(max(d1[e[i].u],d2[e[i].v]),max(d2[e[i].u],d1[e[i].v])));
printf("%d\n",Ans);
}
int main() {
//int T; read(T); while(T--)
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7936kb
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: 83ms
memory: 28928kb
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: 85ms
memory: 23044kb
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: 54ms
memory: 22236kb
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: 76ms
memory: 25684kb
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: 93ms
memory: 25592kb
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: 0
Accepted
time: 69ms
memory: 22268kb
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...
output:
1823402145
result:
ok 1 number(s): "1823402145"
Test #8:
score: 0
Accepted
time: 85ms
memory: 23780kb
input:
300000 299999 240182 240189 427579190 41871 41880 360542232 57131 57140 353813367 122650 122653 621913649 67332 67340 271427538 107523 107524 774306311 60374 60379 315636931 130805 130808 667109508 154531 154534 327293148 138561 138569 833879694 32543 32551 382610722 287398 287400 211744079 59693 59...
output:
1999983202
result:
ok 1 number(s): "1999983202"
Test #9:
score: 0
Accepted
time: 0ms
memory: 9904kb
input:
10 20 1 6 98 3 4 3 4 5 26 7 8 72 1 2 86 3 7 83 7 10 89 4 7 100 3 6 59 6 9 74 5 6 28 6 7 1 2 9 100 2 6 99 5 10 85 8 10 97 2 10 98 8 9 3 2 3 94 9 10 71
output:
170
result:
ok 1 number(s): "170"
Test #10:
score: 0
Accepted
time: 1ms
memory: 7864kb
input:
10 20 2 8 94 3 7 81 8 10 85 2 4 88 4 5 90 1 4 96 3 6 95 7 10 77 1 8 98 4 7 91 2 6 38 1 10 89 1 3 45 4 9 94 3 9 64 6 10 83 5 8 19 2 5 81 6 7 92 3 4 92
output:
89
result:
ok 1 number(s): "89"
Test #11:
score: 0
Accepted
time: 1ms
memory: 7916kb
input:
10 20 1 6 58 1 4 80 1 10 28 1 3 46 6 7 76 7 10 75 4 9 95 2 10 92 1 7 15 9 10 52 3 6 93 5 7 94 1 2 75 1 5 41 3 7 79 4 8 94 2 6 80 6 9 63 1 9 42 1 8 9
output:
28
result:
ok 1 number(s): "28"
Test #12:
score: 0
Accepted
time: 1ms
memory: 10044kb
input:
10 20 6 9 79 5 6 72 2 5 74 2 4 74 8 10 90 1 5 82 3 4 55 6 10 94 7 8 55 3 7 92 1 8 83 9 10 93 4 7 98 4 5 24 2 3 28 6 7 24 1 2 63 3 10 99 8 9 2 5 10 95
output:
158
result:
ok 1 number(s): "158"
Test #13:
score: 0
Accepted
time: 1ms
memory: 7912kb
input:
10 20 3 4 75 5 7 98 3 10 91 5 8 41 2 7 84 2 3 73 4 10 100 2 4 80 1 5 99 3 9 79 4 5 97 4 9 10 4 7 52 1 10 96 8 10 98 6 9 99 1 2 50 5 9 98 2 9 93 3 6 92
output:
96
result:
ok 1 number(s): "96"
Test #14:
score: 0
Accepted
time: 1ms
memory: 9960kb
input:
10 20 1 5 84 9 10 98 2 3 56 2 4 5 3 9 95 4 9 94 3 7 82 6 8 68 1 3 10 4 8 64 3 6 46 5 10 58 5 7 92 6 7 96 1 2 38 2 5 74 1 8 70 8 9 100 4 7 93 7 9 98
output:
132
result:
ok 1 number(s): "132"
Test #15:
score: 0
Accepted
time: 1ms
memory: 9984kb
input:
10 20 2 10 100 8 10 100 7 10 85 3 7 73 5 7 100 4 9 100 1 8 7 2 4 26 6 8 27 3 4 100 6 7 100 2 3 99 3 9 66 9 10 13 4 8 75 1 2 8 4 10 100 1 6 19 7 9 99 2 5 49
output:
107
result:
ok 1 number(s): "107"
Test #16:
score: 0
Accepted
time: 1ms
memory: 7868kb
input:
100 200 60 77 957 70 71 589 63 64 915 13 79 1000 8 9 757 41 42 141 21 53 1000 82 99 911 58 59 683 62 63 889 92 93 455 71 72 457 11 92 1000 9 43 1000 94 95 582 57 58 606 54 55 162 27 28 732 99 100 256 42 43 201 13 99 1000 15 73 1000 19 20 646 22 91 1000 22 50 1000 93 94 888 14 15 904 10 47 1000 68 83...
output:
1671
result:
ok 1 number(s): "1671"
Test #17:
score: -100
Wrong Answer
time: 1ms
memory: 9908kb
input:
100 200 21 59 969 4 22 998 47 98 637 8 51 982 48 55 995 14 65 22 3 35 987 40 46 969 6 82 432 13 98 960 24 49 965 5 32 571 20 71 617 71 82 982 30 66 979 76 79 255 7 56 965 18 21 971 53 65 81 63 64 991 6 88 949 1 13 995 31 38 405 40 91 952 47 89 956 8 84 475 29 90 202 6 12 975 30 89 509 47 88 82 4 58 ...
output:
1888
result:
wrong answer 1st numbers differ - expected: '1859', found: '1888'