同BZOJ2229
这题unique就完了
Code:
#include<bits/stdc++.h>
using namespace std;
inline int read(){
int res=0,f=1;char ch=getchar();
while(!isdigit(ch)) {if(ch=='-') f=-f;ch=getchar();}
while(isdigit(ch)) {res=(res<<1)+(res<<3)+(ch^48);ch=getchar();}
return res*f;
}
const int M=2e4+5,INF=1e9;
namespace Dinic{
int vis[M],head[M],nxt[M],c[M],tot=1;
inline void add(int x,int y,int z){
vis[++tot]=y;nxt[tot]=head[x];head[x]=tot;c[tot]=z;
vis[++tot]=x;nxt[tot]=head[y];head[y]=tot;c[tot]=z;
}
int d[M],s,t;
inline bool bfs(){
memset(d,-1,sizeof(d));
queue<int>q;
d[s]=1,q.push(s);
while(!q.empty()){
int x=q.front();q.pop();
for(int i=head[x];i;i=nxt[i]){
int y=vis[i];
if(d[y]==-1 && c[i]){
d[y]=d[x]+1;
q.push(y);
if(y==t) return 1;
}
}
}
return 0;
}
inline int dfs(int v,int flow){
if(v==t) return flow;
int res=flow,k;
for(int i=head[v];i && res;i=nxt[i]){
int y=vis[i];
if(c[i] && d[y]==d[v]+1){
k=dfs(y,min(res,c[i]));
if(!k) d[y]=-1;
c[i]-=k;c[i^1]+=k;res-=k;
if(!flow) break;
}
}
return flow-res;
}
inline int dinic(int x,int y){
s=x;t=y;
int flow,mxflow=0;
while(bfs()){
while(flow=dfs(s,INF)) mxflow+=flow;
}
return mxflow;
}
}
using namespace Dinic;
namespace MCT{
inline void reset(){
for(int i=2;i<=tot;i+=2)
c[i]=c[i^1]=(c[i]+c[i^1])>>1;
}
int p[M],col[M],ans[M],tmp[M],cnt=0;
inline void color(int v){
col[v]=1;
for(int i=head[v];i;i=nxt[i]){
if(!col[vis[i]] && c[i]) color(vis[i]);
}
}
inline void solve(int l,int r){
if(l==r) return;
reset();
int res=dinic(p[l],p[r]);
ans[++cnt]=res;
memset(col,0,sizeof(col));
color(p[l]);
int cnt1=l-1,cnt2;
for(int i=l;i<=r;i++)
if(col[p[i]]==1) tmp[++cnt1]=p[i];
cnt2=cnt1;
for(int i=l;i<=r;i++)
if(col[p[i]]==0) tmp[++cnt1]=p[i];
for(int i=l;i<=r;i++) p[i]=tmp[i];
solve(l,cnt2);solve(cnt2+1,r);
}
}
using namespace MCT;
int main(){
int n=read(),m=read();
for(int x,y,z,i=1;i<=m;i++){
x=read(),y=read(),z=read();
add(x,y,z);
}
for(int i=1;i<=n;i++) p[i]=i;
solve(1,n);
sort(ans+1,ans+cnt+1);
cnt=unique(ans+1,ans+cnt+1)-ans-1;
cout<<cnt<<endl;
return 0;
}