90pts WA 求助
  • 板块P1264 K-联赛
  • 楼主_qingshu_
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/6/18 08:47
  • 上次更新2024/6/18 09:02:03
查看原帖
90pts WA 求助
602803
_qingshu_楼主2024/6/18 08:47

前面的是快读。

#include<bits/stdc++.h>
namespace Fread{
const long long SIZE=1<<21;
	char buf[SIZE],*S,*T;
	inline char getchar(){
		if (S==T){
			T=(S=buf)+fread(buf,1,SIZE,stdin);
			if(S==T){
				return '\n';
			}
		}
		return *S++;
	}
}	
namespace Fwrite{
	const long long SIZE=1<<21;
	char buf[SIZE],*S=buf,*T=buf+SIZE;
	inline void flush(){
		fwrite(buf,1,S-buf,stdout);
		S=buf;
	}
	inline void putchar(char c){
		*S++=c;
		if(S==T){
			flush();
		}
	}
	struct NTR{
		~NTR(){
			flush();
		}
	}ztr;
} 
#ifdef ONLINE_JUDGE
#define getchar Fread::getchar
#define putchar Fwrite::putchar
#endif
namespace Fastio{
	struct Reader{
		template<typename T>
		Reader& operator>>(T& x){
			char c=getchar();
			T f=1;
			while (c<'0'||c>'9'){
				if (c=='-') f=-1;
				c=getchar();
			}
			x=0;
			while (c>='0'&&c<='9'){
				x=x*10+(c-'0');
				c=getchar();
			}
			x*=f;
			return *this;
		}
		Reader& operator>>(char& c){
			c=getchar();
			while (c==' '||c=='\n'){
				c=getchar();
			}
			return *this;
		}
		Reader& operator>>(char* str){
			long long len=0;
			char c=getchar();
			while (c==' '||c=='\n'){
				c=getchar();
			}
			while (c!=' '&&c!='\n'&&c!='\r'){ 
				str[len++]=c;
				c=getchar();
			}
			str[len]='\0';
			return *this;
		}
		Reader(){}
	}cin;
	const char endl='\n';
	struct Writer{
		template<typename T>
		Writer&operator<<(T x){
			if(x==0){
				putchar('0');
				return *this;
			}
			if(x<0){
				putchar('-');
				x=-x;
			}
			static long long sta[45];
			long long top=0;
			while(x){
				sta[++top]=x%10;
				x/=10;
			}
			while(top){
				putchar(sta[top]+'0');
				--top;
			}
			return *this;
		}
		Writer& operator<<(char c){
			putchar(c);
			return *this;
		}
		Writer& operator<<(char* str){
			long long cur=0;
			while(str[cur]){
				putchar(str[cur++]);
			}
			return *this;
		}
		Writer& operator<<(const char* str){
			long long cur=0;
			while(str[cur]){
				putchar(str[cur++]);
			}
			return *this;
		}
		Writer(){}
	}cout;
}
#define cin Fastio::cin
#define cout Fastio::cout
#define endl Fastio::endl
using namespace std;
int n,w[5200010],d[5200010],a[5200][5200],N[5200010],S,T,sum;
struct edge{
	int to,nxt;
	long long val;
}e[5200010];
int head[520010],tot=1,ans=0;
inline void add(int u,int v,long long val){
	e[++tot].to=v;
	e[tot].nxt=head[u];
	e[tot].val=val;
	head[u]=tot;
	
	e[++tot].to=u;
	e[tot].nxt=head[v];
	e[tot].val=0;
	head[v]=tot;
}
int dis[520010],now[5200010];
inline bool bfs(){
	queue<int>q;q.push(S);memset(dis,0x3f,sizeof dis);dis[S]=0;
	now[S]=head[S];while(!q.empty()){
		int x=q.front();q.pop();
		for(int i=head[x];i;i=e[i].nxt){
			int v=e[i].to;
			if(e[i].val&&dis[v]>dis[x]+1){
				dis[v]=dis[x]+1;q.push(v);now[v]=head[v];
				if(v==T)return true;
			}
		} 
	}
	return false;
}
inline long long dfs(int x,long long sum){
	if(x==T)return sum;
	long long res=0,k;
	for(int i=now[x];i&&sum;i=e[i].nxt){
		now[x]=i;int v=e[i].to;
		if(e[i].val&&dis[v]==dis[x]+1){
			k=dfs(v,min(sum,e[i].val));
			e[i].val-=k;
			e[i^1].val+=k;
			sum-=k;res+=k;
		}
	}
	return res;
}
inline void dinic(){
	while(bfs())ans+=dfs(S,INT_MAX/2);
}
inline bool check(int id){
	memset(head,0,sizeof head);tot=1;ans=0;sum=0;
	for(int i=1;i<=n;i++)N[id]+=a[id][i];N[id]+=w[id];
	for(int i=1;i<=n;i++)if(w[i]>N[id])return false;
	for(int i=1;i<=n;i++)add(i,T,N[id]-w[i]);
	for(int i=1;i<=n;i++)
	for(int j=i+1;j<=n;j++){
		add(S,i*j+n,a[i][j]);
		add(i*j+n,i,INT_MAX/2);
		add(i*j+n,j,INT_MAX/2);
		sum+=a[i][j];
	}
	dinic();
	return (ans==sum);
}
signed main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>w[i]>>d[i];S=n+n*n+1;T=S+1;
	for(int i=1;i<=n;i++)
	for(int j=1;j<=n;j++)cin>>a[i][j];
	for(int i=1;i<=n;i++)if(check(i))cout<<i<<" ";
}
2024/6/18 08:47
加载中...