Algorithm Training Correlation Matrix

Source: Internet
Author: User

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
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

#include <iostream>#include<cstdio>#include<algorithm>#include<cstdlib>#definefor (i,x,n) for (int i=x;i<n;i++)#definell Long Long intusing namespacestd;inta[ the][1005]={0};intMain () {intM,n; intx, y; scanf ("%d%d",&n,&m);  forI0, M) {scanf ("%d%d",&x,&y); A[x][i]=1; A[y][i]=-1; }     forI1, n+1){         for(J,0, M) {printf ("%d", A[i][j]); } printf ("\ n"); }    return 0;}

Algorithm Training Correlation Matrix

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.