diff --git a/S2OJ/1506/1506.cpp b/S2OJ/1506/1506.cpp new file mode 100644 index 00000000..3ee9e185 --- /dev/null +++ b/S2OJ/1506/1506.cpp @@ -0,0 +1,95 @@ +#include +#include + +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 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; +} diff --git a/S2OJ/1506/data/data1.in b/S2OJ/1506/data/data1.in new file mode 100644 index 00000000..a4762058 --- /dev/null +++ b/S2OJ/1506/data/data1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6bf1ba32ec1acbc20abd645c627ef82e45900da070a1d7eff59815764a9f7feb +size 20 diff --git a/S2OJ/1506/data/data1.out b/S2OJ/1506/data/data1.out new file mode 100644 index 00000000..38118f32 --- /dev/null +++ b/S2OJ/1506/data/data1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:53c234e5e8472b6ac51c1ae1cab3fe06fad053beb8ebfd8977b010655bfdd3c3 +size 2 diff --git a/S2OJ/1506/data/data10.in b/S2OJ/1506/data/data10.in new file mode 100644 index 00000000..5201bcc3 --- /dev/null +++ b/S2OJ/1506/data/data10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b69c8154cee3c867504eb65d6494c1acd07cf7c3ebe3814e56d55873cbdca10e +size 80004 diff --git a/S2OJ/1506/data/data10.out b/S2OJ/1506/data/data10.out new file mode 100644 index 00000000..7c55cca8 --- /dev/null +++ b/S2OJ/1506/data/data10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:46b9d3a6b593718297df7eb071f0725bcf72fe988f1a5cfe099ea20ceeb016bd +size 4 diff --git a/S2OJ/1506/data/data2.in b/S2OJ/1506/data/data2.in new file mode 100644 index 00000000..ed882aed --- /dev/null +++ b/S2OJ/1506/data/data2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:571815253c88020977819744af262146aecfdc61659bc3a22312786d9273c57f +size 80004 diff --git a/S2OJ/1506/data/data2.out b/S2OJ/1506/data/data2.out new file mode 100644 index 00000000..5ac03902 --- /dev/null +++ b/S2OJ/1506/data/data2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:29ef5f0b7fc0c2facd22af7e616542825331312745dfc31f37423ab0b5e005ee +size 4 diff --git a/S2OJ/1506/data/data3.in b/S2OJ/1506/data/data3.in new file mode 100644 index 00000000..84281c31 --- /dev/null +++ b/S2OJ/1506/data/data3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:57a17623624d0b940f2bdc57b2f747ede0559841361ae25da340b2e92fee3cfb +size 80004 diff --git a/S2OJ/1506/data/data3.out b/S2OJ/1506/data/data3.out new file mode 100644 index 00000000..9ea6af95 --- /dev/null +++ b/S2OJ/1506/data/data3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5ba22c28ca5e198f96731dda13761ed0853d04cfe4e0399867caf9cea15c272e +size 4 diff --git a/S2OJ/1506/data/data4.in b/S2OJ/1506/data/data4.in new file mode 100644 index 00000000..7e510dd3 --- /dev/null +++ b/S2OJ/1506/data/data4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:81acdea974e0dc1599598061f1cf4a4ce236d72ce6eabc14096db12b04fd50e5 +size 52 diff --git a/S2OJ/1506/data/data4.out b/S2OJ/1506/data/data4.out new file mode 100644 index 00000000..d595cdb8 --- /dev/null +++ b/S2OJ/1506/data/data4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7de1555df0c2700329e815b93b32c571c3ea54dc967b89e81ab73b9972b72d1d +size 2 diff --git a/S2OJ/1506/data/data5.in b/S2OJ/1506/data/data5.in new file mode 100644 index 00000000..a8f435e4 --- /dev/null +++ b/S2OJ/1506/data/data5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:14242b3947f436f5df7ebfae6b8da98210ff521cdde33aa5c03c6687ce0d19c4 +size 5003 diff --git a/S2OJ/1506/data/data5.out b/S2OJ/1506/data/data5.out new file mode 100644 index 00000000..aa471a2d --- /dev/null +++ b/S2OJ/1506/data/data5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6f3e559bbd93fa2f9b25cbd9b5f348a4b20c902d8e6498de5c28d73df8e2f571 +size 3 diff --git a/S2OJ/1506/data/data6.in b/S2OJ/1506/data/data6.in new file mode 100644 index 00000000..eb425ccb --- /dev/null +++ b/S2OJ/1506/data/data6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2cec427278171549accb6baa81de37bb7c46f95b55763f838f6da0fd6ca8cbf6 +size 3701 diff --git a/S2OJ/1506/data/data6.out b/S2OJ/1506/data/data6.out new file mode 100644 index 00000000..761a9f94 --- /dev/null +++ b/S2OJ/1506/data/data6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:420002158111bff8adb3347d84029e480f45e60e1869b454b6adac3345f9f7d4 +size 3 diff --git a/S2OJ/1506/data/data7.in b/S2OJ/1506/data/data7.in new file mode 100644 index 00000000..12b18f3b --- /dev/null +++ b/S2OJ/1506/data/data7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:05c232a1a04f69d7bba885fce2ac0b7928a08b7e5c5e5aa3c86ca25c8466f4e9 +size 11555 diff --git a/S2OJ/1506/data/data7.out b/S2OJ/1506/data/data7.out new file mode 100644 index 00000000..dff0a636 --- /dev/null +++ b/S2OJ/1506/data/data7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:95aebc97bc646c67fdcd923a5965b001f3c8a5c4d3a77075112e12a3a311d760 +size 3 diff --git a/S2OJ/1506/data/data8.in b/S2OJ/1506/data/data8.in new file mode 100644 index 00000000..b06664af --- /dev/null +++ b/S2OJ/1506/data/data8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:48dede65f9e7f40c7ec29942a3591fedfd4b04eb3cb61244d24164c2422d0713 +size 28804 diff --git a/S2OJ/1506/data/data8.out b/S2OJ/1506/data/data8.out new file mode 100644 index 00000000..fa264543 --- /dev/null +++ b/S2OJ/1506/data/data8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:806ed966b29024dcd0b6c125cc9dd50f85cb9b180bed1a909de0f410983ac10e +size 4 diff --git a/S2OJ/1506/data/data9.in b/S2OJ/1506/data/data9.in new file mode 100644 index 00000000..4944eb69 --- /dev/null +++ b/S2OJ/1506/data/data9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:592f4509a175d26d9be491882c9d8167068c75a36464052e36e9146a8870c27f +size 80004 diff --git a/S2OJ/1506/data/data9.out b/S2OJ/1506/data/data9.out new file mode 100644 index 00000000..28615f82 --- /dev/null +++ b/S2OJ/1506/data/data9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c11e3f4837efde2441e23a7b9da02131f53bf59fddeb7147c4ab81afe400460f +size 4 diff --git a/S2OJ/1506/data/problem.conf b/S2OJ/1506/data/problem.conf new file mode 100644 index 00000000..a39aada8 --- /dev/null +++ b/S2OJ/1506/data/problem.conf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:16c8474d800be5daf3cb0f74c8aa06133e1bf6d3bb8df5be994e363d2ab648b7 +size 177