标签:
4 4 1 2 1 3 2 3 2 4
18
其实就是一个矩阵,自己乘自己,画图可以秒懂
java:
import java.util.*; import java.io.*; import java.math.*; public class Main{ static final int MAXN = 10000 + 5; static int [] mp = new int[MAXN]; public static void main(String [] agrv) throws IOException { //System.setIn(new FileInputStream(new File("D:" + File.separator + "imput.txt"))); Scanner cin = new Scanner(System.in); int N, M, u, v; while(cin.hasNext()){ N = cin.nextInt(); M = cin.nextInt(); Arrays.fill(mp, 1, N + 1, 0); for(int i = 1;i <= M ;i ++){ u = cin.nextInt(); v = cin.nextInt(); if(u == v) mp[v] ++; else { mp[v] ++; mp[u] ++; } } long ans = 0; for(int i = 1;i <= N;i ++){ ans += (long)mp[i] * mp[i]; } System.out.println(ans); } } }
版权声明:本文为博主原创文章,未经博主允许不得转载。
ACdream 1213 Matrix Multiplication(矩阵相乘)
标签:
原文地址:http://blog.csdn.net/qq_18661257/article/details/47999531