CSU1612: Destroy Tunnels
来源:互联网 发布:北京大学网络教学平台 编辑:程序博客网 时间:2024/05/16 19:30
Description
Zuosige always has bad luck. Recently, he is in hospital because of pneumonia. While he is taking his injection, he feels extremely bored. However, clever Zuosige comes up with a new game.
Zuosige is playing a computer game called Call of Pneumonia. In the game, Zuosige is pursued by germs which may cause pneumonia. Zuosige is feared, so he wants to destroy the country. The country consists of N cities and for each city, there exits exactly one directed tunnel from it to every other city.
To destroy bridges, Zuosige gets a magic matrix An*n (Ai,j>=0). Then let , if Bi,j>0, the bridge from city i to city j will be destroyed.
Now Zuosige wants to know whether he can destroy all tunnels.
Input
The first line contains one integer T, indicating the number of test cases.
In one test case, there are several lines.
In the first line, there is one integer N (1<=n<=1000), indicating the number of cities.
In the following N lines, each line has N integers. These N lines describes matrix A. The j-th integer in i-th line is Ai,j.
Output
For each test case, output “not exists” if all tunnels can be destroyed or “exists” otherwise.
Sample Input
230 1 32 0 11 1 030 1 00 0 00 0 0
Sample Output
not existsexists
HINT
Source
#include <iostream> #include <stdio.h> #include <string.h> #include <stack> #include <queue> #include <map> #include <set> #include <vector> #include <math.h> #include <bitset> #include <algorithm> using namespace std; #define ls 2*i #define rs 2*i+1 #define up(i,x,y) for(i=x;i<=y;i++) #define down(i,x,y) for(i=x;i>=y;i--) #define mem(a,x) memset(a,x,sizeof(a)) #define w(a) while(a) #define LL long long const double pi = acos(-1.0); #define N 1000005 #define mod 19999997 const int INF = 0x3f3f3f3f; #define exp 1e-8 bitset<1005> a[1005]; int main() { int t,n,i,j,k,flag; cin>>t; w(t--) { cin>>n; up(i,1,n) { up(j,1,n) { cin>>k; a[i][j] = (k>0?1:0); } } up(i,1,n) { up(j,1,n) if(a[j][i]) a[j]|=a[i]; } flag = 0; up(i,1,n) { up(j,1,n) { if(i==j)continue; if(!a[i][j]) { flag=1; break; } } if(flag) break; } if(flag) printf("exists\n"); else printf("not exists\n"); } return 0; }
- CSU1612: Destroy Tunnels
- Destroy Tunnels(矩阵水题)
- CSU 1612: Destroy Tunnels 强连通分量 Kosaraju算法
- Destroy
- SSH-Tunnels
- Ural1553.Caves and Tunnels
- hdu 4856 Tunnels
- HDU 4856 Tunnels
- HDU-4856-Tunnels
- GRE tunnels in neutron
- URAL1553 Caves and Tunnels
- 4849: [Neerc2016]Mole Tunnels
- BZOJ4849 [Neerc2016]Mole Tunnels
- [bzoj4849]Mole Tunnels
- AbstractApplicationContext -> destroy()
- WebView.destroy()
- angularjs-$destroy
- Destroy Walls
- day14/LinkedListTest.java
- linux 命令系列之 if控制流程(60)
- Android中各种组件的生命周期
- day14/ListDemo.java
- OC协议
- CSU1612: Destroy Tunnels
- day15/ArrayListDemo.java
- Mininet的示例代码教会你用python API
- JavaScript中for..in循环陷阱介绍
- eclipse里访问tomcat首页出现404错误解决之法
- glide的配置
- day15/GenericDemo1.java
- 纯数字验证码
- day15/GenericDemo2.java