Description
Input
Output
Maximum number of attractions to choose from
Sample Input7 6
1 2
2 3
5 4
4 3
3 6
6 7
Sample Output2
HINT
The question is the conclusion
Answer = Longest anti-chain = minimum path overlay =n-binary graph Max match
First Floyd to deal with the connectivity between two points, and then split, if a can go to B, a to B ' connected edge
#include <cstdio> #include <iostream> #include <cstring> #define LL long long#define inf 0x7ffffff# Define S 0#define T 2*n+1using namespace Std;inline ll read () {LL X=0,f=1;char Ch=getchar (); while (ch< ' 0 ' | | Ch> ' 9 ') {if (ch== '-') F=-1;ch=getchar ();} while (ch>= ' 0 ' &&ch<= ' 9 ') {x=x*10+ch-' 0 '; Ch=getchar ();} return x*f;} struct Edge{int to,next,v;} E[100010];int n,m,cnt=1,ans;bool go[1010][1010];int head[100010];int q[100010];int h[100010];inline void ins (int u,int V,int W) {e[++cnt].to=v; E[cnt].v=w; E[cnt].next=head[u]; head[u]=cnt;} inline void Insert (int u,int v,int W) {ins (u,v,w); Ins (v,u,0);} inline bool BFs () {memset (h,-1,sizeof (h)); Q[1]=s;h[s]=0;int t=0,w=1; while (t<w) {int now=q[++t]; for (int i=head[now];i;i=e[i].next) if (e[i].v&&h[e[i].to]==-1) {q[++w]=e[i].to; h[e[i].to]=h[now]+1; }} if (H[t]==-1) return 0; return 1;} inline int DFs (int x,int f) {if (x==t| |! f) return F; int w,used=0; for (int i=head[x];i;i=e[i].next) if (e[i].v&&h[e[i].to]==h[x]+1) {W=dfs (E[i].to,min (f-u SED,E[I].V)); E[i].v-=w; E[i^1].v+=w; Used+=w; if (used==f) return F; } if (!used) h[x]=-1; return used;} inline void Dinic () {while (BFS ()) Ans+=dfs (S,inf);} int main () {n=read (); M=read (); for (int i=1;i<=m;i++) {int x=read (), Y=read (); Go[x][y]=1; } for (int k=1;k<=n;k++) for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) if (Go[i][k]&&go[k][j] ) Go[i][j]=1; for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) if (Go[i][j]) insert (i,j+n,1); for (int i=1;i<=n;i++) Insert (s,i,1), insert (i+n,t,1); Dinic (); printf ("%d\n", N-ans);}
bzoj2718 [Violet 4] Graduation Trip