Title Link: https://nanti.jisuanke.com/t/19979
Test instructions: Give a DAG with n dots and M edges, and select the largest subset to make the node 22 unreachable.
Solving: Reference from: 79849472
First, using Freud to run out of an accessibility matrix, and then start from each point Dfs run binary graph, the last DFS out of the path is a number of chains, and for the chain apparently except for the last node, the other nodes are to be deleted, and the total number of other nodes is the number of running two-point graph matching, minus the total.
1#include <bits/stdc++.h>2 using namespacestd;3 #definell Long Long4 #defineull unsigned long Long5 #defineMST (b) memset ((a), (b), sizeof (a))6 #defineMP (A, b) Make_pair (A, B)7 #definePi ACOs (-1)8 #definePII pair<int,int>9 #definePB Push_backTen Const intINF =0x3f3f3f3f; One Const DoubleEPS = 1e-6; A Const intMAXN = 1e5 +Ten; - Const intMAXM = 2e6 +Ten; - the intn,m; - intg[ the][ the],fa[ the]; - BOOLvis[ the]; - + BOOLDfsintu) { - for(inti =1; I <= N; i++) { + if(G[u][i] &&!Vis[i]) { AVis[i] =true; at if(Fa[i] = =0||DFS (Fa[i])) { -Fa[i] =u; - return true; - } - } - } in return false; - } to + intMain () { - #ifdef Local theFreopen ("Data.txt","R", stdin); * //freopen ("Data.txt", "w", stdout); $ #endifPanax Notoginseng intT; -scanf"%d",&t); the while(t--) { +scanf"%d%d",&n,&m); A for(inti =1; I <= N; i++) { theFa[i] =0; + for(intj =1; J <= N; J + +) G[i][j] =0; - } $ while(m--) { $ intu,v; -scanf"%d%d",&u,&v); -G[U][V] =1; the } - for(intK =1; K <= N; k++)Wuyi for(inti =1; I <= N; i++) the for(intj =1; J <= N; J + +) -G[I][J] |= G[i][k] &G[k][j]; Wu intres =0; - for(inti =1; I <= N; i++) { AboutMST (VIS,0); $ if(Dfs (i)) res++; - } -printf"%d\n"Nres); - } A return 0; +}
ACM-ICPC 2017 Nanning Division live race M. The Maximum unreachable Node Set