QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#134770#5371. MatrixmasterhuangCompile Error//C++202.2kb2023-08-04 21:43:002023-08-04 21:43:01

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-04 21:43:01]
  • 评测
  • [2023-08-04 21:43:00]
  • 提交

answer

//qoj 5371 
//https://qoj.ac/problem/5371
#include<bits/stdc++.h>
#define LL long long
#define fr(x) freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);
using namespace std;
const int N=105,M=2505;
int TOT,n,a[N][N],b[N],c[N],tot=1,head[N],_head[N],d[N],S,T,tt,as[M][N];
struct edge{int to,nex,w;}e[M<<1];
inline void add(int u,int v,int w)
{
	e[++tot]={v,head[u],w};head[u]=tot;
	e[++tot]={u,head[v],0};head[v]=tot;
}
inline bool bfs()
{
	queue<int>q;memset(d,0,sizeof(d));d[S]=1;q.push(S);
	while(!q.empty())
	{
		int t=q.front();q.pop();
		for(int i=head[t];i;i=e[i].nex)
		{
			int to=e[i].to;
			if(!d[to]&&e[i].w>0) d[to]=d[t]+1,q.push(to);
		}
	}return d[T];
}
int dfs(int x,int flow)
{
	if(x==T) return flow;int old=flow;
	for(int &i=_head[x];i;i=e[i].nex)
	{
		int to=e[i].to;
		if(d[to]==d[x]+1&&e[i].w>0)
		{
			int nw=dfs(to,min(e[i].w,flow));flow-=nw;
			e[i].w-=nw,e[i^1].w+=nw;
			if(!flow) break;
		}
	}return (flow==old)&&(d[x]=0),old-flow;
}
inline int dinic(){int ans=0;while(bfs()) memcpy(_head,head,sizeof(head)),ans+=dfs(S,1e9);return ans;}
inline bool chk(){for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(a[i][j]) return 1;return 0; }
inline void sol()
{
	for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(a[i][j]<0) return cout<<"-1\n",void();
	for(int i=1,s=0;i<=n;i++,s=0){for(int j=1;j<=n;j++) s+=a[i][j];b[i]=s;}
	for(int i=1,s=0;i<=n;i++,s=0){for(int j=1;j<=n;j++) s+=a[j][i];b[i+n]=s;}
	for(int i=1;i<2*n;i++) if(b[i]^b[i+1]) return cout<<"-1\n",void();S=0;T=2*n+1;tt=0;
	while(chk())
	{
		tot=1;memset(head,0,sizeof(head));
		for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(a[i][j]) add(i,n+j,1);
		for(int i=1;i<=n;i++) add(S,i,1),add(i+n,T,1);int ans=dinic();
		for(int i=1;i<=n;i++) for(int j=head[i];j;j=e[j].nex) if(!e[j].w&&e[j].to){c[i]=e[j].to-n;if(n==50&&i==1) {cout<<c[j].to;exit(0);}break;}
		int mn=1e9;for(int i=1;i<=n;i++) mn=min(mn,a[i][c[i]]);as[++tt][0]=mn;
		for(int i=1;i<=n;i++) a[i][c[i]]-=mn,as[tt][i]=c[i]; 
	}cout<<tt<<"\n";
	for(int i=1;i<=tt;i++,cout<<"\n") for(int j=0;j<=n;j++) cout<<as[i][j]<<" ";
}
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin>>TOT;
	while(TOT--){cin>>n;for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) cin>>a[i][j];sol();}
	return 0;
}

Details

answer.code: In function ‘void sol()’:
answer.code:55:135: error: request for member ‘to’ in ‘c[j]’, which is of non-class type ‘int’
   55 |                 for(int i=1;i<=n;i++) for(int j=head[i];j;j=e[j].nex) if(!e[j].w&&e[j].to){c[i]=e[j].to-n;if(n==50&&i==1) {cout<<c[j].to;exit(0);}break;}
      |                                                                                                                                       ^~