正文
增加 53 行删除 31 行
1234567891011121314151617181920212223242526272829303132333435363738394041```c++#include <bits/stdc++.h>using namespace std;const int N = 1e5 + 10;int n,m;vector<int> g[N];int dfs_cnt,dfsc[N],low[N];bool vis[N];bool vis_cnt[N];void Tarjan(int u,bool root) {dfs_cnt++;dfsc[u] = low[u] = dfs_cnt;vis[u] = 1;int son = 0;for (int v : g[u]) {if (!dfsc[v]) {son++;Tarjan(v,0);low[u] = min(low[u],low[v]);if (!root && low[v] >= low[u] || root && son >= 2) vis_cnt[u] = 1;}else if (dfsc[u] > dfsc[v]) low[u] = min(low[u],dfsc[v]);}}int main() {cin >> n >> m;for (int i=1;i<=m;++i) {int u,v;cin >> u >> v;g[u].push_back(v);g[v].push_back(u);}for (int i=1;i<=n;++i) if (!vis[i]) Tarjan(i,1);// for (int i=1;i<=n;++i) cout << dfsc[i] << ' '<< low[i] << '\n';int ans = 0;for (int i=1;i<=n;++i) if (vis_cnt[i]) ans++;cout << ans << '\n';for (int i=1;i<=n;++i) if (vis_cnt[i]) cout << i << ' ';return 0;}```123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263```c++#include <bits/stdc++.h>using namespace std;int main() {ios::sync_with_stdio(false);cin.tie(nullptr);int n, m, p, k;if (!(cin >> n >> m >> p >> k)) return 0;struct Ball { long long x, y, w; };vector<Ball> a(k);for (auto& b : a) cin >> b.x >> b.y >> b.w;long long ans = 0;{vector<Ball> v = a;sort(v.begin(), v.end(), [](const Ball& A, const Ball& B) {if (A.x != B.x) return A.x < B.x;return A.y < B.y;});int i = 0;while (i < k) {int j = i;while (j < k && v[j].x == v[i].x) ++j;long long s = 0;int L = i;for (int R = i; R < j; ++R) {s += v[R].w;while (v[R].y - v[L].y > p) { s -= v[L].w; ++L; }ans = max(ans, s);}i = j;}}{vector<Ball> v = a;sort(v.begin(), v.end(), [](const Ball& A, const Ball& B) {if (A.y != B.y) return A.y < B.y;return A.x < B.x;});int i = 0;while (i < k) {int j = i;while (j < k && v[j].y == v[i].y) ++j;long long s = 0;int L = i;for (int R = i; R < j; ++R) {s += v[R].w;while (v[R].x - v[L].x > p) { s -= v[L].w; ++L; }ans = max(ans, s);}i = j;}}cout << ans << '\n';return 0;}```