QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#792281 | #143. 最大流(随机数据) | cppcppcpp3 | 100 ✓ | 7ms | 4140kb | C++14 | 1.6kb | 2024-11-29 08:47:15 | 2024-11-29 08:47:21 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=105;
const int M=1e4+5;
const int inf=1e18;
static char buf[1000000],*p1=buf,*p2=buf;
#define getchar() p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++
inline int wrd(){int x=0,f=1;char c=getchar();while(c<'0' || c>'9'){if(c=='-') f=-1;c=getchar();}while(c>='0' && c<='9') {x=(x<<3)+(x<<1)+c-48;c=getchar();}return x*f;}
inline void write(int x){static char buf[20];static int len=-1;if(x<0)putchar('-'),x=-x;do buf[++len]=x%10,x/=10;while(x);while(len>=0)putchar(buf[len--]+48);}
int n,m,s,t,as,cnt=1,head[N];
struct edge{int to,w,nxt;}e[M];
void add(int u,int v,int w){e[++cnt]={v,w,head[u]},head[u]=cnt;}
void addedge(int u,int v,int w){add(u,v,w),add(v,u,0);}
bool vs[N];
int dep[N],cur[N];
bool bfs(){
queue<int> q;
for(int i=1;i<=n;++i) vs[i]=0,dep[i]=inf;
q.push(s),dep[s]=0,cur[s]=head[s];
while(q.size()){
int u=q.front(); q.pop();
for(int i=head[u];i;i=e[i].nxt){
int v=e[i].to;
if(dep[v]!=inf || !e[i].w) continue;
dep[v]=dep[u]+1,cur[v]=head[v],q.push(v);
}
}
return dep[t]!=inf;
}
int dfs(int u,int flow){
if(u==t) return flow;
int as(0);
for(int i=cur[u];i&&flow;i=e[i].nxt){
cur[u]=i;
int v=e[i].to;
if(dep[v]!=dep[u]+1 || !e[i].w) continue;
int x=dfs(v,min(flow,e[i].w));
if(!x) dep[v]=inf;
else as+=x,flow-=x,e[i].w-=x,e[i^1].w+=x;
}
return as;
}
signed main(){
n=wrd(),m=wrd(),s=wrd(),t=wrd();
for(int i=1;i<=m;++i){
int u=wrd(),v=wrd(),w=wrd();
addedge(u,v,w);
}
while(bfs()) as+=dfs(s,inf);
write(as);
}
详细
Pretests
Final Tests
Test #1:
score: 12.5
Accepted
time: 1ms
memory: 3600kb
input:
52 275 1 2 11 18 1 18 48 9 10 15 1 11 19 1 10 20 1 3 14 1 8 16 1 31 32 2147483647 10 42 9 5 14 1 3 15 1 5 17 1 6 50 9 1 6 9 28 29 2147483647 18 40 9 43 42 2147483647 1 9 9 9 20 1 1 7 9 24 6 9 39 38 2147483647 4 14 1 38 37 2147483647 5 46 9 3 18 1 15 44 9 4 17 1 32 33 2147483647 28 9 9 32 9 9 26 12 9...
output:
729
result:
ok single line: '729'
Test #2:
score: 12.5
Accepted
time: 0ms
memory: 3768kb
input:
67 4489 14 1 25 63 19983 49 18 26963 9 29 23009 25 30 10286 45 6 14693 61 11 8464 12 19 29821 39 36 2365 12 7 20737 56 51 21002 9 63 14701 15 10 24386 21 36 25930 49 21 10680 56 11 25508 26 27 2101 46 4 1770 16 56 19722 23 8 28411 67 32 28897 45 62 22880 30 38 13226 37 56 18650 10 57 700 62 53 19659...
output:
1025243
result:
ok single line: '1025243'
Test #3:
score: 12.5
Accepted
time: 1ms
memory: 3644kb
input:
100 1029 1 2 39 96 19 68 19 19 16 33 1 17 25 1 74 22 19 50 23 19 46 29 19 70 24 19 27 92 19 50 25 19 6 36 1 34 80 19 72 19 19 48 13 19 11 86 19 19 86 19 100 99 2147483647 4 39 1 60 9 19 76 7 19 34 100 19 98 97 2147483647 15 25 1 14 94 19 5 40 1 4 38 1 46 34 19 90 89 2147483647 42 39 19 58 27 19 3 39...
output:
4693
result:
ok single line: '4693'
Test #4:
score: 12.5
Accepted
time: 0ms
memory: 3580kb
input:
100 500 64 68 97 1 597234350 42 59 1020828575 52 59 1341185789 46 82 534859215 84 98 1408384018 95 85 97421544 50 51 1658946459 71 91 1071433566 16 5 577259372 79 16 941940144 32 66 2144021311 42 94 132280559 100 83 2093384600 34 98 1633024304 31 69 735801701 68 13 632197336 70 25 868338831 60 91 14...
output:
4259958644
result:
ok single line: '4259958644'
Test #5:
score: 12.5
Accepted
time: 1ms
memory: 3672kb
input:
100 1500 30 87 12 52 1212854316 66 34 500229329 28 30 1905848380 45 10 1906211267 35 5 1227091997 14 10 797678626 42 39 2119948760 80 55 263028757 72 32 1402091192 2 70 114204531 53 87 1885940117 39 68 1262963681 20 100 363298998 81 19 475298425 86 17 276841422 95 43 940479356 85 55 1720319570 40 65...
output:
17139501202
result:
ok single line: '17139501202'
Test #6:
score: 12.5
Accepted
time: 0ms
memory: 3912kb
input:
100 5000 12 73 5 90 596775756 35 20 226786760 28 31 1775982092 79 17 743002845 10 19 150120683 83 96 901953035 91 62 809520329 2 61 1024423315 30 91 1374494188 93 26 751944004 82 82 727762428 1 43 502389284 84 87 1379778919 52 32 1459460146 71 15 983677176 18 3 249963037 80 32 828290820 40 99 159181...
output:
37381805875
result:
ok single line: '37381805875'
Test #7:
score: 12.5
Accepted
time: 7ms
memory: 3908kb
input:
100 5000 13 28 74 16 599476 99 76 112185 76 68 887056 13 2 181381 23 72 214611 10 15 955272 57 53 163306 81 44 721618 68 62 71172 70 44 233121 13 52 701794 77 40 298244 54 28 626039 26 63 829000 25 14 91588 97 62 980457 17 15 572847 100 75 273645 4 65 344467 17 47 299474 40 19 270752 50 68 804106 21...
output:
2193636882
result:
ok single line: '2193636882'
Test #8:
score: 12.5
Accepted
time: 6ms
memory: 4140kb
input:
100 5000 66 90 35 39 966842 3 56 577708 38 60 515530 3 73 351251 29 27 508007 56 70 185615 73 51 331650 6 32 589603 29 96 822851 9 99 335209 20 45 806531 60 10 460779 93 21 203582 77 27 391590 3 14 315530 86 41 234991 53 69 96865 97 15 203159 14 43 815111 4 24 337097 88 79 288209 64 34 806690 13 26 ...
output:
4340954172
result:
ok single line: '4340954172'