9 const int maxn
=10001,maxm
=50001;
21 int ehead
[maxn
],dis
[maxn
],low
[maxn
],contract
[maxn
],cnt
,tot
;
23 std::stack
<int> stack
;
25 inline void insert_edge(int p
, int q
)
29 edge
[cnt
].next
=ehead
[p
];
38 for (int p
=ehead
[i
]; p
!=-1; p
=edge
[p
].next
)
42 if (instack
[j
]) low
[i
]=std::min(low
[i
],low
[j
]);
59 std::memset(ehead
,255,sizeof(ehead
));
69 for (int i
=1; i
<=m
; ++i
)
71 std::scanf("%d%d",&data
[i
].src
,&data
[i
].dest
);
72 insert_edge(data
[i
].src
,data
[i
].dest
);
74 for (int i
=1; i
<=n
; ++i
) if (!dis
[i
]) dfs(i
);
76 for (int i
=1; i
<=m
; ++i
)
77 insert_edge(contract
[data
[i
].src
],contract
[data
[i
].dest
]);
79 for (int i
=1; i
<=n
; ++i
)
80 if (contract
[i
]==i
&& ehead
[i
]==-1)
81 if (ans
==0) ans
=i
; else if (ans
!=i
) ans
=-1;
93 for (int i
=1; i
<=n
; ++i
) tmp
+=(contract
[i
]==ans
);