0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-24 17:51:58 +00:00

#1991. 【模板】缩点

https://sjzezoj.com/submission/74866
This commit is contained in:
Baoshuo Ren 2023-03-30 16:48:39 +08:00
parent 32fe353537
commit 9e86128cf2
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
45 changed files with 300 additions and 0 deletions

114
S2OJ/1991/1991.cpp Normal file
View File

@ -0,0 +1,114 @@
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1e4 + 5;
const int INF = 0x3f3f3f3f;
int n, m, a[N];
std::vector<int> g[N], g2[N];
int cnt, dfn[N], low[N];
int scc_cnt, id[N], w[N], dist[N];
bool vis[N];
std::stack<int> st;
void tarjan(int u) {
dfn[u] = low[u] = ++cnt;
vis[u] = true;
st.push(u);
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 (low[u] == dfn[u]) {
scc_cnt++;
int v;
do {
v = st.top();
st.pop();
vis[v] = false;
id[v] = scc_cnt;
w[scc_cnt] += a[v];
} while (v != u);
}
}
int spfa(int s) {
std::fill_n(dist, N, -INF);
int res = 0;
std::queue<int> q;
q.emplace(s);
dist[s] = 0;
while (!q.empty()) {
int u = q.front();
q.pop();
res = std::max(res, dist[u] + w[u]);
for (int v : g2[u]) {
if (dist[v] < dist[u] + w[u]) {
dist[v] = dist[u] + w[u];
q.push(v);
}
}
}
return res;
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1, u, v; i <= m; i++) {
cin >> u >> v;
g[u].emplace_back(v);
}
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]) {
g2[id[i]].emplace_back(id[v]);
}
}
}
int ans = 0;
for (int i = 1; i <= scc_cnt; i++) {
ans = std::max(ans, spfa(i));
}
cout << ans << endl;
return 0;
}

BIN
S2OJ/1991/data/1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1991/data/1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1991/data/10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1991/data/10.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1991/data/11.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1991/data/11.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1991/data/12.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1991/data/12.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1991/data/13.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1991/data/13.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1991/data/14.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1991/data/14.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1991/data/15.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1991/data/15.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1991/data/16.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1991/data/16.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1991/data/17.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1991/data/17.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1991/data/18.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1991/data/18.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1991/data/19.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1991/data/19.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1991/data/2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1991/data/2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1991/data/20.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1991/data/20.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1991/data/3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1991/data/3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1991/data/4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1991/data/4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1991/data/5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1991/data/5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1991/data/6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1991/data/6.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1991/data/7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1991/data/7.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1991/data/8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1991/data/8.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1991/data/9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1991/data/9.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1991/data/problem.conf (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1991/data/std.cpp (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1991/data/val.cpp (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -0,0 +1,57 @@
/**
* @file S2OJ/1991/gen.cpp
* @author Baoshuo <i@baoshuo.ren>
* @url https://baoshuo.ren
* @license GPL-3.0
* @date 2023-03-30
*/
#include "testlib.h"
#include <iostream>
#include <limits>
using std::cin;
using std::cout;
const char endl = '\n';
#define N_TESTS 20
#define PERCENT_TESTS(_percent) (static_cast<double>(_percent) / 100 * N_TESTS)
int main(int argc, char* argv[]) {
registerGen(argc, argv, 1);
int id = opt<int>("id");
int min_n = 10000,
max_n = 10000; // 1e4
int min_m = 10000,
max_m = 10000; // 1e4
if (id <= PERCENT_TESTS(50)) {
min_n = max_n = 100;
min_m = max_m = 100;
} else { // all tests
// (none)
}
int n = rnd.next(min_n, max_n);
int m = rnd.next(min_m, max_m);
cout << n << ' ' << m << endl;
for (int i = 1; i <= n; i++) {
const char end_c = i < n ? ' ' : '\n';
cout << rnd.next(0, 1000) << end_c;
}
for (int i = 1; i <= m; i++) {
int u = rnd.next(1, n);
int v = rnd.next(1, n);
cout << u << ' ' << v << endl;
}
return 0;
}