您的位置:首页 > 其它

ZOJ-2316-鄙视浙大的OJ

2015-03-10 22:56 309 查看
以前一直都是在POJ上面刷,今年要报ACM ICPC只好在自己学校的OJ上面刷,2316这道题真坑,最开始线性代数上面aij指的是第i行j列的元素,这道题居然是第j行i列,出题者你学过线代吗?害我笔算程序算,算好多遍都和sample output不一样!然后就是该死的格式,什么叫输出块之间空一行,最开始第一行空了,WA,后来又WA,原来最后一行也不能空,我去,从没见过这么严格的OJ,而且这东西有什么意义啊!另:今天起入住CSDN写博客啦~

question:

Matrix Multiplication

Time Limit: 2 Seconds Memory Limit: 32768 KB

Let us consider undirected graph G = which has N vertices and M edges. Incidence matrix of this graph is N * M matrix A = {aij}, such that aij is 1 if i-th vertex
is one of the ends of j-th edge and 0 in the other case. Your task is to find the sum of all elements of the matrix ATA.

This problem contains multiple test cases!

The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank
line between input blocks.
The output format consists of N output blocks. There is a blank line between output blocks.

Input

The first line of the input file contains two integer numbers - N and M (2 <= N <= 10 000, 1 <= M <= 100 000). 2M integer numbers follow, forming M pairs, each pair describes one edge
of the graph. All edges are different and there are no loops (i.e. edge ends are distinct).

Output

Output the only number - the sum requested.

Sample Input

1

4 4

1 2

1 3

2 3

2 4

Sample Output

18

code:

#include <iostream>

#include <memory.h>

#include <stdio.h>

using namespace std;

int main()

{

int a[10001];

int repeat, n, m;

int v1, v2;

int sum;

cin >> repeat;

for (int r = 0; r<repeat; r++)

{

memset(a, 0, sizeof(a));

cin >> n >> m;

sum = 0;

for (int i = 0; i<m; i++)

{

cin >> v1 >> v2;

a[v1]++;

a[v2]++;

}

for (int q = 1; q<=n; q++)

{

sum += a[q] * a[q];

}

cout << sum << endl;

if (r<repeat-1)cout << endl;

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: