(傳遞閉包) hdu 3357

來源:互聯網
上載者:User

標籤:

Stock Chase

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


Problem DescriptionI have to admit, the solution I proposed last year for solving the bank cash crisis didn’t solve the whole economic crisis. As it turns out, companies don’t have that much cash in the first place.
They have assets which are primarily shares in other companies. It is common, and acceptable, for one company to own shares in another. What complicates the issue is for two companies to own shares in each other at the same time. If you think of it for a moment, this means that each company now (indirectly) controls its own shares.
New market regulation is being implemented: No company can control shares in itself, whether directly or indirectly. The Stock Market Authority is looking for a computerized solution that will help it detect any buying activity that will result in a company controlling its own shares. It is obvious why they need a program to do so, just imagine the situation where company A buying shares in B, B buying in C, and then C buying in A. While the first two purchases are acceptable.
The third purchase should be rejected since it will lead to the three companies controlling shares in themselves. The program will be given all purchasing transactions in chronological order. The program should reject any transaction that could lead to one company controlling its own shares.
All other transactions are accepted. 

 

InputYour program will be tested on one or more test cases. Each test case is specified on T + 1 lines. The first line specifies two positive numbers: (0 < N <= 234) is the number of companies and (0 < T <= 100, 000) is the number of transactions. T lines follow, each describing a buying transaction. Each transaction is specified using two numbers A and B where (0 < A,B <= N) indicating that company A wants to buy shares in company B.
The last line of the input file has two zeros. 

 

OutputFor each test case, print the following line:
k. R
Where k is the test case number (starting at one,) R is the number of transactions that should be rejected.
Note: There is a blank space before R. 

 

Sample Input3 61 21 33 12 11 22 30 0 

 

Sample Output1. 2 

 

Source2009 ANARC 
#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<cmath>#include<algorithm>#include<cstdlib>#include<queue>#include<vector>#include<stack>using namespace std;int n,m;bool mp[300][300];void update(int x,int y){    mp[x][y]=true;    for(int i=1;i<=n;i++)    {        if(mp[i][x])            mp[i][y]=true;    }    for(int i=1;i<=n;i++)    {        if(mp[y][i])        {            mp[x][i]=true;            for(int j=1;j<=n;j++)            {                if(mp[j][y])                    mp[j][i]=true;            }        }    }}int main(){    int x,y,cnt=0;    while(scanf("%d%d",&n,&m)!=EOF)    {        if(n==0&&m==0)            break;        int ans=0;        memset(mp,0,sizeof(mp));        for(int i=0;i<m;i++)        {            scanf("%d%d",&x,&y);            if(x==y) ans++;            else if(mp[y][x]) ans++;            else if(!mp[x][y])            {                update(x,y);            }        }        printf("%d. %d\n",++cnt,ans);    }    return 0;}

  

(傳遞閉包) hdu 3357

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.