比赛 20250904开学热身赛 评测结果 AWAWWWAWWWWA
题目名称 追查坏牛奶 最终得分 33
用户昵称 秋_Water 运行时间 0.036 s
代码语言 C++ 内存使用 3.78 MiB
提交时间 2025-09-04 21:36:42
显示代码纯文本
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int INF=1e9;
const int N=2500;
int n,m;
ll g[N][N],pre[N];
ll flow[N];
ll fx[N],fy[N];
vector<int>ans;
bitset<N>vis;
ll bfs(int s,int t){
	memset(pre,-1,sizeof(pre));
	flow[s]=INF;
	pre[s]=0;
	queue<int>q;
	q.push(s);
	while(!q.empty()){
		int u=q.front();
		q.pop();
		if(u==t){
			break; 
		}
		for(int i=1;i<=n;i++){
			if(i!=s&&g[u][i]>0&&pre[i]==-1){
				pre[i]=u;
				q.push(i);
				flow[i]=min(flow[u],g[u][i]);
			}
		}
	}
	if(pre[t]==-1) return -1;
	return flow[t]; 
}
ll maxflow(int s,int t){
	ll flowans=0;
	while(1){
		ll newflow=bfs(s,t);
		if(newflow==-1) break;
		int cur=t;
		while(cur!=s){
			int fa=pre[cur];
			g[fa][cur]-=newflow;
			g[cur][fa]+=newflow;
			cur=fa;
		} 
		flowans+=newflow; 
	}
	return flowans;
}
int main(){
	freopen("milk6.in","r",stdin);
	freopen("milk6.out","w",stdout);
	int s,t;
	cin>>n>>m;
	s=1,t=n;
	for(int i=1;i<=m;i++){
		int xx,yy;
		cin>>xx>>yy;
		fx[i]=xx,fy[i]=yy;
		cin>>g[xx][yy];
	} 
	cout<<maxflow(s,t)<<" ";
    queue<int> q;
    q.push(s);
    vis[s] = 1;
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        for (int i = 1; i <= n; i++) {
            if (g[u][i] > 0 && !vis[i]) {
                vis[i] = 1;
                q.push(i);
            }
        }
    }
    vector<int> cut_edges;
    for (int i = 1; i <= m; i++) {
        if (vis[fx[i]] && !vis[fy[i]]) {
            cut_edges.push_back(i);
        }
    }
    cout << cut_edges.size() << endl;
    for (int i : cut_edges) {
        cout << i << " ";
    }
    cout << endl;

	return 0;
}