Find the longest backlink naked question
Add some knowledge. .
Chain: A subset C in D satisfies C is a totally ordered set and all elements in C can be compared in size
Anti-chain: A subset B in D satisfies that any non-empty subset in B is not a fully ordered set, that is, all elements cannot be compared in size
Chain coverage: the union of several chains is D, and the intersection between them is ∅
Anti-chain coverage: The union of several anti-chains is D, and the intersection between them is ∅
Longest chain: The one with the largest number of elements in all chains (there can be multiple longest chains)
The longest reverse chain: the largest number of elements in all reverse chains (there can be multiple longest reverse chains
Partially ordered set height: the number of elements in the longest chain
Partially ordered set width: the number of elements in the longest anti-chain
The longest anti-chain is equal to the minimum chain coverage, and the minimum chain coverage can be obtained by bipartite graph matching.
1 #include<bits/stdc++.h> 2 #define LL long long 3 #define fi first 4 #define se second 5 #define mk make_pair 6 #define pii pair<int,int> 7 8 using namespace std; 9 10 const int N=200+7; 11 const int M=1e4+7; 12 const int inf=0x3f3f3f3f; 13 const LL INF=0x3f3f3f3f3f3f3f3f; 14 const int mod=1e9 + 7; 15 16 int n, m, match[N]; 17 bool d[N][N], vis[N]; 18 bool edge[N][N]; 19 20 int path(int u) { 21 for(int v = 1; v <= n; v++) { 22 if(edge[u][v] && !vis[v]) { 23 vis[v] = true; 24 if(match[v] == -1 || path(match[v])) { 25 match[v] = u; 26 return 1; 27 } 28 } 29 } 30 return 0; 31 } 32 int main() { 33 memset(match, -1, sizeof(match)); 34 scanf("%d%d", &n, &m); 35 for(int i = 1; i <= m; i++) { 36 int u, v; scanf("%d%d", &u, &v); 37 d[u][v] = true; 38 } 39 for(int k = 1; k <= n; k++) { 40 for(int i = 1; i <= n; i++) { 41 for(int j = 1; j <= n; j++) { 42 d[i][j] |= d[i][k] && d[k][j]; 43 } 44 } 45 } 46 47 for(int i = 1; i <= n; i++) { 48 for(int j = 1; j <= n; j++) { 49 if(d[i][j] && i != j) { 50 edge[i][j] = 1; 51 } 52 } 53 } 54 55 int ans = n; 56 for(int i = 1; i <= n; i++) { 57 memset(vis, false, sizeof(vis)); 58 if(path(i)) ans--; 59 } 60 printf("%d\n", ans); 61 return 0; 62 } 63 /* 64 */