ACM-ICPC 2017 Nanning Division live race M. The Maximum unreachable Node Set

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.