QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#864801#4809. Maximum Rangegyydp123_LIMWA 58ms20724kbC++203.0kb2025-01-21 08:35:292025-01-21 08:35:30

Judging History

你现在查看的是最新测评结果

  • [2025-01-21 08:35:30]
  • 评测
  • 测评结果:WA
  • 用时:58ms
  • 内存:20724kb
  • [2025-01-21 08:35:29]
  • 提交

answer

#include<bits/stdc++.h>
#define For(i,j,k) for(int i=(j);i<=(k);++i)
#define ForDown(i,j,k) for(int i=(j);i>=(k);--i)
#define Debug(fmt, args...) fprintf(stderr,"(func %s, line #%d): " fmt,__func__,__LINE__,##args),fflush(stderr)
#define debug(fmt, args...) fprintf(stderr,fmt,##args),fflush(stderr)
#define within :
#define LJY main
using namespace std;
typedef long long ll;
const int N=1e5+5,inf=1e9+7;
mt19937 rnd(chrono::system_clock::now().time_since_epoch().count());
inline int read(){
  char ch=getchar();int x=0,f=1;
  while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
  while(ch>='0'&&ch<='9')
    x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
  return x*f;
}
int n,m;
vector<tuple<int,int,int> >G[N];
tuple<int,int,int>E[N];
int dfn[N],low[N],cdfn,stk[N],tp;
int bel[N],bcc,Mx[N],Mn[N],Mnid[N],Mxid[N];
void tarjan(int u,int fa){
  dfn[u]=low[u]=++cdfn;stk[++tp]=u;
  for(auto [v,_,__] within G[u]) if(v!=fa){
    if(!dfn[v]) tarjan(v,u),low[u]=min(low[u],low[v]);
    else low[u]=min(low[u],dfn[v]);
  }if(low[u]==dfn[u]){
    int y;++bcc;Mn[bcc]=inf;Mx[bcc]=-inf;
    while(y=stk[tp--]){bel[y]=bcc;if(y==u) break;}
  }
}
int h[N],dep[N],cur[N],ce=1,s,t;
struct Edge{int v,w,nxt;}e[N<<1];
void addedge(int u,int v){
  debug("%d %d\n",u,v);
  e[++ce]={v,1,h[u]};h[u]=ce;e[++ce]={u,1,h[v]};h[v]=ce;}
vector<int>Ans;
bool bfs(){
  static queue<int>q;while(!q.empty()) q.pop();
  For(i,1,t) dep[i]=0,cur[i]=h[i];dep[s]=1;q.emplace(s);
  while(!q.empty()){
    int u=q.front();q.pop();
    for(int i=h[u];i;i=e[i].nxt) if(e[i].w&&!dep[e[i].v]){
      int v=e[i].v;dep[v]=dep[u]+1;
      if(v==t) return 1;q.emplace(v);
    }
  }return 0;
}
int dfs(int u,int flow){
  if(u==t) return flow;int rec=0;
  for(int&i=cur[u];i;i=e[i].nxt){
    int v=e[i].v,w=e[i].w;
    if(!w||dep[v]!=dep[u]+1) continue;
    int ret=dfs(v,min(flow-rec,e[i].w));
    rec+=ret;e[i].w-=ret;e[i^1].w+=ret;
    if(rec==flow) return flow;
  }return rec;
}
void Dinic(int S,int T){s=S;t=T;while(bfs()) dfs(s,inf);}
void print(int u,int v){
  // debug("%d %d\n",u,v);
  if(u<=n) Ans.emplace_back(u);if(u==v) return;
  for(int i=h[u];i;i=e[i].nxt) if(!e[i].w){e[i].w=inf;print(e[i].v,v);return;}
}
signed LJY(){
  n=read();m=read();
  For(i,1,m){
    int u=read(),v=read(),w=read();E[i]={u,v,w};
    G[u].emplace_back(v,w,i);
    G[v].emplace_back(u,w,i);
  }For(i,1,n) if(!dfn[i]) tarjan(i,0);
  For(i,1,n) for(auto [v,w,id] within G[i]) if(bel[i]==bel[v]){
    if(Mn[bel[i]]>w) Mn[bel[i]]=w,Mnid[bel[i]]=id;
    if(Mx[bel[i]]<w) Mx[bel[i]]=w,Mxid[bel[i]]=id;
  }int ans=0,id=0;
  For(i,1,bcc) if(Mx[i]-Mn[i]>ans) ans=Mx[i]-Mn[i],id=i;
  printf("%d\n",ans);int S=n+1,T=n+2;
  auto [u,v,w]=E[Mnid[id]];addedge(S,u);addedge(S,v);
  tie(u,v,w)=E[Mxid[id]];addedge(u,T);addedge(v,T);
  For(i,1,n) if(bel[i]==id) for(auto [v,w,Id] within G[i])
    if(i<v&&bel[v]==id&&Id!=Mnid[id]&&Id!=Mxid[id]) addedge(i,v);
  Dinic(S,T);print(S,T);reverse(Ans.begin(),Ans.end());print(S,T);
  printf("%d\n",Ans.size());for(int x within Ans) printf("%d ",x);
  return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 10076kb

input:

5 7
1 2 1
1 3 -2
2 3 1
3 4 3
4 5 1
1 5 -1
2 5 2

output:

5
4
3 1 5 4 

result:

ok ok

Test #2:

score: 0
Accepted
time: 19ms
memory: 17396kb

input:

99997 100000
12238 99016 352755196
99016 25485 -412473602
25485 2440 991507552
2440 31171 -181894654
36970 2440 -800167579
2440 41865 -148191946
96629 31171 847888506
36970 95740 395546542
27992 2440 647886610
99016 29557 369124914
80795 27992 -673871966
36970 3509 573208857
57672 29557 874406776
41...

output:

1959330954
37
96048 4697 44442 68883 69259 57672 29557 99016 25485 2440 31171 95092 34883 46301 96778 37694 88289 30288 68523 54073 84997 89628 67966 84407 3463 72825 51491 87712 96230 22074 72089 76022 86665 92617 74677 86274 94991 

result:

ok ok

Test #3:

score: 0
Accepted
time: 24ms
memory: 14932kb

input:

99997 100000
41884 21178 -431811360
41884 42699 -450057006
36523 21178 582079730
21178 96679 615552614
63637 21178 498974417
96679 5108 235820276
75058 41884 220112636
35148 42699 589595309
36523 18002 -637739861
65854 5108 -312755792
45137 41884 -511118771
5108 31311 554050951
25335 35148 -28341059...

output:

1968439328
40
98098 99686 71024 89860 18331 78274 35287 14678 59612 54901 26981 83047 87303 41126 28694 6204 50088 5108 7577 69337 51434 52252 25926 90144 26071 33264 70298 99716 98733 71151 55330 83919 83711 38202 85192 45137 41884 42699 87673 23692 

result:

ok ok

Test #4:

score: 0
Accepted
time: 21ms
memory: 14936kb

input:

99984 99999
33974 29867 335681778
33974 87468 348956829
83048 87468 320849805
29867 69456 -424530698
72457 69456 -950650074
53838 83048 755969166
85914 69456 569454441
51728 87468 -202158773
15970 29867 -865071002
15970 94894 697607001
94894 74694 616318126
33974 11496 -89287579
53838 34365 -6577379...

output:

1985932414
36
80694 78849 28078 91542 83656 97838 70238 5449 75902 51728 87468 83048 53838 29864 76013 1652 83298 23026 27866 92249 11395 303 46598 61993 55857 79605 58540 57640 55808 85914 75496 32897 79841 13570 35807 50114 

result:

ok ok

Test #5:

score: 0
Accepted
time: 21ms
memory: 17324kb

input:

99988 99992
8584 11873 -811540160
68064 11873 -930246087
11873 60056 916668870
68064 82193 -859062523
60056 75072 790866030
27767 75072 357619485
75072 78221 411650300
39636 82193 264106928
6675 60056 933851261
71747 78221 -508471038
11873 92771 -665232168
34402 27767 -906494982
11873 42714 63734230...

output:

1932268861
30
60056 75072 91957 3186 29873 5185 88236 50628 2518 83283 23798 89787 8975 26922 21107 93559 75593 83884 20678 16385 62720 25891 75176 34179 64174 38274 8778 99809 28745 6675 

result:

ok ok

Test #6:

score: 0
Accepted
time: 23ms
memory: 14804kb

input:

99996 99996
58191 98120 261718607
91298 98120 471683748
58191 68921 217652908
67441 91298 -731916804
78177 68921 810185021
98120 54747 -35446486
78177 2822 -409569426
91298 68058 -897038977
68921 39067 892161204
30165 78177 379543758
32418 98120 -139944101
11281 68921 422411872
37751 32418 331606200...

output:

1752928792
25
29915 78216 34081 11281 68921 58191 48440 3783 3308 58464 1917 30739 77560 4369 46983 74019 64478 81854 65221 16812 67249 25934 42296 85525 18913 

result:

ok ok

Test #7:

score: 0
Accepted
time: 24ms
memory: 17620kb

input:

99996 100000
39127 4358 657531703
4358 66528 484843263
47215 4358 -856669390
47215 26179 -147254695
24822 39127 -635228854
81984 26179 600617794
24822 60559 327733708
39127 23879 286268283
95563 81984 -766366787
96587 24822 723252700
23879 13711 -303309809
60559 38379 992907085
60559 6012 -15086498
...

output:

1948904917
51
60559 24822 39127 23879 13711 16150 60168 12024 27325 73608 58919 19383 92093 74141 3750 42006 67183 31390 97465 24485 4358 61378 82877 24890 38051 91154 63827 13465 90743 30145 41482 70789 91374 66385 37095 8030 96587 24822 10570 52647 79459 24450 54151 79904 28267 1066 23254 53517 37...

result:

ok ok

Test #8:

score: 0
Accepted
time: 20ms
memory: 15396kb

input:

99983 99998
360 38113 273639182
29807 360 -492749399
360 45494 960572841
67090 45494 -168787586
38113 61765 -90469418
71988 360 -556152065
67090 77653 704061103
30847 38113 542389160
84363 30847 295740326
30847 62591 -916431414
86104 77653 878763485
45494 11422 -795069866
86104 64096 714130240
61765...

output:

1972142685
35
64559 25273 47913 1904 50615 97340 8333 42546 32497 58830 58078 3710 93146 3381 46673 75450 28454 29807 67396 49296 2351 1877 74104 85692 24073 31895 12093 71599 84363 30847 38113 360 45494 67090 85762 

result:

ok ok

Test #9:

score: 0
Accepted
time: 23ms
memory: 14932kb

input:

99991 99993
70785 63179 -402654804
91872 63179 -441007900
30847 70785 779215016
72954 63179 -228470351
92375 30847 534166099
49724 63179 -37611056
44235 70785 -443931516
38220 44235 -187234181
44235 63035 -237171010
30847 50624 118354734
92375 24980 -382011924
56418 50624 -658160541
50624 10991 -966...

output:

1793776773
23
31140 44630 73442 3092 58361 62402 66274 56013 57891 97526 53000 30214 85483 52773 86737 91872 63179 72954 40199 70428 9524 46153 84999 

result:

ok ok

Test #10:

score: 0
Accepted
time: 22ms
memory: 14420kb

input:

99995 99997
93178 82375 -969044986
93178 19072 -204354005
35344 93178 172625135
93178 56390 -284098052
88798 19072 842699965
82375 24707 508376359
19072 71420 2142150
40446 93178 -437060610
40446 51377 -236216782
51377 89470 -349454494
19614 71420 -747727667
89470 14659 91615005
35344 49064 -7684125...

output:

1928930936
17
13782 6259 19871 82375 93178 40446 51377 3209 48876 53143 61912 65439 55069 80688 84372 3529 41657 

result:

ok ok

Test #11:

score: 0
Accepted
time: 19ms
memory: 17520kb

input:

99984 99992
13417 15144 707033172
79217 13417 -472387862
26033 13417 -36135406
13417 16174 -89686765
16174 96840 613288820
13417 11444 -398371819
11444 41716 627519572
41716 5951 233568303
96840 41978 -755500822
55150 41716 715325856
41978 88656 816236450
15144 5839 644375332
88656 95763 878003222
6...

output:

1958415767
40
11993 93511 80696 35258 84539 78871 41533 72086 64840 71601 61488 1019 19346 20549 6162 15155 65480 95763 95939 39284 33954 92172 82891 26100 81816 24802 65474 44860 12538 28616 36613 4719 62781 15965 90176 17104 96840 16174 13417 26033 

result:

ok ok

Test #12:

score: 0
Accepted
time: 58ms
memory: 19280kb

input:

80000 98516
26903 1777 -924244496
60501 50043 -169932745
73857 9688 924119596
51789 37304 -395289958
66012 19584 677645038
36094 31329 -438857807
23716 36356 333796707
64800 10550 -272867916
24677 61533 -276717055
37159 23410 564922612
57429 13265 -535543043
53527 15651 304660186
13261 58532 2102669...

output:

1999981013
59626
79643 37280 5554 78997 11316 25051 25291 62056 58809 6365 3574 65862 23850 57161 50170 42566 44274 11751 21406 42594 52409 73528 47295 21188 44843 78428 50116 40264 51819 60784 61422 29265 15997 9392 77878 28858 11500 14291 60267 77942 76466 11706 5075 62632 7158 48045 17116 65210 2...

result:

ok ok

Test #13:

score: 0
Accepted
time: 35ms
memory: 17080kb

input:

80000 94684
787 61972 -860542411
20083 27809 428832046
4166 26381 209001312
20451 29135 61290072
27638 15329 -490707445
59773 62375 228047113
41999 67706 -799550202
19069 6355 948713742
55898 70936 -879012749
13950 62531 -590275719
50627 17883 622866713
69768 13748 953427970
48538 24420 123552876
18...

output:

1999848367
19139
62625 3089 26776 28230 37002 9379 75740 44182 26012 44857 24205 59521 60388 44934 8906 61725 53397 67718 11637 45354 4057 7264 58884 69497 31336 14596 17434 59719 18426 40360 24153 72600 33742 1985 3288 12168 76551 62303 75365 11465 75065 60859 5141 48718 79005 5881 1398 56836 68611...

result:

ok ok

Test #14:

score: 0
Accepted
time: 34ms
memory: 18372kb

input:

85000 100000
12684 20697 -831379236
10219 41211 -539041569
17720 69181 -525999432
58189 3530 -215648248
29815 3583 -430621047
9529 62763 -641420982
54333 16217 517578175
3636 39822 -659701191
77761 44172 489371539
55825 60143 523113008
70503 23773 907033043
33924 58465 321062719
14586 28291 -3111270...

output:

1999860030
29750
36590 59271 65843 80176 58775 29607 55342 59787 54180 80260 68164 72983 805 70355 5078 1265 2330 45094 5068 58996 45647 9623 48292 54471 79963 27451 61649 61822 79375 14930 28767 25031 76432 60853 24794 67258 52814 70575 81701 40656 33789 76090 48871 29803 77993 19320 14357 44101 18...

result:

ok ok

Test #15:

score: 0
Accepted
time: 36ms
memory: 20724kb

input:

90000 98235
4034 56551 535462424
1285 78054 -432396039
13482 78432 326444126
36922 32666 -423303402
46270 14278 327106206
73367 11943 -120750644
57985 1074 521321207
51396 70877 604419844
80121 19287 -807213060
83316 29903 437891049
11641 29638 -109912627
54265 78774 -197898831
30288 41596 5540178
6...

output:

1999860693
31500
60067 7300 26771 14931 51692 83822 52198 50738 68125 6777 45812 3844 12974 15794 16455 81629 59778 10574 67097 75430 39564 23625 56491 30501 62398 58507 19129 25462 47205 31301 78365 1757 87085 73714 70677 63563 21533 75255 49244 67633 24457 7401 83887 18956 45692 68183 75261 10441 ...

result:

ok ok

Test #16:

score: -100
Wrong Answer
time: 0ms
memory: 8044kb

input:

3 3
1 2 233
2 3 233
3 1 233

output:

0
0

result:

wrong answer Integer 0 violates the range [1, 3]