煩人的交通Submit: 433 Accepted:256Time Limit: 1000MS Memory Limit: 1000K
Description
奧運會來了,北京的交通實在讓人擔憂,特别是交錯複雜的立交橋 。真是讓人眼花缭亂,是以聰明的你,要為交通部規劃一種方案來簡化這煩人的立交橋。
簡化方案是,在任意兩個地方都能通過立交橋到達的前提下,盡量減少橋的數量。
假設每條立交橋連接配接了兩個不同的地方,并且立交橋是無向的。(注意:由于現有的立交橋是在太混亂,兩個地方甚至有多條立交橋可到達 ――!)
Input
以下會給出1<=N<=1000個地方,0<=M<=500000000條立交橋,後面有m行,每行兩個數a , b , 表示a , b兩點相連(1 <= a , b <= N)。
你可以确定,給出的橋可以使任意兩個地方都能通過立交橋到達。
Output
你需要輸出需要删除多餘的立交橋的數量。
Sample Input
5 7
4 5
1 2
1 3
1 4
2 3
2 4
3 4
Sample Output
3
Source
Wangkun
#include<iostream>
using namespace std;
int main()
{
int i,b,e,count=0,n,m;
int a[1001]; //A記錄已經出現過的數字
for(i=0;i<1001;i++)
a[i]=0;
while(cin>>n>>m)
{
for(i=0;i<m;i++)
{
cin>>b>>e;
if(a[b]==0)
{
a[b]=1;
count++;
}
if(a[e]==0)
{
a[e]=1;
count++;
}
}
if(count<=n) //沒有貌似也對~
cout<<"0"<<endl;
else
cout<<m-n+1<<endl;
}
return 0;
}
簡單的:
#include<iostream>
using namespace std;
int main()
{
int i,b,e,count=0,n,m;
while(cin>>n>>m)
{
for(i=0;i<m;i++)
{
cin>>b>>e;
}
cout<<m-n+1<<endl;
}
return 0;
}
這也能AC。。。。