ABC239G题,有人能告诉我为什么只对了30个点吗
  • 板块学术版
  • 楼主doctorZ_
  • 当前回复8
  • 已保存回复8
  • 发布时间2022/2/19 21:52
  • 上次更新2023/10/28 08:07:22
查看原帖
ABC239G题,有人能告诉我为什么只对了30个点吗
111475
doctorZ_楼主2022/2/19 21:52
#include<cstdio>
#include<queue>
#define ll long long
using namespace std;
void read(int &res)
{
	res=0;int x=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') x=-x;ch=getchar();}
	while('0'<=ch&&ch<='9') res=(res<<1)+(res<<3)+(ch^48),ch=getchar();
	res*=x;
}
const int N=3000,M=100000;
const ll inf=1e18;
int n,m,s,t,st[N+10],tot=1;
struct edge
{
	int to,last;ll flow;
}e[M<<1|1];
void add(int a,int b,ll c)
{
	e[++tot].to=b;
	e[tot].flow=c;
	e[tot].last=st[a];
	st[a]=tot;
}
void Add(int a,int b,ll c){add(a,b,c),add(b,a,0);}
int dep[N+10],cur[N+10];queue<int> q;
bool bfs(int s,int t)
{
	for(int i=s;i<=t;i++) dep[i]=-1,cur[i]=st[i];
	dep[s]=0,q.push(s);
	while(!q.empty())
	{
		int u=q.front();q.pop();
		for(int i=st[u],v;i!=0;i=e[i].last)
		{
			v=e[i].to;
			if(e[i].flow!=0&&dep[v]==-1) dep[v]=dep[u]+1,q.push(v);
		}
	}
	return dep[t]!=-1;
}
ll dfs(int u,int t,ll flow)
{
	if(u==t) return flow;
	for(int i=cur[u],v,res;i!=0;i=e[i].last)
	{
		cur[u]=i,v=e[i].to;
		if(e[i].flow!=0&&dep[v]==dep[u]+1)
		{
			if((res=dfs(v,t,min(flow,e[i].flow)))!=0)
			{
				e[i].flow-=res,e[i^1].flow+=res;
				return res;
			}
		}
	}
	return 0;
}
ll dinic(int s,int t)
{
	ll res=0;
	while(bfs(s,t))
	{
		ll inc=0;
		while((inc=dfs(s,t,inf))!=0) res+=inc;
	}
	return res;
}
int eid[N+10];
int main()
{
	read(n),read(m);
	for(int i=1,a,b;i<=m;i++) read(a),read(b),Add(a+n,b,inf),Add(b+n,a,inf);
	for(int i=1,c;i<=n;i++)
	{
		read(c);
		if(i!=1&&i!=n)
		{
			add(i,i+n,1ll*c),eid[i]=tot,
			add(i+n,i,0);
		}
		else Add(i,i+n,inf);
	}
	s=1,t=2*n;
	printf("%lld\n",dinic(s,t));
	int num=0;
	for(int i=2;i<n;i++)
	{
		if(e[eid[i]].flow==0)
			num++;
	}
	printf("%d\n",num);
	for(int i=2;i<n;i++)
	{
		if(e[eid[i]].flow==0)
			printf("%d ",i);
	}
	return 0;
}
2022/2/19 21:52
加载中...