POJ3352-Road Construction

Source: Internet
Author: User

POJ3352-Road Construction
Road Construction

Time Limit:2000 MS Memory Limit:65536 K
Total Submissions:8652 Accepted:4323

Description

It's almost summer time, and that means that it's almost summer construction time! This year, the good people who are in charge of the roads on the tropical island paradise of Remote Island wowould like to repair and upgrade the various roads that lead between the various tourist attractions on the island.

The roads themselves are also rather interesting. due to the strange customs of the island, the roads are arranged so that they never meet at intersections, but rather pass over or under each other using bridges and tunnels. in this way, each road runs between two specific tourist attractions, so that the tourists do not become irreparably lost.

Unfortunately, given the nature of the repairs and upgrades needed on each road, when the construction company works on a participant road, it is unusable in either direction. this cocould cause a problem if it becomes impossible to travel between two tourist attractions, even if the construction company works on only one road at any participant time.

So, the Road Department of Remote Island has decided to call upon your consulting services to help remedy this problem. it has been decided that new roads will have to be built between the varous attractions in such a way that in the final configuration, if any one road is undergoing construction, it wowould still be possible to travel between any two tourist attractions using the remaining roads. your task is to find the minimum number of new roads necessary.

Input

The first line of input will consist of positive integersNAndR, Separated by a space, where 3 ≤N≤ 1000 is the number of tourist attractions on the island, and 2 ≤R≤ 1000 is the number of roads. The tourist attractions are conveniently labeled from 1N. Each of the followingRLines will consist of two integers,VAndW, Separated by a space, indicating that a road exists between the attractions labeledVAndW. Note that you may travel in either direction down each road, and any pair of tourist attractions will have at most one road directly between them. also, you are assured that in the current configuration, it is possible to travel between any two tourist attractions.

Output

One line, consisting of an integer, which gives the minimum number of roads that we need to add.

Sample Input

Sample Input 110 121 21 31 42 52 65 63 73 87 84 94 109 10Sample Input 23 31 22 31 3

Sample Output

Output for Sample Input 12Output for Sample Input 20
 
Bare computing edge dual-connectivity component.
# Include
  
   
# Include
   
    
# Include
    
     
# Include
     
      
# Include
      
       
# Include
       
         # Include
        
          Using namespace std; const int maxn = 1000 + 10; vector
         
           G [maxn]; int n, m; int dfn [maxn], lown [maxn]; int du [maxn]; int dfs_clk; void init () {for (int I = 0; I <= n; I ++) {G [I]. clear () ;}dfs_clk = 0; memset (dfn, 0, sizeof dfn); memset (du, 0, sizeof du);} int dfs (int u, int fa) {int lowu = dfn [u] = dfs_clk ++; for (int I = 0; I <G [u]. size (); I ++) {int d = G [u] [I]; if (! Dfn [d]) {int lowv = dfs (d, u); lowu = min (lowu, lowv );} else if (dfn [d] <dfn [u] & d! = Fa) {lowu = min (lowu, dfn [d]) ;}} lown [u] = lowu; return lowu ;} int main () {while (~ Scanf ("% d", & n, & m) {init (); while (m --) {int a, B; scanf ("% d", & a, & B); G [a]. push_back (B); G [B]. push_back (a);} dfs (1,-1); for (int I = 1; I <= n; I ++) {for (int j = 0; j <G [I]. size (); j ++) {int k = G [I] [j]; if (lown [I]! = Lown [k]) {du [lown [I] ++; // statistics inbound }}int block = 0; for (int I = 0; I <dfs_clk; I ++) {if (du [I] = 1) ++ block;} printf ("% d \ n", (block + 1) /2);} return 0 ;}
         
        
       
      
     
    
   
  


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.