F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Arborescence Counting

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


Problem Description
"In graph theory, an arborescence is a directed graph in which, for a vertex v called the root and any other vertex u, there is exactly one directed path rom v to u. In other words, an arborescence is a directed, rooted tree in which all edges point away from the root. Every arborescence is a directed acyclic graph."-- from Wikipedia, the free encyclopedia

You are given a directed graph with N vertices, and your task is to count the number of different arborescences of size N that can be found in the given graph.

Two arborescences are considered different when they consist of different edges.
 

Input
Input consists of multiple test cases.
For each test case, the first line contains one integer N described as above.
N lines follows, each consists of N characters, either '0' or '1', representing the adjacency matrix of the graph.
The directed graph contains edge (i,j) if and only if the jth character of the ith line of the matrix is '1'.
The graph consists of no more than 8 vertices.
End of input is indicated by a line consisting of a single 0.
 

Output
For each test case, output one line consisting of one single integer, the number of arborescences.
 

Sample Input
2 00 00 2 01 10 0
 

Sample Output
0 2
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 12:54:51, Gzip enabled