Csu1612:destroy Tunnels

Source: Internet
Author: User
Tags bitset

Description

Zuosige always have bad luck. Recently, he is in hospital because of pneumonia. While he was 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 are 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.

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 would 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 is 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, the output "not exists" if any 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
Test instructions: According to the formula required by the question, can we make the matrix non-0
Because mathematics is not my strong point, in fact, this problem is more guessing.
#include <iostream> #include <stdio.h> #include <string.h> #include <stack> #include <queue& Gt #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 OFF (i,x,y) for (i=x;i>=y;i--) #define Me M (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);         }} (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

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.