Acdream 1213 Matrix Multiplication

Source: Internet
Author: User

Test instructions: To a graph with no direction, the correlation matrix of this graph is a. It then computes the and of all the elements in the ATA matrix.

Idea: If the matrix to find out, space is not able to withstand, the amount of data is too large. All we ask for is the and of the various elements of ATA. Look at the correlation matrix, you can find that, for the two vertices without edges, the contribution of this edge to the result is the degree of the two vertices, so only need to scan each edge, and then add the appearance of the degree of the vertex can be.


#include <iostream> #include <stdio.h> #include <cmath> #include &lt ;algorithm> #include <iomanip> #include <cstdlib> #include &LT;STRING&G            
T #include <memory.h> #include <vector> #include <queue> #include < stack> #include <map> #include <set> #include <ctype.h> #define LL Lo   
 
 
ng Long #define MAX3 (A,B,C) max (A,max (b,c)) using namespace Std;
int edge[100010][2];
 
int cnt[10010];
    int main () {int n,m;
        while (cin>>n>>m) {memset (cnt,0,sizeof (CNT));
            for (int i=1;i<=m;i++) {int u,v;
            scanf ("%d%d", &u,&v);
            Edge[i][0]=u;
            Edge[i][1]=v;
            cnt[u]++;
        cnt[v]++;
        } ll Ans=0; for (int i=1;i<=m;i++) {ans+=cnt[edge[i][0]];
        ANS+=CNT[EDGE[I][1]];
    } cout<<ans<<endl;
} return 0; }


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.