mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-12-25 06:11:59 +00:00
parent
e4a0c00f54
commit
ae4f8203d8
78
LibreOJ/10091/10091.cpp
Normal file
78
LibreOJ/10091/10091.cpp
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <stack>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using std::cin;
|
||||||
|
using std::cout;
|
||||||
|
using std::endl;
|
||||||
|
|
||||||
|
// Limits
|
||||||
|
const int N = 10005;
|
||||||
|
|
||||||
|
int n, m, a, b;
|
||||||
|
std::vector<int> g[N];
|
||||||
|
|
||||||
|
// Tarjan
|
||||||
|
int cnt, dfn[N], low[N];
|
||||||
|
int scc_cnt, id[N], siz[N];
|
||||||
|
int dout[N];
|
||||||
|
bool vis[N];
|
||||||
|
std::stack<int> st;
|
||||||
|
|
||||||
|
void tarjan(int u) {
|
||||||
|
dfn[u] = low[u] = ++cnt;
|
||||||
|
st.push(u);
|
||||||
|
vis[u] = true;
|
||||||
|
for (int v : g[u]) {
|
||||||
|
if (!dfn[v]) {
|
||||||
|
tarjan(v);
|
||||||
|
low[u] = std::min(low[u], low[v]);
|
||||||
|
} else if (vis[v]) {
|
||||||
|
low[u] = std::min(low[u], dfn[v]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (dfn[u] == low[u]) {
|
||||||
|
scc_cnt++;
|
||||||
|
int v;
|
||||||
|
do {
|
||||||
|
v = st.top();
|
||||||
|
st.pop();
|
||||||
|
vis[v] = false;
|
||||||
|
id[v] = scc_cnt;
|
||||||
|
siz[scc_cnt]++;
|
||||||
|
} while (v != u);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
cin >> n >> m;
|
||||||
|
for (int i = 1; i <= m; i++) {
|
||||||
|
cin >> a >> b;
|
||||||
|
g[a].push_back(b);
|
||||||
|
}
|
||||||
|
for (int i = 1; i <= n; i++) {
|
||||||
|
if (!dfn[i]) {
|
||||||
|
tarjan(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int i = 1; i <= n; i++) {
|
||||||
|
for (int v : g[i]) {
|
||||||
|
if (id[i] != id[v]) {
|
||||||
|
dout[id[i]]++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int z = 0, sum = 0;
|
||||||
|
for (int i = 1; i <= scc_cnt; i++) {
|
||||||
|
if (!dout[i]) {
|
||||||
|
z++;
|
||||||
|
sum += siz[i];
|
||||||
|
if (z > 1) {
|
||||||
|
sum = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cout << sum << endl;
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
LibreOJ/10091/data/popular1.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/10091/data/popular1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/10091/data/popular1.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/10091/data/popular1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/10091/data/popular10.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/10091/data/popular10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/10091/data/popular10.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/10091/data/popular10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/10091/data/popular11.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/10091/data/popular11.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/10091/data/popular11.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/10091/data/popular11.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/10091/data/popular12.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/10091/data/popular12.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/10091/data/popular12.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/10091/data/popular12.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/10091/data/popular13.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/10091/data/popular13.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/10091/data/popular13.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/10091/data/popular13.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/10091/data/popular2.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/10091/data/popular2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/10091/data/popular2.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/10091/data/popular2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/10091/data/popular3.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/10091/data/popular3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/10091/data/popular3.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/10091/data/popular3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/10091/data/popular4.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/10091/data/popular4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/10091/data/popular4.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/10091/data/popular4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/10091/data/popular5.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/10091/data/popular5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/10091/data/popular5.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/10091/data/popular5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/10091/data/popular6.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/10091/data/popular6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/10091/data/popular6.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/10091/data/popular6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/10091/data/popular7.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/10091/data/popular7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/10091/data/popular7.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/10091/data/popular7.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/10091/data/popular8.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/10091/data/popular8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/10091/data/popular8.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/10091/data/popular8.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/10091/data/popular9.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/10091/data/popular9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/10091/data/popular9.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/10091/data/popular9.out
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user