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 has to admit, the solution I proposed last year for solving the bank cash crisis didn ' t solve the WH OLE economic crisis. As it turns out, companies don ' t has that much cash in the first place.
They has assets which is primarily shares in other companies. It is common, and acceptable, for one company to own shares in another. What complicates the issue are for both companies to own shares in each of the same time. If you think of the IT for a moment, this means, the company now (indirectly) controls its own shares.
New market regulation are being Implemented:no company can control shares in itself, whether directly or indirectly. The Stock Market authority are looking for a computerized solution that'll help it detect any buying activity that'll r Esult in a company controlling its own shares. It is obvious why they need a program to doing 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 and both purchases are acceptable.
The third purchase should be rejected since it would leads to the three companies controlling shares in themselves. The program would be given all purchasing transactions in chronological order. The program should reject any transaction that could leads to one company controlling its own shares.
All other transactions is accepted.
Inputyour program would be tested on one or more test cases. Each test case was specified on T + 1 lines. The first line specifies-positive numbers: (0 < N <= 234) is the number of companies and (0 < T <= 100, 00 0) is the number of transactions. T lines follow, each describing a buying transaction. Each transaction is specified using the numbers a and B where (0 < b <= N) indicating that company A wants to buy Shares in company B.
The last line of the input file has the 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;}
(delivery closure) HDU 3357