比赛 |
20250904开学热身赛 |
评测结果 |
AWAAWAAAAAAA |
题目名称 |
追查坏牛奶 |
最终得分 |
83 |
用户昵称 |
会挽弯弓满月 |
运行时间 |
0.232 s |
代码语言 |
C++ |
内存使用 |
3.81 MiB |
提交时间 |
2025-09-04 21:39:31 |
显示代码纯文本
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=40,M=1e3+10,inf=1e9+7,mo=2000;
int read(){
int x=0,f=1;
char c=getchar();
while(c<48||c>57){
if(c==45) f=-1;
c=getchar();
}
while(c>=48&&c<=57){
x=x*10+c-48;
c=getchar();
}
return f*x;
}
int n,m;
struct node{
int to,val,nxt,ids,from;
void cl(){
to=0;val=0;nxt=0;ids=0;from=0;
return;
}
}e[M<<2];
int vals[M<<2];
int h[N],tot=1;
void add(int u,int v,int w,int id){
e[++tot].to=v;
e[tot].from=u;
e[tot].val=w;
e[tot].nxt=h[u];
e[tot].ids=id;
vals[tot]=w/mo;
h[u]=tot;
return;
}
int s,t;
int dep[N];
bool bfs(){
queue<int> q;
memset(dep,-1,sizeof(dep));
dep[s]=1;q.push(s);
int u,v,w;
while(q.size()){
u=q.front();q.pop();
for(int i=h[u];i;i=e[i].nxt){
v=e[i].to;w=e[i].val;
if(w<=0) continue;
if(dep[v]!=-1) continue;
dep[v]=dep[u]+1;
q.push(v);
}
}
if(dep[t]==-1) return 0;
return 1;
}
int dfs(int u,int flow){
if(u==t) return flow;
int rmn=flow;
int v,w,c;
for(int i=h[u];i&&rmn;i=e[i].nxt){
v=e[i].to;w=e[i].val;
if(w<=0) continue;
if(dep[v]!=dep[u]+1) continue;
c=dfs(v,min(rmn,w));
if(c==0){
dep[v]=-1;
continue;
}
rmn-=c;
e[i].val-=c;
e[i^1].val+=c;
}
return flow-rmn;
}
int ans;
void dinic(){
while(bfs()) ans+=dfs(s,inf);
}
void init(){
ans=0;
for(int i=2;i<=tot;i++){
e[i].val=vals[i];
}
return;
}
int maxn,tip;
int sum[N],cnt;
signed main(){
freopen("milk6.in","r",stdin);
freopen("milk6.out","w",stdout);
n=read();m=read();
int u,v,w;
s=1;t=n;
for(int i=1;i<=m;i++){
u=read();v=read();w=read();
add(u,v,w*mo+1,i);add(v,u,0,i);
}
dinic();
printf("%lld %lld\n",ans/mo,ans%mo);
maxn=ans/mo;
for(int i=2;i<=tot;i+=2){
init();
tip=e[i].val;
e[i].val=0;
e[i^1].val=0;
dinic();
if(ans+tip==maxn){
sum[++cnt]=e[i].ids;
maxn-=tip;
vals[i]=0;
vals[i^1]=0;
}
if(maxn==0) break;
}
sort(sum+1,sum+cnt+1);
for(int i=1;i<=cnt;i++){
printf("%lld\n",sum[i]);
}
return 0;
}