QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#184466 | #5036. 卑鄙的下毒人 | yyyyxh | 30 | 887ms | 139904kb | C++14 | 2.1kb | 2023-09-20 19:43:22 | 2023-09-20 19:43:23 |
Judging History
answer
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cassert>
using namespace std;
int read(){
char c=getchar();int x=0;
while(c<48||c>57) c=getchar();
do x=(x<<1)+(x<<3)+(c^48),c=getchar();
while(c>=48&&c<=57);
return x;
}
int n,m,s,t,k;
struct Info{
int dis,x;
Info(int D,int X):dis(D),x(X){}
friend bool operator<(const Info a,const Info b){
return a.dis>b.dis;
}
};
priority_queue<Info> que;
typedef __int128 ll;
const int N=500013,M=2000013;
const long long lINF=0x3f3f3f3f3f3f3f3f;
const ll INF=(ll)lINF*lINF;
int hd[N],ver[M],nxt[M],tot=1;
ll cap[M],val[M];
void add(int u,int v,int w,int c){
nxt[++tot]=hd[u];hd[u]=tot;ver[tot]=v;cap[tot]=w;val[tot]=c;
nxt[++tot]=hd[v];hd[v]=tot;ver[tot]=u;cap[tot]=0;val[tot]=-c;
}
ll dis[N],h[N];
int cur[N];
bool dij(){
for(int i=1;i<=n;++i){
cur[i]=hd[i];
if(dis[i]!=INF){
h[i]+=dis[i];
dis[i]=INF;
}
}
que.emplace(dis[s]=0,s);
while(!que.empty()){
auto [ds,u]=que.top();que.pop();
if(ds>dis[u]) continue;
for(int i=hd[u];i;i=nxt[i]){
if(!cap[i]) continue;
int v=ver[i];
ll w=val[i]+h[u]-h[v];
assert(w>=0);
if(dis[v]>ds+w) que.emplace(dis[v]=ds+w,v);
}
}
return dis[t]!=INF;
}
ll res,cost;
bool vis[N];
ll dinic(int u,ll fl){
if(!fl||u==t) return fl;
vis[u]=1;
ll sum=0;
for(int i=cur[u];i&&fl;i=nxt[i]){
cur[u]=i;
int v=ver[i];
if(vis[v]||dis[v]!=dis[u]+val[i]+h[u]-h[v]) continue;
ll cfl=dinic(v,min(fl,cap[i]));
sum+=cfl;cap[i]-=cfl;cap[i^1]+=cfl;
fl-=cfl;cost+=cfl*val[i];
}
vis[u]=0;
return sum;
}
void slack(int u){
for(int i=hd[u];i;i=nxt[i])
if(cap[i]){
int v=ver[i];
h[v]=min(h[v],h[u]+val[i]);
}
}
int main(){
n=read();m=read();k=read();
for(int i=1;i<=m;++i){
int u=read(),v=read();
add(u,v+1,1,-read());
}
add(s=n+2,1,k,0);
for(int i=1;i<=n;++i) add(i,i+1,k,0);
h[s]=0;
for(int i=1;i<=n+1;++i) h[i]=INF;
slack(s);
for(int i=1;i<=n+1;++i) slack(i);
t=n+1;n+=2;
while(dij()) res+=dinic(s,INF);
printf("%lld\n",(long long)-cost);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 2ms
memory: 14140kb
input:
7 20 5 3 4 1 1 1 1 2 7 1 3 7 1 2 2 1 3 7 1 4 6 1 7 7 1 5 5 1 1 6 1 3 4 1 1 4 1 3 6 1 3 3 1 2 5 1 1 1 1 5 5 1 1 1 1 6 7 1 2 2 1
output:
15
result:
ok "15"
Test #2:
score: 0
Accepted
time: 0ms
memory: 16104kb
input:
12 20 5 5 5 1 8 12 1 4 10 1 10 12 1 2 11 1 3 6 1 6 12 1 1 10 1 4 9 1 7 10 1 4 12 1 2 10 1 1 12 1 4 5 1 4 9 1 7 9 1 3 9 1 10 11 1 6 12 1 4 10 1
output:
10
result:
ok "10"
Test #3:
score: 0
Accepted
time: 2ms
memory: 14004kb
input:
7 20 5 2 7 1 6 6 1 3 6 1 3 3 1 2 5 1 6 6 1 2 6 1 2 7 1 4 6 1 3 3 1 2 2 1 5 5 1 1 4 1 1 5 1 2 5 1 4 4 1 2 7 1 3 4 1 2 4 1 1 2 1
output:
12
result:
ok "12"
Test #4:
score: 0
Accepted
time: 2ms
memory: 16052kb
input:
11 20 5 1 8 1 1 10 1 10 11 1 7 11 1 3 10 1 3 8 1 1 8 1 4 5 1 4 5 1 1 7 1 3 4 1 3 7 1 5 6 1 2 6 1 4 9 1 4 10 1 4 4 1 1 11 1 7 10 1 4 8 1
output:
9
result:
ok "9"
Test #5:
score: 0
Accepted
time: 0ms
memory: 16184kb
input:
8 20 5 6 7 1 4 5 1 1 7 1 3 7 1 1 6 1 3 8 1 1 1 1 2 2 1 1 7 1 3 4 1 6 6 1 1 7 1 1 1 1 1 3 1 4 4 1 8 8 1 3 4 1 1 6 1 6 6 1 2 8 1
output:
13
result:
ok "13"
Test #6:
score: 0
Accepted
time: 0ms
memory: 14040kb
input:
20 20 1 3 14 1 1 17 1 3 18 1 14 20 1 15 17 1 9 17 1 10 12 1 6 20 1 11 16 1 3 17 1 1 2 1 6 19 1 17 18 1 4 18 1 4 9 1 3 7 1 4 13 1 17 19 1 7 12 1 10 14 1
output:
4
result:
ok "4"
Test #7:
score: 0
Accepted
time: 1ms
memory: 14044kb
input:
20 20 2 10 20 1 8 9 1 1 8 1 12 17 1 3 20 1 7 18 1 6 10 1 3 5 1 5 9 1 3 6 1 1 3 1 2 6 1 9 11 1 2 11 1 3 15 1 1 7 1 5 7 1 6 11 1 15 18 1 8 10 1
output:
7
result:
ok "7"
Test #8:
score: 0
Accepted
time: 1ms
memory: 13984kb
input:
20 20 3 3 16 1 6 17 1 8 17 1 11 19 1 5 7 1 3 13 1 16 19 1 6 8 1 3 14 1 7 10 1 6 13 1 1 5 1 4 20 1 16 16 1 8 17 1 7 19 1 12 16 1 5 14 1 10 18 1 10 16 1
output:
7
result:
ok "7"
Test #9:
score: 0
Accepted
time: 1ms
memory: 13984kb
input:
20 20 4 8 19 1 15 19 1 10 20 1 5 11 1 1 2 1 12 15 1 5 7 1 10 14 1 3 6 1 13 19 1 5 10 1 6 7 1 7 7 1 1 19 1 9 16 1 3 16 1 1 2 1 4 20 1 15 16 1 7 11 1
output:
12
result:
ok "12"
Test #10:
score: 0
Accepted
time: 1ms
memory: 13984kb
input:
20 20 5 10 18 1 5 9 1 1 17 1 12 19 1 12 13 1 11 17 1 7 10 1 2 10 1 8 13 1 4 6 1 12 13 1 13 13 1 14 20 1 1 9 1 19 19 1 5 8 1 16 16 1 1 6 1 5 16 1 2 4 1
output:
15
result:
ok "15"
Subtask #2:
score: 0
Time Limit Exceeded
Test #11:
score: 0
Time Limit Exceeded
input:
1794 5000 5 419 430 46802829 1071 1140 167141363 1154 1554 366136993 735 1265 152210166 387 1104 646459531 1073 1637 525871859 1340 1729 44303243 1221 1574 588158235 91 478 922877048 1117 1268 460323230 315 1103 378106915 272 1071 784282054 1147 1469 220209516 281 375 514585737 677 1031 231082599 55...
output:
result:
Subtask #3:
score: 0
Time Limit Exceeded
Test #31:
score: 0
Time Limit Exceeded
input:
322675 500000 1 162058 177924 125740423 72321 188693 51206015 73706 159883 238256306 223634 241332 292316893 8164 94217 879196279 232892 319246 624760769 67688 195525 319652781 70831 92026 394982900 68675 156743 598333126 107804 308096 843245966 57077 248406 291662171 12794 193657 560389007 105560 2...
output:
result:
Subtask #4:
score: 20
Accepted
Test #51:
score: 20
Accepted
time: 719ms
memory: 88692kb
input:
194181 500000 5 22921 38709 1 103611 130117 1 33044 135246 1 25161 106036 1 13484 183424 1 129622 133239 1 103905 105727 1 8418 141108 1 5951 145648 1 61392 105830 1 139975 149309 1 47361 59947 1 91598 172246 1 32303 43094 1 72490 170121 1 68502 168603 1 56051 91019 1 106112 129606 1 70776 177996 1 ...
output:
2485
result:
ok "2485"
Test #52:
score: 0
Accepted
time: 887ms
memory: 110736kb
input:
304003 500000 5 101915 187818 1 96905 285932 1 39472 217335 1 223783 231789 1 201166 211239 1 22769 134905 1 19436 89499 1 78054 117024 1 6577 94503 1 16701 62281 1 59789 95662 1 68941 96708 1 17347 224646 1 1970 50789 1 197428 215792 1 79626 243334 1 70524 218601 1 17518 113996 1 199398 247243 1 63...
output:
2493
result:
ok "2493"
Test #53:
score: 0
Accepted
time: 685ms
memory: 102140kb
input:
249974 496542 5 87672 88771 1 52366 53940 1 25887 25963 1 184719 186260 1 104443 104706 1 95989 96053 1 134358 135382 1 55635 55647 1 134371 134382 1 148206 149011 1 95965 96135 1 140844 140891 1 78797 78798 1 15619 15943 1 31258 31343 1 47248 47358 1 157920 157998 1 135597 135708 1 98966 99089 1 20...
output:
78661
result:
ok "78661"
Test #54:
score: 0
Accepted
time: 658ms
memory: 101944kb
input:
249974 494350 5 161514 163184 1 87911 87959 1 105204 106421 1 178980 181538 1 19665 19715 1 58148 58167 1 67664 67964 1 5582 6048 1 242900 242913 1 218881 218915 1 84444 84678 1 99763 100602 1 208276 208335 1 35121 35190 1 115890 115966 1 122960 123877 1 22163 22657 1 100321 100645 1 99196 99575 1 1...
output:
97350
result:
ok "97350"
Test #55:
score: 0
Accepted
time: 661ms
memory: 102780kb
input:
249983 486062 5 178515 178556 1 46509 46657 1 623 630 1 223892 223897 1 227434 227448 1 127239 127242 1 175036 175061 1 144855 144868 1 107886 107891 1 118310 118312 1 165907 165919 1 174395 174413 1 196413 196457 1 137455 139090 1 59658 59673 1 196868 196878 1 53952 54025 1 49268 49480 1 38355 3885...
output:
144650
result:
ok "144650"
Test #56:
score: 0
Accepted
time: 674ms
memory: 104016kb
input:
249983 495448 5 123223 124925 1 161437 161839 1 204523 204907 1 123417 124631 1 169136 169205 1 109580 109591 1 202411 202609 1 237547 237552 1 43171 43533 1 19726 20052 1 191894 192321 1 140366 140369 1 24388 24490 1 1393 1417 1 155640 155653 1 204676 205389 1 232668 235247 1 45859 47006 1 77633 77...
output:
87916
result:
ok "87916"
Test #57:
score: 0
Accepted
time: 652ms
memory: 103744kb
input:
249992 494620 5 84373 84412 1 125864 125902 1 203420 203427 1 64431 64437 1 56552 56567 1 71532 71611 1 71190 71248 1 107213 108211 1 115775 116553 1 181151 181244 1 37673 37714 1 44770 44800 1 227519 227561 1 245293 245343 1 11949 12034 1 51161 51192 1 242357 242401 1 142142 142144 1 203117 203611 ...
output:
94967
result:
ok "94967"
Test #58:
score: 0
Accepted
time: 718ms
memory: 95572kb
input:
208426 500000 5 28645 101916 1 7440 127239 1 137321 138796 1 155729 158144 1 167838 203986 1 127568 151506 1 49515 81900 1 37962 167268 1 141888 144316 1 48742 192792 1 8191 124087 1 113172 141152 1 92571 105888 1 23469 75518 1 25800 127940 1 94900 157340 1 11438 114334 1 1826 37080 1 5738 122480 1 ...
output:
2398
result:
ok "2398"
Test #59:
score: 0
Accepted
time: 811ms
memory: 106152kb
input:
270310 500000 5 151314 259090 1 80695 183506 1 20699 196732 1 142374 248474 1 77831 129977 1 31693 170486 1 42481 50638 1 237296 244555 1 117532 206885 1 154573 230747 1 17424 38046 1 95181 228843 1 123250 217068 1 194563 252222 1 93291 206436 1 4217 7976 1 89143 239119 1 222217 248624 1 9680 246195...
output:
2422
result:
ok "2422"
Test #60:
score: 0
Accepted
time: 792ms
memory: 102724kb
input:
255424 500000 5 59606 133843 1 186905 209051 1 67305 243269 1 27933 65974 1 78338 171108 1 3704 177437 1 62314 217400 1 65683 216660 1 10999 51811 1 203698 245062 1 200238 227732 1 95702 203308 1 108957 224327 1 7616 111101 1 188051 237741 1 54576 209144 1 98897 230281 1 154770 233686 1 106761 20723...
output:
2448
result:
ok "2448"
Test #61:
score: 0
Accepted
time: 251ms
memory: 139048kb
input:
500000 500000 1 435056 435101 1 96682 96726 1 366447 366479 1 409321 409329 1 319459 319478 1 386826 386851 1 477209 477243 1 405392 405424 1 366564 366584 1 313831 313852 1 126671 126705 1 402868 402877 1 126969 127001 1 433546 433559 1 103408 103446 1 203 220 1 499640 499669 1 86463 86509 1 222795...
output:
56551
result:
ok "56551"
Test #62:
score: 0
Accepted
time: 378ms
memory: 139904kb
input:
500000 500000 2 398851 398882 1 269476 269518 1 239296 239337 1 16069 16079 1 442104 442126 1 209852 209891 1 327424 327439 1 297952 297955 1 21272 21303 1 220730 220772 1 79140 79174 1 405354 405360 1 313185 313228 1 171020 171069 1 316725 316764 1 325712 325733 1 477774 477781 1 204985 205014 1 16...
output:
94306
result:
ok "94306"
Test #63:
score: 0
Accepted
time: 513ms
memory: 139392kb
input:
500000 500000 3 81122 81131 1 307742 307754 1 421008 421037 1 126583 126613 1 349371 349376 1 108214 108231 1 234333 234335 1 51679 51691 1 176180 176215 1 457610 457643 1 429415 429416 1 143493 143498 1 455898 455937 1 225199 225227 1 38247 38264 1 115825 115851 1 433824 433827 1 2395 2399 1 156156...
output:
124594
result:
ok "124594"
Test #64:
score: 0
Accepted
time: 644ms
memory: 138948kb
input:
500000 500000 4 50207 50249 1 466545 466586 1 409439 409451 1 3041 3073 1 261821 261845 1 303963 303989 1 74383 74417 1 256880 256917 1 393046 393056 1 56497 56534 1 255489 255533 1 283323 283329 1 151024 151051 1 110312 110338 1 229377 229384 1 252166 252196 1 387865 387886 1 398932 398966 1 287693...
output:
150753
result:
ok "150753"
Test #65:
score: 0
Accepted
time: 767ms
memory: 139052kb
input:
500000 500000 5 498982 499017 1 489602 489619 1 184352 184383 1 272166 272181 1 165728 165760 1 195337 195354 1 119007 119010 1 195484 195507 1 151529 151550 1 263467 263503 1 102050 102056 1 295825 295850 1 337212 337242 1 217581 217620 1 74890 74894 1 286633 286645 1 149257 149275 1 369127 369159 ...
output:
174194
result:
ok "174194"
Subtask #5:
score: 0
Time Limit Exceeded
Test #66:
score: 0
Time Limit Exceeded
input:
265199 500000 5 51732 151507 196279569 1147 251097 325871693 79410 120618 539045634 209514 221950 912376813 44813 147573 616444800 53619 134328 533306546 94940 108466 186490362 42483 236958 489649490 127349 167018 943263893 103970 193784 202963780 197001 221033 210521750 5815 113674 152090319 129972...