QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#423714 | #2208. Flow | fzj2007 | AC ✓ | 555ms | 4420kb | C++14 | 2.1kb | 2024-05-28 15:29:12 | 2024-05-28 15:29:12 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
template<typename T>inline void read(T &x){
x=0;
bool flag=0;
char ch=getchar();
while(ch<'0'||ch>'9') flag=flag||(ch=='-'),ch=getchar();
while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
x=flag?-x:x;
}
template<typename T,typename ...Args>inline void read(T &x,Args &...args){
read(x),read(args...);
}
template<typename T>inline void prt(T x){
if(x>9) prt(x/10);
putchar(x%10+'0');
}
template<typename T>inline void put(T x){
if(x<0) putchar('-'),x=-x;
prt(x);
}
template<typename T>inline void put(char ch,T x){
put(x),putchar(ch);
}
template<typename T,typename ...Args>inline void put(char ch,T x,Args ...args){
put(ch,x),put(ch,args...);
}
#define N 2024
struct Flow{
int head[N],cnt,s,t;
Flow(){
memset(head,0,sizeof(head));
memset(e,0,sizeof(e));
cnt=1;
}
struct edge{
int v,nxt,flow,cost;
}e[N<<4];
inline void adde(int u,int v,int flow,int cost){
e[++cnt]=(edge){v,head[u],flow,cost},head[u]=cnt;
}
inline void add(int u,int v,int flow,int cost){
adde(u,v,flow,cost),adde(v,u,0,-cost);
}
int dis[N],vis[N],incf[N],pre[N];
inline bool spfa(){
memset(dis,0x3f,sizeof(dis));
memset(vis,0,sizeof(vis));
queue<int> q;
q.push(s),dis[s]=0,vis[s]=1,incf[s]=0x3f3f3f3f;
while(!q.empty()){
int x=q.front();q.pop(),vis[x]=0;
for(int i=head[x];i;i=e[i].nxt){
int v=e[i].v;
if(e[i].flow&&dis[v]>dis[x]+e[i].cost){
dis[v]=dis[x]+e[i].cost,incf[v]=min(incf[x],e[i].flow),pre[v]=i;
if(!vis[v]) vis[v]=1,q.push(v);
}
}
}
return dis[t]<0x3f3f3f3f;
}
inline int mcmf(){
int res=0;
while(spfa()){
res+=dis[t]*incf[t];
for(int x=t,i=pre[x];x!=s;x=e[i^1].v,i=pre[x])
e[i].flow-=incf[t],e[i^1].flow+=incf[t];
}
return res;
}
}F;
int n,m,deg[N],ans;
int main(){
read(n,m);
for(int i=1,u,v,w;i<=m;i++){
read(u,v,w),F.add(u,v,w,1),ans+=w;
deg[u]+=w,deg[v]-=w;
}
F.s=0,F.t=n+1;
for(int i=1;i<=n;i++)
if(deg[i]>0) F.add(F.s,i,deg[i],0);
else if(deg[i]<0) F.add(i,F.t,-deg[i],0);
put('\n',ans-F.mcmf());
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 224ms
memory: 4412kb
Test #2:
score: 0
Accepted
time: 109ms
memory: 4092kb
Test #3:
score: 0
Accepted
time: 203ms
memory: 4172kb
Test #4:
score: 0
Accepted
time: 226ms
memory: 4176kb
Test #5:
score: 0
Accepted
time: 302ms
memory: 4168kb
Test #6:
score: 0
Accepted
time: 293ms
memory: 4376kb
Test #7:
score: 0
Accepted
time: 409ms
memory: 4184kb
Test #8:
score: 0
Accepted
time: 152ms
memory: 4052kb
Test #9:
score: 0
Accepted
time: 210ms
memory: 4376kb
Test #10:
score: 0
Accepted
time: 252ms
memory: 4148kb
Test #11:
score: 0
Accepted
time: 4ms
memory: 4156kb
Test #12:
score: 0
Accepted
time: 286ms
memory: 4152kb
Test #13:
score: 0
Accepted
time: 414ms
memory: 4136kb
Test #14:
score: 0
Accepted
time: 518ms
memory: 4380kb
Test #15:
score: 0
Accepted
time: 67ms
memory: 4172kb
Test #16:
score: 0
Accepted
time: 130ms
memory: 4160kb
Test #17:
score: 0
Accepted
time: 182ms
memory: 4400kb
Test #18:
score: 0
Accepted
time: 72ms
memory: 4104kb
Test #19:
score: 0
Accepted
time: 491ms
memory: 4112kb
Test #20:
score: 0
Accepted
time: 7ms
memory: 4040kb
Test #21:
score: 0
Accepted
time: 247ms
memory: 4168kb
Test #22:
score: 0
Accepted
time: 152ms
memory: 4404kb
Test #23:
score: 0
Accepted
time: 304ms
memory: 4180kb
Test #24:
score: 0
Accepted
time: 256ms
memory: 4060kb
Test #25:
score: 0
Accepted
time: 511ms
memory: 4408kb
Test #26:
score: 0
Accepted
time: 212ms
memory: 4096kb
Test #27:
score: 0
Accepted
time: 82ms
memory: 4160kb
Test #28:
score: 0
Accepted
time: 97ms
memory: 4164kb
Test #29:
score: 0
Accepted
time: 394ms
memory: 4176kb
Test #30:
score: 0
Accepted
time: 459ms
memory: 4104kb
Test #31:
score: 0
Accepted
time: 157ms
memory: 4364kb
Test #32:
score: 0
Accepted
time: 462ms
memory: 4112kb
Test #33:
score: 0
Accepted
time: 259ms
memory: 4172kb
Test #34:
score: 0
Accepted
time: 450ms
memory: 4148kb
Test #35:
score: 0
Accepted
time: 179ms
memory: 4408kb
Test #36:
score: 0
Accepted
time: 422ms
memory: 4180kb
Test #37:
score: 0
Accepted
time: 463ms
memory: 4348kb
Test #38:
score: 0
Accepted
time: 377ms
memory: 4412kb
Test #39:
score: 0
Accepted
time: 238ms
memory: 4172kb
Test #40:
score: 0
Accepted
time: 338ms
memory: 4412kb
Test #41:
score: 0
Accepted
time: 89ms
memory: 4392kb
Test #42:
score: 0
Accepted
time: 113ms
memory: 4096kb
Test #43:
score: 0
Accepted
time: 218ms
memory: 4372kb
Test #44:
score: 0
Accepted
time: 356ms
memory: 4180kb
Test #45:
score: 0
Accepted
time: 422ms
memory: 4128kb
Test #46:
score: 0
Accepted
time: 366ms
memory: 4172kb
Test #47:
score: 0
Accepted
time: 191ms
memory: 4176kb
Test #48:
score: 0
Accepted
time: 368ms
memory: 4376kb
Test #49:
score: 0
Accepted
time: 227ms
memory: 4176kb
Test #50:
score: 0
Accepted
time: 324ms
memory: 4180kb
Test #51:
score: 0
Accepted
time: 119ms
memory: 4168kb
Test #52:
score: 0
Accepted
time: 61ms
memory: 4096kb
Test #53:
score: 0
Accepted
time: 38ms
memory: 4360kb
Test #54:
score: 0
Accepted
time: 495ms
memory: 4116kb
Test #55:
score: 0
Accepted
time: 28ms
memory: 4104kb
Test #56:
score: 0
Accepted
time: 269ms
memory: 4168kb
Test #57:
score: 0
Accepted
time: 128ms
memory: 4096kb
Test #58:
score: 0
Accepted
time: 429ms
memory: 4136kb
Test #59:
score: 0
Accepted
time: 421ms
memory: 4116kb
Test #60:
score: 0
Accepted
time: 409ms
memory: 4120kb
Test #61:
score: 0
Accepted
time: 485ms
memory: 4412kb
Test #62:
score: 0
Accepted
time: 142ms
memory: 4104kb
Test #63:
score: 0
Accepted
time: 210ms
memory: 4136kb
Test #64:
score: 0
Accepted
time: 67ms
memory: 4400kb
Test #65:
score: 0
Accepted
time: 266ms
memory: 4184kb
Test #66:
score: 0
Accepted
time: 433ms
memory: 4344kb
Test #67:
score: 0
Accepted
time: 76ms
memory: 4192kb
Test #68:
score: 0
Accepted
time: 342ms
memory: 4408kb
Test #69:
score: 0
Accepted
time: 220ms
memory: 4404kb
Test #70:
score: 0
Accepted
time: 156ms
memory: 4208kb
Test #71:
score: 0
Accepted
time: 10ms
memory: 4044kb
Test #72:
score: 0
Accepted
time: 115ms
memory: 4168kb
Test #73:
score: 0
Accepted
time: 157ms
memory: 4332kb
Test #74:
score: 0
Accepted
time: 230ms
memory: 4184kb
Test #75:
score: 0
Accepted
time: 120ms
memory: 4196kb
Test #76:
score: 0
Accepted
time: 183ms
memory: 4176kb
Test #77:
score: 0
Accepted
time: 233ms
memory: 4108kb
Test #78:
score: 0
Accepted
time: 512ms
memory: 4416kb
Test #79:
score: 0
Accepted
time: 453ms
memory: 4120kb
Test #80:
score: 0
Accepted
time: 266ms
memory: 4180kb
Test #81:
score: 0
Accepted
time: 170ms
memory: 4172kb
Test #82:
score: 0
Accepted
time: 450ms
memory: 4124kb
Test #83:
score: 0
Accepted
time: 348ms
memory: 4172kb
Test #84:
score: 0
Accepted
time: 263ms
memory: 4180kb
Test #85:
score: 0
Accepted
time: 489ms
memory: 4344kb
Test #86:
score: 0
Accepted
time: 334ms
memory: 4180kb
Test #87:
score: 0
Accepted
time: 16ms
memory: 4156kb
Test #88:
score: 0
Accepted
time: 163ms
memory: 4164kb
Test #89:
score: 0
Accepted
time: 107ms
memory: 4160kb
Test #90:
score: 0
Accepted
time: 468ms
memory: 4220kb
Test #91:
score: 0
Accepted
time: 172ms
memory: 4112kb
Test #92:
score: 0
Accepted
time: 23ms
memory: 4200kb
Test #93:
score: 0
Accepted
time: 201ms
memory: 4180kb
Test #94:
score: 0
Accepted
time: 349ms
memory: 4180kb
Test #95:
score: 0
Accepted
time: 157ms
memory: 4168kb
Test #96:
score: 0
Accepted
time: 62ms
memory: 4132kb
Test #97:
score: 0
Accepted
time: 207ms
memory: 4212kb
Test #98:
score: 0
Accepted
time: 462ms
memory: 4172kb
Test #99:
score: 0
Accepted
time: 34ms
memory: 4100kb
Test #100:
score: 0
Accepted
time: 498ms
memory: 4120kb
Test #101:
score: 0
Accepted
time: 480ms
memory: 4112kb
Test #102:
score: 0
Accepted
time: 521ms
memory: 4184kb
Test #103:
score: 0
Accepted
time: 99ms
memory: 4160kb
Test #104:
score: 0
Accepted
time: 555ms
memory: 4416kb
Test #105:
score: 0
Accepted
time: 208ms
memory: 4208kb
Test #106:
score: 0
Accepted
time: 315ms
memory: 4412kb
Test #107:
score: 0
Accepted
time: 115ms
memory: 4092kb
Test #108:
score: 0
Accepted
time: 225ms
memory: 4056kb
Test #109:
score: 0
Accepted
time: 128ms
memory: 4100kb
Test #110:
score: 0
Accepted
time: 233ms
memory: 4108kb
Test #111:
score: 0
Accepted
time: 146ms
memory: 4140kb
Test #112:
score: 0
Accepted
time: 164ms
memory: 4172kb
Test #113:
score: 0
Accepted
time: 268ms
memory: 4108kb
Test #114:
score: 0
Accepted
time: 318ms
memory: 4108kb
Test #115:
score: 0
Accepted
time: 282ms
memory: 4184kb
Test #116:
score: 0
Accepted
time: 58ms
memory: 4168kb
Test #117:
score: 0
Accepted
time: 195ms
memory: 4164kb
Test #118:
score: 0
Accepted
time: 143ms
memory: 4164kb
Test #119:
score: 0
Accepted
time: 283ms
memory: 4064kb
Test #120:
score: 0
Accepted
time: 247ms
memory: 4340kb
Test #121:
score: 0
Accepted
time: 452ms
memory: 4152kb
Test #122:
score: 0
Accepted
time: 353ms
memory: 4172kb
Test #123:
score: 0
Accepted
time: 212ms
memory: 4340kb
Test #124:
score: 0
Accepted
time: 470ms
memory: 4212kb
Test #125:
score: 0
Accepted
time: 512ms
memory: 4144kb
Test #126:
score: 0
Accepted
time: 194ms
memory: 4056kb
Test #127:
score: 0
Accepted
time: 9ms
memory: 4164kb
Test #128:
score: 0
Accepted
time: 416ms
memory: 4112kb
Test #129:
score: 0
Accepted
time: 299ms
memory: 4112kb
Test #130:
score: 0
Accepted
time: 40ms
memory: 4128kb
Test #131:
score: 0
Accepted
time: 207ms
memory: 4404kb
Test #132:
score: 0
Accepted
time: 88ms
memory: 4160kb
Test #133:
score: 0
Accepted
time: 471ms
memory: 4176kb
Test #134:
score: 0
Accepted
time: 492ms
memory: 4380kb
Test #135:
score: 0
Accepted
time: 377ms
memory: 4176kb
Test #136:
score: 0
Accepted
time: 241ms
memory: 4148kb
Test #137:
score: 0
Accepted
time: 190ms
memory: 4168kb
Test #138:
score: 0
Accepted
time: 191ms
memory: 4408kb
Test #139:
score: 0
Accepted
time: 185ms
memory: 4404kb
Test #140:
score: 0
Accepted
time: 379ms
memory: 4236kb
Test #141:
score: 0
Accepted
time: 480ms
memory: 4412kb
Test #142:
score: 0
Accepted
time: 351ms
memory: 4340kb
Test #143:
score: 0
Accepted
time: 415ms
memory: 4164kb
Test #144:
score: 0
Accepted
time: 427ms
memory: 4176kb
Test #145:
score: 0
Accepted
time: 176ms
memory: 4100kb
Test #146:
score: 0
Accepted
time: 184ms
memory: 4404kb
Test #147:
score: 0
Accepted
time: 289ms
memory: 4216kb
Test #148:
score: 0
Accepted
time: 284ms
memory: 4412kb
Test #149:
score: 0
Accepted
time: 455ms
memory: 4376kb
Test #150:
score: 0
Accepted
time: 81ms
memory: 4200kb
Test #151:
score: 0
Accepted
time: 241ms
memory: 4064kb
Test #152:
score: 0
Accepted
time: 181ms
memory: 4148kb
Test #153:
score: 0
Accepted
time: 486ms
memory: 4416kb
Test #154:
score: 0
Accepted
time: 201ms
memory: 4108kb
Test #155:
score: 0
Accepted
time: 309ms
memory: 4216kb
Test #156:
score: 0
Accepted
time: 513ms
memory: 4176kb
Test #157:
score: 0
Accepted
time: 101ms
memory: 4104kb
Test #158:
score: 0
Accepted
time: 328ms
memory: 4124kb
Test #159:
score: 0
Accepted
time: 483ms
memory: 4416kb
Test #160:
score: 0
Accepted
time: 141ms
memory: 4112kb
Test #161:
score: 0
Accepted
time: 129ms
memory: 4356kb
Test #162:
score: 0
Accepted
time: 103ms
memory: 4396kb
Test #163:
score: 0
Accepted
time: 109ms
memory: 4152kb
Test #164:
score: 0
Accepted
time: 229ms
memory: 4404kb
Test #165:
score: 0
Accepted
time: 91ms
memory: 4128kb
Test #166:
score: 0
Accepted
time: 330ms
memory: 4116kb
Test #167:
score: 0
Accepted
time: 302ms
memory: 4172kb
Test #168:
score: 0
Accepted
time: 517ms
memory: 4180kb
Test #169:
score: 0
Accepted
time: 483ms
memory: 4064kb
Test #170:
score: 0
Accepted
time: 208ms
memory: 4184kb
Test #171:
score: 0
Accepted
time: 323ms
memory: 4180kb
Test #172:
score: 0
Accepted
time: 123ms
memory: 4328kb
Test #173:
score: 0
Accepted
time: 425ms
memory: 4420kb
Test #174:
score: 0
Accepted
time: 169ms
memory: 4404kb
Test #175:
score: 0
Accepted
time: 207ms
memory: 4144kb
Test #176:
score: 0
Accepted
time: 417ms
memory: 4352kb
Test #177:
score: 0
Accepted
time: 128ms
memory: 4104kb
Test #178:
score: 0
Accepted
time: 176ms
memory: 4168kb
Test #179:
score: 0
Accepted
time: 221ms
memory: 4340kb
Test #180:
score: 0
Accepted
time: 47ms
memory: 4168kb
Test #181:
score: 0
Accepted
time: 388ms
memory: 4216kb
Test #182:
score: 0
Accepted
time: 172ms
memory: 4168kb
Test #183:
score: 0
Accepted
time: 156ms
memory: 4172kb
Test #184:
score: 0
Accepted
time: 526ms
memory: 4176kb
Test #185:
score: 0
Accepted
time: 526ms
memory: 4112kb
Test #186:
score: 0
Accepted
time: 530ms
memory: 4188kb