4 public class inspection_rs_wa
implements Runnable
{
5 private BufferedReader in
;
6 private PrintWriter out
;
8 private void check(boolean expr
, String msg
) {
14 private void checkBounds(int n
, int low
, int hi
, String nStr
) {
15 check((low
<= n
) && (n
<= hi
), nStr
+ " is not in [" + low
+ ", " + hi
+ "]");
18 private boolean[][] go
;
19 private boolean[] mark
;
20 private int[] topsort
;
23 private List
<List
<Integer
>>[] paths
;
25 private void dfs(int u
) {
27 for (int v
= 0; v
< n
; v
++) {
28 if (!mark
[v
] && go
[u
][v
]) {
35 @SuppressWarnings("unchecked")
36 private void solve() throws IOException
{
37 n
= Integer
.parseInt(in
.readLine());
38 checkBounds(n
, 1, 100, "n");
39 go
= new boolean[n
][n
];
40 for (int i
= 0; i
< n
; i
++) {
41 StringTokenizer st
= new StringTokenizer(in
.readLine());
42 int w
= Integer
.parseInt(st
.nextToken());
43 for (int j
= 0; j
< w
; j
++) {
44 int u
= Integer
.parseInt(st
.nextToken()) - 1;
45 check(u
!= i
, "Edge from vertix to itself");
46 check(!go
[i
][u
], "Duplicate edges");
50 mark
= new boolean[n
];
53 for (int i
= 0; i
< n
; i
++) {
59 for (int i
= 0; i
< n
; i
++) {
60 for (int j
= i
+ 1; j
< n
; j
++) {
61 check(!go
[topsort
[j
]][topsort
[i
]], "graph is not acyclic");
66 for (int i
= 0; i
< n
; i
++) {
67 paths
[i
] = new ArrayList
<List
<Integer
>>();
70 for (int ii
= 0; ii
< n
; ii
++) {
72 for (int jj
= 0; jj
< ii
; jj
++) {
77 if (!paths
[j
].isEmpty()) {
78 List
<Integer
> path
= paths
[j
].get(paths
[j
].size() - 1);
79 paths
[j
].remove(paths
[j
].size() - 1);
86 List
<Integer
> path
= new ArrayList
<Integer
>();
94 out
.println(totalPaths
);
95 for (int i
= 0; i
< n
; i
++) {
96 for (List
<Integer
> path
: paths
[i
]) {
98 out
.print((j
+ 1) + " ");
105 public static void main(String
[] args
) {
106 new Thread(new inspection_rs_wa()).start();
110 String problem
= getClass().getName().split("_")[0];
112 in
= new BufferedReader(new FileReader(new File(problem
+ ".in")));
113 out
= new PrintWriter(new File(problem
+ ".out"));
117 } catch (IOException e
) {