QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#276735 | #4180. 晨跑 | SoyTony | 100 ✓ | 164ms | 4564kb | C++14 | 2.5kb | 2023-12-06 10:12:34 | 2023-12-06 10:12:35 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=405;
const int maxm=4e4+10;
const ll maxxn=0x3f3f3f3f3f3f3f3f;
inline int read(){
int x=0,w=1;char c=getchar();
while(c<'0'||c>'9'){if(c=='-')w=-1;c=getchar();}
while(c<='9'&&c>='0'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}
return x*w;
}
int n,m,S,T,tot;
int id[205][2];
struct Graph{
struct edge{
int to,nxt;
ll lim,c;
}e[maxm<<1];
int head[maxn],cnt=1;
inline void add_edge(int u,int v,ll w,ll c){
e[++cnt].to=v,e[cnt].nxt=head[u],e[cnt].lim=w,e[cnt].c=c,head[u]=cnt;
e[++cnt].to=u,e[cnt].nxt=head[v],e[cnt].lim=0,e[cnt].c=-c,head[v]=cnt;
}
int pre[maxn];
ll dis[maxn];
bool vis[maxn];
inline void SPFA(){
queue<int> q;
memset(dis,0x3f,sizeof(dis));
memset(vis,0,sizeof(vis));
dis[S]=0,vis[S]=1;
q.push(S);
while(!q.empty()){
int u=q.front();
vis[u]=0;
q.pop();
for(int i=head[u];i;i=e[i].nxt){
int v=e[i].to;
ll c=e[i].c;
if(dis[u]+c<dis[v]&&e[i].lim){
dis[v]=dis[u]+c;
pre[v]=i;
if(vis[v]) continue;
vis[v]=1;
q.push(v);
}
}
}
}
inline pair<ll,ll> max_flow(){
ll flow=0,min_cost=0;
while(1){
SPFA();
if(dis[T]==maxxn) return make_pair(flow,min_cost);
ll mn=maxxn;
for(int u=T;u!=S;u=e[pre[u]^1].to){
mn=min(mn,e[pre[u]].lim);
}
flow+=mn;
for(int u=T;u!=S;u=e[pre[u]^1].to){
min_cost+=e[pre[u]].c*mn;
e[pre[u]].lim-=mn,e[pre[u]^1].lim+=mn;
}
}
}
}G;
int main(){
n=read(),m=read();
S=1,T=2,tot=2;
for(int i=1;i<=n;++i){
if(i==1) id[i][0]=id[i][1]=S;
else if(i==n) id[i][0]=id[i][1]=T;
else{
id[i][0]=++tot,id[i][1]=++tot;
G.add_edge(id[i][0],id[i][1],1,0);
}
}
for(int i=1;i<=m;++i){
int u=read(),v=read(),c=read();
if(u==1&&v==n) G.add_edge(S,T,1,c);
else G.add_edge(id[u][1],id[v][0],1e9,c);
}
pair<ll,ll> ans=G.max_flow();
printf("%lld %lld\n",ans.first,ans.second);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 10
Accepted
time: 1ms
memory: 3744kb
input:
5 8 1 2 5 1 3 6 1 4 3 2 3 3 2 4 7 2 5 1 3 5 3 4 5 9
output:
3 27
result:
ok single line: '3 27'
Test #2:
score: 10
Accepted
time: 0ms
memory: 3700kb
input:
10 30 9 6 89 5 9 11 5 6 45 1 5 38 8 3 3 1 10 3 4 7 7 9 8 96 8 5 69 6 2 99 8 7 18 5 10 28 1 7 47 9 10 79 1 3 64 9 7 21 7 4 6 3 10 2 1 6 89 3 7 27 1 4 39 1 8 74 4 10 30 7 6 71 1 9 68 7 2 41 8 9 40 9 4 63 2 10 16 3 2 23
output:
6 455
result:
ok single line: '6 455'
Test #3:
score: 10
Accepted
time: 0ms
memory: 3744kb
input:
20 120 10 12 273 7 11 39 11 3 380 9 17 197 11 12 163 2 18 460 3 6 127 9 4 241 14 20 49 9 2 83 9 16 347 19 20 136 17 9 112 3 20 429 5 14 306 12 13 276 19 12 477 5 6 210 19 8 374 18 10 148 15 18 360 4 18 22 18 20 214 17 20 36 5 8 425 12 9 48 12 17 449 2 6 413 15 14 189 8 14 413 4 11 74 8 7 465 2 19 13...
output:
11 4036
result:
ok single line: '11 4036'
Test #4:
score: 10
Accepted
time: 1ms
memory: 3724kb
input:
50 1000 12 15 443 22 14 491 24 22 616 9 36 1 32 35 736 20 44 201 25 7 773 49 45 783 10 5 342 15 23 826 17 15 733 28 2 34 40 11 353 1 40 906 25 42 758 47 38 449 36 33 816 24 46 859 3 37 934 18 33 357 46 33 81 17 6 487 28 50 860 1 49 851 42 15 916 2 33 728 22 33 31 42 45 663 1 38 644 44 50 495 36 17 7...
output:
38 43948
result:
ok single line: '38 43948'
Test #5:
score: 10
Accepted
time: 23ms
memory: 4060kb
input:
100 8000 28 100 686 3 32 726 2 23 64 58 76 848 39 37 207 1 52 711 77 33 574 13 86 282 77 47 309 26 28 601 1 16 115 29 89 406 1 67 818 1 35 266 56 74 261 75 79 474 76 5 335 72 39 282 20 69 51 5 50 942 47 80 709 24 83 188 34 5 578 8 52 801 39 58 648 10 39 239 27 73 195 34 81 354 85 58 931 1 92 449 30 ...
output:
96 95262
result:
ok single line: '96 95262'
Test #6:
score: 10
Accepted
time: 3ms
memory: 3828kb
input:
100 3000 37 100 102 75 76 587 59 46 145 72 59 934 56 44 606 2 48 53 70 11 965 50 17 725 94 20 109 88 16 247 48 66 437 44 42 994 1 75 578 91 22 4 27 36 674 86 89 942 1 30 690 52 81 168 12 59 996 26 62 340 24 15 119 1 77 245 1 96 912 39 3 888 1 97 273 67 63 325 64 23 43 65 70 764 1 73 978 89 65 267 94...
output:
67 67478
result:
ok single line: '67 67478'
Test #7:
score: 10
Accepted
time: 28ms
memory: 4008kb
input:
100 8000 59 40 704 4 24 58 90 76 695 97 4 646 4 69 764 68 98 955 39 80 840 48 46 748 80 35 164 1 32 344 85 5 609 67 78 39 12 19 115 34 13 15 1 29 619 16 31 656 44 95 462 1 96 584 56 5 838 85 99 614 15 48 537 46 72 126 86 25 457 18 15 595 13 42 948 76 26 515 70 71 85 69 4 294 96 18 556 19 7 131 23 36...
output:
95 98141
result:
ok single line: '95 98141'
Test #8:
score: 10
Accepted
time: 57ms
memory: 4096kb
input:
200 10000 75 64 184 71 41 753 182 139 304 172 13 646 93 108 513 120 117 834 199 124 894 30 108 956 122 65 162 108 30 362 180 166 99 1 46 244 42 180 156 1 148 297 69 19 226 185 39 177 162 170 598 77 83 971 165 88 808 103 157 27 1 149 313 3 100 991 43 161 725 49 51 320 61 85 4 42 122 836 64 44 342 182...
output:
122 129072
result:
ok single line: '122 129072'
Test #9:
score: 10
Accepted
time: 71ms
memory: 4192kb
input:
200 12000 58 157 686 132 170 322 33 56 421 77 156 610 1 120 744 186 49 360 84 155 429 12 92 757 93 161 579 144 175 198 183 17 405 178 195 835 104 78 335 1 121 577 39 50 475 82 8 921 1 50 496 1 179 144 1 95 673 53 140 408 147 200 78 69 165 195 1 145 957 34 181 581 93 40 418 74 42 315 12 153 701 32 92...
output:
129 125997
result:
ok single line: '129 125997'
Test #10:
score: 10
Accepted
time: 164ms
memory: 4564kb
input:
200 20000 41 72 25 1 19 1758 150 33 1697 12 140 2252 1 109 2789 26 64 1339 57 2 1853 27 154 2887 180 78 978 79 97 745 139 26 2767 119 147 2523 194 144 631 162 110 1426 1 195 1243 1 26 2268 197 128 1443 183 129 2287 50 186 2212 46 197 1464 190 69 1499 36 17 458 86 180 2613 74 56 727 83 148 925 121 12...
output:
157 451256
result:
ok single line: '157 451256'