1752: TeamBuilding

内存限制:128 MB 时间限制:3.000 S
评测方式:文本比较 命题人:
提交:0 解决:0

题目描述

You are arranging a weird game for a team building exercise. In this game there are certain locations that people can stand at, and from each location there are paths that lead to other locations, but there are not necessarily paths that lead directly back. You want the paths set up such that regardless of where someone starts, there will be at least one path they can take that will return to their starting location. You already have the locations set up, and some paths connecting them. You want to know the fewest paths that you have to add such that everything is set up the way you need it.

输入

There are several test cases,Each have two parts.The first part contains one integer,N,N is the number of the positions.The second part contains N lines, Each line contais N characters,the jth element of the ith line contains ‘1‘ means there is a path form position i to position j,contains ‘0‘ means no such path. 2<=N<=20.

输出

For each test cases ,output the fewest paths that you have to add.

样例输入 复制

3
010
100
000
4
0110
0001
0101
1000

样例输出 复制

1
0

来源/分类