Algorithm training correlation matrix time limit: 1.0s memory Limit: 512.0MB problem description There is a forward graph of n nodes m-bars, please output his correlation matrix. Input format the first line two integers n, m, indicating the number of nodes and edges in the graph. n<=100,m<=1000.
Next m line, two integers a, b for each line, indicates that there are (b) edges in the diagram.
Note that the image may contain a heavy edge, but there is no self-loop. Output format output the graph's correlation matrix, and be careful not to change the order of edges and nodes. Sample Input 5 9
0 S
3 1
1 5
2 5
2 3
2 3
3 2
4 3
5 4 Sample Output 1-1 1 0 0 0 0 0 0
-1 0 0 1 1 1-1 0 0
0 1 0 0-1-1 1-1 0
0 0 0 0 0 0 0 1-1
0 0-1-1 0 0 0 0 1 The correlation matrix uses a matrix to represent the relationship between each point and each edge. For an G,PXQ graph, p is the number of vertices and q is the number of edges.
bijRepresents the relationship between midpoint I and Edge J in the correlation matrix. If the point I and the side J are connected, then
bij= 1. Conversely, the
bij= 0. For example: For the left image is a graph G, and the graph on the right is its associated matrix. For the first row of the associative matrix 1 1 1 0, represents the relationship between the point V1 and the edges. , v1 and E1,e2,e3 are connected, and E4 are not connected, so the value of the correlation matrix is 1 1 1 0. The following behavior points are associated with V2,V3, V4, and each edge, and so on. It is important to note that the sum of each row value is the degree of that point. For a direction graph, if
bij= 1, which indicates that the edge J leaves the point I. If
bij=-1, indicating the edge J entry point I. If
bij= 0, indicating that the Edge J is not associated with point I. --------from Baidu Encyclopedia
#include <cstdio> #include <cstdlib> #include <cstring>using namespace Std;int map[110][1010];int Main () {int a,b,m,n,i,j;while (scanf ("%d%d", &n,&m) ==2) {memset (map,0,sizeof (map)); for (I=1;i<=m;++i) { scanf ("%d%d", &a,&b); map[a][i]=1;map[b][i]=-1;} for (i=1;i<=n;++i) {printf ("%d", map[i][1]), for (j=2;j<=m;++j) {printf ("%d", Map[i][j]);} printf ("\ n");}} return 0;}
Algorithm Training Correlation Matrix