QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#18081 | #2178. Robot | _silhouette_# | 34 | 88ms | 22896kb | C++ | 1.9kb | 2022-01-16 10:39:37 | 2022-05-04 17:03:06 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int Max_N=1e5,Max_M=2e5,B=1e6;
const long long Inf=1e18;
int n,m,Num,lin[Max_N+5];
long long sum[Max_M+5];
map<int,long long> dis[Max_N+5],vis[Max_N+5];
struct Edge_fir{ int u,v,c,p; } E[Max_M+5];
vector<int> a[Max_N+5];
priority_queue< pair< long long, long long > > Q;
struct Edge{
int Next,Id,c;
long long val;
} e[Max_M*8+5];
void Insert(int x,int y,int c,long long w){
e[++Num].Next=lin[x]; lin[x]=Num; e[Num].Id=y; e[Num].c=c; e[Num].val=w;
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++){
scanf("%d%d%d%d",&E[i].u,&E[i].v,&E[i].c,&E[i].p);
a[E[i].u].push_back(i),a[E[i].v].push_back(i);
dis[E[i].u][i]=Inf,dis[E[i].v][i]=Inf;
}
for(int x=1;x<=n;x++){
dis[x][-1]=Inf;
for(int i=0;i<a[x].size();i++)
sum[E[a[x][i]].c]+=E[a[x][i]].p;
for(int i=0;i<a[x].size();i++)
Insert(x,x^E[a[x][i]].v^E[a[x][i]].u,a[x][i],E[a[x][i]].p),
Insert(x,x^E[a[x][i]].v^E[a[x][i]].u,-a[x][i],sum[E[a[x][i]].c]-E[a[x][i]].p);
for(int i=0;i<a[x].size();i++)
sum[E[a[x][i]].c]-=E[a[x][i]].p;
}
Q.push(make_pair(0,B));
dis[1][-1]=0;
for(;Q.size();){
int x=Q.top().second/B;
int c=Q.top().second%B-1; Q.pop();
if(vis[x][c]) continue; vis[x][c]=1;
for(int i=lin[x];i;i=e[i].Next){
if(c!=-1&&e[i].c<0&&E[c].c==E[-e[i].c].c){
if(dis[x][c]+e[i].val-E[c].p<dis[e[i].Id][-1])
dis[e[i].Id][-1]=dis[x][c]+e[i].val-E[c].p,
Q.push(make_pair(-dis[e[i].Id][-1],e[i].Id*B));
} else{
if(dis[x][c]+e[i].val<dis[e[i].Id][max(e[i].c,-1)])
dis[e[i].Id][max(e[i].c,-1)]=min(dis[e[i].Id][max(e[i].c,-1)],dis[x][c]+e[i].val),
Q.push(make_pair(-dis[e[i].Id][max(e[i].c,-1)],e[i].Id*B+max(e[i].c,-1)+1));
}
}
}
long long ans=Inf;
for(map<int,long long>::iterator It=dis[n].begin();It!=dis[n].end();++It)
ans=min(ans,(*It).second);
printf("%lld\n",ans==Inf?-1:ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 34
Accepted
Test #1:
score: 34
Accepted
time: 0ms
memory: 18088kb
input:
2 1 1 2 1 10
output:
0
result:
ok single line: '0'
Test #2:
score: 0
Accepted
time: 3ms
memory: 22232kb
input:
8 1 5 6 1 7
output:
-1
result:
ok single line: '-1'
Test #3:
score: 0
Accepted
time: 2ms
memory: 18144kb
input:
8 19 4 8 15 5 7 8 15 6 1 4 15 6 3 4 2 10 2 7 15 10 5 6 2 10 1 7 2 3 4 5 15 7 1 6 15 6 2 5 2 6 1 8 15 2 1 2 15 9 5 7 2 5 3 8 2 5 4 7 2 6 6 7 15 8 3 7 15 6 2 8 2 1 5 8 15 6
output:
2
result:
ok single line: '2'
Test #4:
score: 0
Accepted
time: 2ms
memory: 20088kb
input:
4 6 1 2 1 7 3 4 1 10 2 3 2 5 2 4 1 4 1 4 6 2 1 3 1 2
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 8ms
memory: 20228kb
input:
64 106 7 46 100 641441921 4 22 92 909042053 27 46 100 185644091 52 54 100 333473988 21 41 69 747879553 23 45 24 121784836 16 23 69 538978180 15 42 92 403583091 49 60 69 112127397 44 48 21 733685727 18 40 92 287239281 3 30 48 498139743 21 25 24 281665265 13 24 69 315527284 12 35 21 100990101 33 56 10...
output:
-1
result:
ok single line: '-1'
Test #6:
score: 0
Accepted
time: 0ms
memory: 18152kb
input:
10 45 6 7 29 19322896 6 8 29 826842878 5 9 29 229755065 1 6 29 49301462 4 10 29 356862039 3 7 29 377906409 8 10 29 877820670 4 8 29 150486169 1 10 29 291057766 1 5 29 982043864 1 3 29 126557279 5 6 29 721959799 3 10 29 636909401 1 7 29 772752473 5 8 29 523364181 7 9 29 250673970 2 6 29 417264209 2 4...
output:
255671682
result:
ok single line: '255671682'
Test #7:
score: 0
Accepted
time: 14ms
memory: 20496kb
input:
71 788 5 24 146 614916874 56 61 567 467226384 16 44 275 490241032 14 25 567 779488700 19 42 262 524833651 6 19 567 912315689 8 21 774 326632848 46 62 675 296672130 27 32 715 104878301 13 47 675 546642528 18 68 675 349712771 8 43 146 305351688 13 58 567 776051722 49 63 601 454628166 30 43 715 7695855...
output:
46083838
result:
ok single line: '46083838'
Test #8:
score: 0
Accepted
time: 6ms
memory: 18384kb
input:
55 443 11 21 307 732223755 32 42 307 182136903 47 48 346 925071240 45 53 307 225221704 1 45 307 807617287 28 46 307 644657251 2 42 346 807672874 39 42 346 173126332 11 50 346 105073586 48 53 346 363756204 19 27 346 749462761 8 20 346 838034581 28 31 307 183749842 28 53 346 909041858 33 50 346 364806...
output:
342534314
result:
ok single line: '342534314'
Test #9:
score: 0
Accepted
time: 55ms
memory: 19040kb
input:
999 1988 153 528 1690 1 1 867 1158 1 481 785 1741 1 226 528 203 1 356 481 1957 1 278 481 716 1 168 528 612 1 1 140 489 1 528 533 446 1 4 528 1715 1 481 698 1350 1 35 528 1658 1 528 601 1345 1 24 481 559 1 524 528 88 1 1 606 1547 1 481 493 1017 1 165 528 1685 1 481 849 1847 1 528 711 1464 1 1 663 222...
output:
3
result:
ok single line: '3'
Test #10:
score: 0
Accepted
time: 43ms
memory: 18908kb
input:
999 1988 328 983 1573 1 130 468 1140 1 44 983 210 1 15 983 1848 1 517 983 1451 1 1 131 563 1 1 209 182 1 130 793 1295 1 130 947 1295 1 130 680 1295 1 130 214 1295 1 584 983 567 1 726 983 1019 1 130 456 1295 1 198 575 1295 1 1 6 283 1 200 575 1295 1 205 575 1295 1 1 399 1128 1 130 589 1510 1 923 983 ...
output:
3
result:
ok single line: '3'
Test #11:
score: 0
Accepted
time: 75ms
memory: 22896kb
input:
1000 1990 528 730 1843 1 523 730 1843 1 124 894 1843 1 224 730 1843 1 124 617 1843 1 679 730 1843 1 124 913 1843 1 488 730 1843 1 493 730 1843 1 730 748 1843 1 730 959 1843 1 124 437 1843 1 124 187 1843 1 124 332 1843 1 124 279 1843 1 124 961 1843 1 124 744 1843 1 203 730 1843 1 723 730 1843 1 730 9...
output:
3
result:
ok single line: '3'
Test #12:
score: 0
Accepted
time: 31ms
memory: 20872kb
input:
998 1658 296 805 151 1 141 805 151 1 218 983 151 2 1 608 151 2 1 49 151 2 740 805 151 1 225 805 151 1 218 420 151 2 87 266 151 1 218 527 151 2 1 374 151 2 218 905 151 2 699 744 151 1 660 805 151 1 836 889 151 1 62 805 151 1 184 218 151 2 95 457 151 1 218 985 151 2 218 621 151 2 1 577 151 2 587 981 1...
output:
666
result:
ok single line: '666'
Test #13:
score: 0
Accepted
time: 77ms
memory: 19132kb
input:
1000 1983 752 787 507 1 752 832 507 1 752 927 507 1 556 581 507 1 581 891 507 1 451 581 507 1 107 581 507 1 752 765 507 1 81 752 507 2 251 581 507 1 581 859 507 1 321 581 507 1 55 581 507 1 752 814 507 1 581 780 507 1 581 790 507 1 387 581 507 1 356 752 507 1 581 932 507 1 1 889 507 2 581 893 507 1 ...
output:
989
result:
ok single line: '989'
Test #14:
score: 0
Accepted
time: 88ms
memory: 18972kb
input:
1000 1983 415 567 756 1 62 709 756 1 89 709 756 1 417 709 756 1 457 709 756 1 149 415 756 1 709 964 756 1 275 709 756 1 709 928 756 1 299 709 756 1 487 709 756 1 709 791 756 1 415 967 756 1 415 941 756 1 217 709 756 1 709 984 756 1 415 604 756 1 212 415 756 1 399 415 756 1 438 709 756 1 294 709 756 ...
output:
26
result:
ok single line: '26'
Test #15:
score: 0
Accepted
time: 3ms
memory: 18616kb
input:
1000 999 656 793 229 300116971 200 526 229 848062849 57 209 229 748009426 608 970 229 962221417 161 721 229 384089949 260 595 229 428874737 156 233 229 577150696 158 385 229 738154446 136 709 229 67894231 25 903 229 397142287 732 767 229 957266971 550 781 229 823510106 384 752 229 406598247 5 271 22...
output:
201664848082
result:
ok single line: '201664848082'
Test #16:
score: 0
Accepted
time: 5ms
memory: 18976kb
input:
1000 1998 216 873 802 148650296 85 606 802 89598343 113 720 802 287659390 468 531 802 204322693 331 564 802 373686511 583 642 802 115887999 602 719 802 233321776 642 944 802 57082002 916 950 802 92555430 143 352 802 461653014 434 687 802 72505880 238 659 802 31377094 187 375 802 140765767 250 272 80...
output:
18092395296
result:
ok single line: '18092395296'
Test #17:
score: 0
Accepted
time: 11ms
memory: 18828kb
input:
800 1478 477 620 933 5658029 288 630 933 374079479 93 181 1082 151764046 469 690 1082 161114493 100 381 933 708106586 266 327 1082 738393737 17 495 933 368385363 312 496 933 399240908 165 548 1082 436276578 389 677 933 31330966 310 493 933 121847365 361 459 933 576299908 396 796 933 981781202 60 303...
output:
-1
result:
ok single line: '-1'
Test #18:
score: 0
Accepted
time: 2ms
memory: 20356kb
input:
915 572 332 504 416 228776811 435 728 445 412258532 93 182 506 914985113 10 162 416 307159431 339 583 416 622601819 738 814 445 464379203 787 795 560 265814135 806 820 445 529333835 774 798 506 119778570 435 583 506 6220730 374 789 560 753701380 441 693 560 808760860 81 102 506 803896086 383 507 506...
output:
-1
result:
ok single line: '-1'
Test #19:
score: 0
Accepted
time: 18ms
memory: 20956kb
input:
100 2000 35 48 1983 65612927 31 53 60 76830022 30 56 1764 65879682 32 35 60 20526498 38 83 60 28781478 31 99 60 2620538 32 51 1983 32927409 5 73 1764 2812104 7 41 1983 10191012 13 90 60 71582220 10 50 1262 38366351 45 80 1262 15238959 23 82 1983 12778753 39 48 1675 27393975 82 87 1764 48078651 28 96...
output:
153828372
result:
ok single line: '153828372'
Test #20:
score: 0
Accepted
time: 6ms
memory: 20868kb
input:
1000 1332 60 826 1091 1000000000 603 878 1091 1000000000 511 904 1091 999999999 111 952 1091 999999999 10 634 1091 1000000000 582 840 1091 999999999 87 486 1091 999999999 156 748 1091 999999999 45 232 1091 1000000000 625 940 1091 999999999 84 380 1091 1000000000 49 490 1091 999999999 184 909 1091 10...
output:
665999999497
result:
ok single line: '665999999497'
Subtask #2:
score: 0
Runtime Error
Test #21:
score: 0
Runtime Error
input:
25437 78923 921 9998 30945 1 5452 13736 24464 1 11746 24238 24464 1 10875 12958 24464 1 12267 20617 30945 1 3738 16549 35589 1 16223 16940 35589 1 1303 23059 24464 1 12424 21853 24464 1 11198 20674 35589 1 15645 19099 30945 1 8860 9441 24464 1 3609 15160 35589 1 22638 23472 24464 1 766 8991 35589 1 ...
output:
result:
Subtask #3:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%