mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-23 20:48:48 +00:00
parent
1f2d950fb9
commit
b3f66bd654
95
S2OJ/1506/1506.cpp
Normal file
95
S2OJ/1506/1506.cpp
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <stack>
|
||||||
|
|
||||||
|
using std::cin;
|
||||||
|
using std::cout;
|
||||||
|
const char endl = '\n';
|
||||||
|
|
||||||
|
const int N = 205;
|
||||||
|
|
||||||
|
int n, ans;
|
||||||
|
bool g[N][N], g2[N][N];
|
||||||
|
|
||||||
|
// Tarjan
|
||||||
|
int cnt, dfn[N], low[N];
|
||||||
|
int scc_cnt, id[N], siz[N];
|
||||||
|
int dout[N], din[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 i = 1; i <= n; i++) {
|
||||||
|
if (!g[u][i]) continue;
|
||||||
|
|
||||||
|
if (!dfn[i]) {
|
||||||
|
tarjan(i);
|
||||||
|
low[u] = std::min(low[u], low[i]);
|
||||||
|
} else if (vis[i]) {
|
||||||
|
low[u] = std::min(low[u], dfn[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
if (siz[scc_cnt] > 1) ans += siz[scc_cnt];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
cin.tie(nullptr);
|
||||||
|
|
||||||
|
cin >> n;
|
||||||
|
|
||||||
|
for (int i = 1; i <= n; i++) {
|
||||||
|
for (int j = 1; j <= n; j++) {
|
||||||
|
cin >> g[i][j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 1; i <= n; i++) {
|
||||||
|
if (!dfn[i]) tarjan(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 1; i <= n; i++) {
|
||||||
|
for (int j = 1; j <= n; j++) {
|
||||||
|
if (g[i][j] && id[i] != id[j]) {
|
||||||
|
g2[id[i]][id[j]] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 1; i <= scc_cnt; i++) {
|
||||||
|
for (int j = 1; j <= scc_cnt; j++) {
|
||||||
|
for (int k = 1; k <= scc_cnt; k++) {
|
||||||
|
if (i != j && j != k && g2[i][k] && g2[k][j]) {
|
||||||
|
g2[i][j] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 1; i <= scc_cnt; i++) {
|
||||||
|
for (int j = 1; j <= scc_cnt; j++) {
|
||||||
|
if (g2[i][j]) ans++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << ans << endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
S2OJ/1506/data/data1.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1506/data/data1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1506/data/data1.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1506/data/data1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1506/data/data10.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1506/data/data10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1506/data/data10.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1506/data/data10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1506/data/data2.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1506/data/data2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1506/data/data2.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1506/data/data2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1506/data/data3.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1506/data/data3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1506/data/data3.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1506/data/data3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1506/data/data4.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1506/data/data4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1506/data/data4.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1506/data/data4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1506/data/data5.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1506/data/data5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1506/data/data5.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1506/data/data5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1506/data/data6.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1506/data/data6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1506/data/data6.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1506/data/data6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1506/data/data7.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1506/data/data7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1506/data/data7.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1506/data/data7.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1506/data/data8.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1506/data/data8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1506/data/data8.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1506/data/data8.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1506/data/data9.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1506/data/data9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1506/data/data9.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1506/data/data9.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1506/data/problem.conf
(Stored with Git LFS)
Normal file
BIN
S2OJ/1506/data/problem.conf
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user