loj过了,洛谷spj提示格式错误???
#include<bits/stdc++.h>
#define int long long
using namespace std;
namespace wxh666{
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#define sqrt(a) __builtin_sqrt(a)
#define f(a,b,c) for(int a=b;a<=c;a++)
#define ff(a,b,c) for(int a=b;a>=c;a--)
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
template<typename T>
inline void read(T &ans)
{
char ch=getchar();int f=1;ans=0;
for(;!isdigit(ch);ch=getchar()) ch=='-'?f=-1:f=1;
for(;isdigit(ch);ch=getchar()) ans=(ans<<3)+(ans<<1)+(ch&15);
ans*=f;
return;
}
template<typename T,typename ...Args>
inline void read(T &tmp,Args &...tmps){read(tmp);read(tmps...);}
inline int read()
{
char ch=getchar();int f=1,ans=0;
for(;!isdigit(ch);ch=getchar()) ch=='-'?f=-1:f=1;
for(;isdigit(ch);ch=getchar()) ans=(ans<<3)+(ans<<1)+(ch&15);
return f*ans;
}
// #define in read()
template<typename T>
inline void pu(T x)
{
ios::sync_with_stdio(false);
cout<<x;
ios::sync_with_stdio(true);
return;
}
template<typename T>
inline void pk(T x)
{
ios::sync_with_stdio(false);
cout<<x<<" ";
ios::sync_with_stdio(true);
return;
}
inline void pk(char x)
{
ios::sync_with_stdio(false);
cout<<x;
if(x!='\n') cout<<' ';
ios::sync_with_stdio(true);
return;
}
template<typename T,typename ...Args>
inline void pu(T x,Args ...xs){pu(x);pu(xs...);}
template<typename T,typename ...Args>
inline void ppu(T x,Args ...xs){pu(x,xs...,'\n');}
template<typename T,typename ...Args>
inline void pk(T x,Args ...xs){pk(x);pk(xs...);}
template<typename T,typename ...Args>
inline void ppk(T x,Args ...xs){pk(x,xs...,'\n');}
#define cs(dt,n,m) \
for(int i=1;i<=n;i++)\
{\
for(int j=1;j<=n;j++)\
printf("%d ",dt[i][j]);\
cout<<endl;\
}
};using namespace wxh666;
namespace lsq {
typedef int lsqxx;
struct lq {
struct lqbz {
lsqxx v,w,nxt;
} e[1000005];
lsqxx h[105],cnt=1;
inline void add(lsqxx u,lsqxx v,lsqxx w=1) {
e[++cnt].v=v;
e[cnt].w=w;
e[cnt].nxt=h[u];
h[u]=cnt;
}
void erase() {cnt=0;memset(h,0,sizeof(h));return;}
#define F(z,u) for(int j=z.h[u],v=z.e[j].v,w=z.e[j].w;j;j=z.e[j].nxt,v=z.e[j].v,w=z.e[j].w)
}q;
};
using namespace lsq;
int n,m,s=0,t;
int x,y;
int d[105];
int dfs(int u=s,int in=INT_MAX)
{
if(u==t) return in;
int out=0;
F(q,u)
{
if(d[u]>d[v]&&w)
{
int nt=dfs(v,min(w,in));
in-=nt;out+=nt;
q.e[j].w-=nt;q.e[j^1].w+=nt;
if(!in) return out;
}
}
++d[u];
return out;
}
int ISAP()
{
int ans=0;
n+=2;
while(d[s]<n+2)
ans+=dfs();
return ans;
}
signed main()
{
cin>>m>>n;t=n+1;
while(true)
{
read(x,y);
if(x==-1&&y==-1) break;
q.add(x,y);q.add(y,x,0);
}
f(i,1,m) q.add(s,i),q.add(i,s,0);
f(i,m+1,n) q.add(i,t),q.add(t,i,0);
cout<<ISAP()<<'\n';
f(i,1,m)
{
F(q,i)
{
if(v==s) continue;
if(w==0) {ppk(i,v);continue;}
}
}
return 0;
}