Analysis reprinted from http://blog.csdn.net/yukizzz/article/details/51029628 test instructions:
Given the N and m two-way edges, change the bidirectional edge to one-way edge, and ask the minimum number of unreachable vertices?
Analysis:
If you cannot reach it, the entry level is 0.
DFS determines whether a ring exists in each of the connected blocks, and if there is a ring, it guarantees that each point in the ring has a degree greater than or equal to 1. Otherwise, the symbolizing, the head of the penetration is 0.
1 varHead,vet,next,flag:Array[1..200000] ofLongint;2 N,m,x,y,tmp,ans,tot,i:longint;3 4 procedureAdd (a,b:longint);5 begin6 Inc (TOT);7next[tot]:=Head[a];8vet[tot]:=b;9head[a]:=tot;Ten End; One A procedureDFS (u,pre:longint); - varE,v:longint; - begin the ifflag[u]=1 Then begintmp:=0; ExitEnd; -flag[u]:=1; -e:=Head[u]; - whileE<>0 Do + begin -v:=Vet[e]; + ifV<>pre ThenDFS (v,u); Ae:=Next[e]; at End; - End; - - begin -Assign (input,'1.in'); Reset (input); -Assign (output,'1.out'); Rewrite (output); in readln (n,m); - fori:=1 toM Do to begin + read (x, y); - Add (x, y); the Add (y,x); * End; $ fori:=1 toN DoPanax Notoginseng ifflag[i]=0 Then - begin thetmp:=1; +DFS (I,0); Aans:=ans+tmp; the End; + writeln (ans); -//close (input); $//close (output); $ End.
View Code
"cf659e" New reform