Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cstring>
- #include <algorithm>
- #include <vector>
- #include <iostream>
- #include <string>
- using namespace std;
- #define STR_BUFFER_SIZE 100000
- #define INF 1000000000
- typedef long long ll;
- typedef unsigned ui;
- int next_int()
- {int t; scanf("%d",&t); return t;}
- double next_double()
- {double t; scanf("%lf",&t); return t;}
- ll next_long()
- {ll t; scanf("%lld",&t); return t;}
- string next_string()
- {char buffer[STR_BUFFER_SIZE]; scanf("%s",buffer); return string(buffer);}
- int v[202][202];
- bool used[202];
- int s=0, t,n;
- bool dfs(int s,int t ,int c)
- {
- if(used[s]) return false;
- if(s==t) return true;
- used[s]=true;
- for(int i=0;i<=t;i++)
- {
- if(v[s][i]>=c&&dfs(i,t,c))
- {
- v[s][i]-=c;
- v[i][s]+=c;
- return true;
- }
- }
- return false;
- }
- int main()
- {
- n=next_int();
- int sum1=0,sum2=0;
- t=2*n+1;
- for(int i=1;i<=n;i++)
- sum1+=(v[s][i]=next_int());
- for(int i=1;i<=n;i++)
- sum2+=(v[i+n][t]=next_int());
- if(sum1==sum2)
- {
- for(int i=1;i<=n;i++)
- for(int j=1;j<=n;j++)
- v[i][j+n]=INF;
- int flow=0;
- int c=INF;
- while(c>0)
- {
- memset(used,0,sizeof(used));
- if(dfs(s,t,c))
- flow+=c;
- else
- c>>=1;
- }
- if(flow==sum1)
- {
- printf("YES\n");
- for(int i=1;i<=n;i++)
- {
- for(int j=1;j<=n;j++)
- printf("%d ",v[j+n][i]);
- puts("");
- }
- return 0;
- }
- }
- printf("NO\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment