ACdream 1213 Matrix Multiplication【水题 、 找规律】
2015-08-26 11:32
393 查看
Matrix Multiplication
Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others)链接:http://acdream.info/problem?pid=1213
Problem Description
Let us consider undirected graph G = {V; E} which has N vertices and M edges. Incidence matrix of this graph is N × M matrix A = {ai,j}, suchthat ai,j 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.
Input
The first line of the input file contains two integer numbers — N and M (2 ≤ N ≤ 10 000, 1 ≤ M ≤100 000). Then 2*M 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
4 4 1 2 1 3 2 3 2 4
Sample Output
18
水题。找规律,规律出来,题就解决了。
#include <cmath> #include <queue> #include <vector> #include <cstdio> #include <string> #include <cstring> #include <iomanip> #include <iostream> #include <algorithm> using namespace std; //#pragma comment(linker, "/STACK:1024000000,1024000000") #define FIN freopen("input.txt","r",stdin) #define FOUT freopen("output.txt","w",stdout) #define CASE(T) for(scanf("%d",&T);T--;) typedef long long LL; const int maxn = 10000 + 5; int N, M, cnt[maxn]; int main() { // FIN; int a, b; while(~scanf("%d %d", &N, &M)) { memset(cnt, 0, sizeof(cnt)); for(int i = 1; i <= M; i++) { scanf("%d %d", &a, &b); cnt[a]++, cnt[b]++; } LL ans = 0; for(int i = 1; i <= N; i++) { ans += (LL)(cnt[i] * (cnt[i] - 1) / 2); } ans *= 2; ans += 2 * M; printf("%lld\n", ans); } return 0; }
相关文章推荐
- 截屏
- 推荐!国外程序员整理的Java资源大全
- 图算法模版
- 编程语言的几个命名法
- Corporative Network
- 探秘腾讯Android手机游戏平台之不安装游戏APK直接启动法
- 2015-8-26-搜房网
- LVS
- 黑马程序员——java基础——Java中常用关键字解析
- eclipse 插件安装备用
- Oracle Study之---Oracle IN和NOT IN的使用
- javascript 正则表达式 exec /g 多次循环
- html与htm的区别
- css笔记
- Segmetation fault分析
- ionic+AngularJS欢迎引导界面
- 解读Android之任务和Back栈
- SQL Server 子查询
- nohup
- Ubuntu 14.04远程登录服务器--ssh的安装和配置