程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> HDOJ 3394 Railway

HDOJ 3394 Railway

編輯:C++入門知識


tarjan縮塊,比較塊中點和邊的數量關系。。。


Railway

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 808 Accepted Submission(s): 332


Problem Description There are some locations in a park, and some of them are connected by roads. The park manger needs to build some railways along the roads, and he would like to arrange tourist routes to each circuit. If a railway belongs to more than one tourist routes, there might be clash on it, and if a railway belongs to none tourist route, it doesn’t need to build.
Now we know the plan, and can you tell us how many railways are no need to build and how many railways where clash might happen.
Input The Input consists of multiple test cases. The first line of each test case contains two integers, n (0 < n <= 10000), m (0 <= m <= 100000), which are the number of locations and the number of the railways. The next m lines, each line contains two integers, u, v (0 <= u, v < n), which means the manger plans to build a railway on the road between u and v.
You can assume that there is no loop and no multiple edges.
The last test case is followed by two zeros on a single line, which means the end of the input.
Output Output the number of railways that are no need to build, and the number of railways where clash might happen. Please follow the format as the sample.
Sample Input
8 10
0 1
1 2
2 3
3 0
3 4
4 5
5 6
6 7
7 4
5 7
0 0

Sample Output
1 5

Author momodi@whu
Source The 5th Guangting Cup Central China Invitational Programming Contest


#include 
#include 
#include 
#include 

using namespace std;

const int maxn=11000;

struct Edge
{
    int to,next;
}edge[maxn*20];

int n,m,ans1,ans2;
int Adj[maxn],Size;

void init()
{
    Size=0; memset(Adj,-1,sizeof(Adj));
}

void Add_Edge(int u,int v)
{
    edge[Size].to=v;
    edge[Size].next=Adj[u];
    Adj[u]=Size++;
}

int Low[maxn],DFN[maxn],Stack[maxn];
bool inStack[maxn];
int Index,top;
int block[maxn];

void ck()
{
    int num=0;
    for(int t=1;t<=block[0];t++)
    {
        for(int i=Adj[block[t]];~i;i=edge[i].next)
        {
            int j=edge[i].to;
            if(inStack[j]) num++;
        }
    }
    num/=2;

    if(block[0]>num) ans1+=num;
    else if(block[0]=DFN[u])
            {
                memset(inStack,false,sizeof(inStack));
                block[0]=0;
                do
                {
                    block[++block[0]]=Stack[--top];
                    inStack[Stack[top]]=true;

                }while(Stack[top]!=v);
                block[++block[0]]=u;
                inStack[u]=true;
                ck();
            }
        }
        else Low[u]=min(Low[u],DFN[v]);
    }
}

void solve()
{
    memset(Low,0,sizeof(Low));
    memset(DFN,0,sizeof(DFN));
    memset(block,0,sizeof(block));
    memset(inStack,0,sizeof(inStack));
    top=Index=0;

    for(int i=0;i


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved