码迷,mamicode.com
首页 > 其他好文 > 详细

SDUT 2829-家快来A水题(邻接矩阵)

时间:2014-09-12 13:32:33      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:des   style   http   color   io   os   java   ar   for   

家快来A水题

Time Limit: 4000ms   Memory limit: 65536K  有疑问?点这里^_^

题目描述

给出一个无向无权图,有n(1<= n <= 1000)个点,m(1<= m <= 1000000)条边。点的编号从1到n。m条边中可能会有重复的边,问去掉重复的边之后还剩下多少条边。
 

输入

多组输入。每组输入的第一行包括两个整数n,m。接下来的m行,每行包含两个整数u,v,表示两点之间有一条边。

输出

输出一个整数代表答案。

示例输入

2 3
1 2
1 2
2 1
3 3
1 1
1 3
3 2
2 2
1 1
1 1

示例输出

1
3
1
好吧。。水一发
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
using namespace std;
bool ma[1002][1002];
int main()
{
	int n,m;
	while(~scanf("%d%d",&n,&m))
	{
		int u,v;
		memset(ma,0,sizeof(ma));
		int ans=m;
		for(int i=1;i<=m;i++)
		{
			scanf("%d%d",&u,&v);
			if(!ma[u][v])
				ma[u][v]=ma[v][u]=1;
			else
				ans--;
		}
		printf("%d\n",ans);
	}
	return 0;
}

SDUT 2829-家快来A水题(邻接矩阵)

标签:des   style   http   color   io   os   java   ar   for   

原文地址:http://blog.csdn.net/qq_16255321/article/details/39228475

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!