Sdut 2829-coming to question a (Adjacent matrix)

Source: Internet
Author: User
Come home Time Limit: 4000 Ms memory limit: 65536 k any questions? Click Here ^_^ The topic Description provides a undirected and untitled graph with n (1 <= n <= 1000) vertices and M (1 <= m <= 1000000) edges. The vertex number ranges from 1 to n. The M side may have duplicate edges. Ask how many remaining edges are removed from the duplicate edges. Multiple Input groups. The first line of input for each group contains two integers n and M. In the next m row, each line contains two integers U and V, indicating an edge between two points. Output an integer to indicate the answer. Sample Input
2 31 21 22 13 31 11 33 22 21 11 1
Sample output
131
Okay .. Shui Fa
#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;elseans--;}printf("%d\n",ans);}return 0;}

Sdut 2829-coming to question a (Adjacent matrix)

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.