Algorithm training correlation matrix time limit: 1.0s memory limit: 512.0MBThe problem description has a forward graph of n nodes m edges, 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
1 2
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
1 /*2 In the associative matrix of the graph, the horizontal axis represents the point, and the ordinate represents the edge;3 If a point is the starting point of an edge, then the corresponding value in the matrix is 1;4 If the end point, then the value is-1;5 if not associated, the value is 0;6 */7#include <stdio.h>8 intmap[ +][ +]={0};9 Main () {Ten intn,m; Onescanf"%d%d",&n,&m); A for(intI=0; i<m;i++){ - intb; -scanf"%d%d",&a,&b); themap[a-1][i]=1; -map[b-1][i]=-1; - } - for(intI=0; i<n;i++){ + for(intj=0; j<m;j++){ -printf"%d", Map[i][j]); + } Aprintf"\ n"); at } -}
C language · Correlation matrix