Previous questions network seek time limit: 1.0s memory limit: 256.0MBProblem description
One network in X countries uses several lines to connect several nodes. The communication between nodes is bidirectional. An important packet, for security reasons, must be forwarded to the destination exactly two times. The package may be generated at any one node, and we need to know how many different forwarding paths there are in the network.
The source address and destination address can be the same, but the intermediate nodes must be different.
As shown in the network.
1, 2, 3 and 1 are allowed
1, 2, 1, 2 or 1, 2, 3, 2, are illegal.
Input format
The first behavior of the input data is two integers N M, representing the number of nodes and the number of bars connecting the lines (1<=n<=10000; 0<=m<=100000).
Then there are M-lines, each acting two integers u and V, indicating node U and v unicom (1<=u,v<=n, U!=v).
The input data guarantees that at most one edge of any two points is connected, and does not have its own edge, that is, there is no heavy edge and self-loop.
Output format outputs an integer that represents the number of path bars that satisfy the requirement. Sample Input 13 3
1 2
2 3
1 3 Example Output 16 sample input 24 4
1 2
2 3
3 1
1 4 Sample Output 210
1#include <iostream>2#include <cstring>3#include <cstdio>4#include <queue>5#include <algorithm>6 using namespacestd;7 #defineSize 100008 structedge{9 intTo,next,val;Ten }; OneEdge e[size*Ten+5]; A intH[size+5]; - intsum; - voidDfsintBintAintf) { the if(f==3){ -sum++; - return; - } + inti; - for(i=h[a];i+1; i=E[i].next) { + if(e[i].to!=b) { ADFS (a,e[i].to,f+1); at } - } - } - intMain () { - //freopen ("D:\\input.txt", "R", stdin); - intn,m; inscanf"%d%d",&n,&m); - inti,num=0, A, b; tomemset (h,-1,sizeof(h)); + for(i=0; i<m;i++){ -scanf"%d%d",&a,&b); the *e[num].to=b; $ Panax Notoginsenge[num].next=H[a]; -h[a]=num++; the +e[num].to=A; A thee[num].next=H[b]; +h[b]=num++; - } $sum=0; $ for(i=1; i<=n;i++){ -DFS (I,i,0); - } thecout<<sum<<Endl; - return 0;Wuyi}
Blue Bridge Cup previous test questions network Seek Road