QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#184442 | #5036. 卑鄙的下毒人 | yyyyxh | 10 | 2ms | 16164kb | C++14 | 1.8kb | 2023-09-20 19:20:02 | 2023-09-20 19:20:04 |
Judging History
answer
#include <cstdio>
#include <algorithm>
#include <queue>
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 long long ll;
const int N=600003,M=2000003;
const ll INF=0x3f3f3f3f3f3f3f3f;
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];
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;
}
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());
}
for(int i=1;i<=n;++i) add(i,i+1,k,0);
add(s=n+2,1,k,0);t=n+1;
n+=2;
while(dij()) res+=dinic(s,INF);
printf("%lld\n",-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: 0ms
memory: 14092kb
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: 2ms
memory: 14128kb
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: 0ms
memory: 14232kb
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: 0ms
memory: 14044kb
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: 16156kb
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: 16164kb
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: 2ms
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: 0ms
memory: 14160kb
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: 2ms
memory: 14160kb
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: 2ms
memory: 14104kb
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: 0
Time Limit Exceeded
Test #51:
score: 0
Time Limit Exceeded
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:
result:
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...