QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#446551 | #4809. Maximum Range | IBory | WA | 36ms | 17792kb | C++20 | 2.0kb | 2024-06-17 12:45:45 | 2024-06-17 12:45:45 |
Judging History
answer
#include <bits/stdc++.h>
#define pii pair<int, int>
using namespace std;
const int MAX = 100007;
vector<pii> G[MAX], BCC[MAX];
int V[MAX], E[MAX], B[MAX], pv[MAX], dn, bn;
bool no[MAX];
vector<int> S;
pii P[MAX];
int DFS(int cur, int prev) {
int ret = V[cur] = ++dn;
for (auto [next, en] : G[cur]) {
if (next == prev) continue;
if (V[cur] > V[next]) S.push_back(en);
if (V[next]) {
ret = min(ret, V[next]);
continue;
}
int t = DFS(next, cur);
ret = min(ret, t);
if (t < V[cur]) continue;
bn++;
do {
int e = S.back(); S.pop_back();
B[e] = bn;
BCC[bn].emplace_back(E[e], e);
} while (BCC[bn].back().second != en);
sort(BCC[bn].begin(), BCC[bn].end());
}
return ret;
}
vector<int> BFS(int S, int EA, int EB) {
memset(V, 0, sizeof(V));
queue<int> Q;
Q.push(S); V[S] = 1;
while (!Q.empty()) {
int cur = Q.front(); Q.pop();
if (cur == EA || cur == EB) break;
for (auto [next, _] : G[cur]) {
if (V[next] || no[next]) continue;
V[next] = 1;
pv[next] = cur;
Q.push(next);
}
}
vector<int> ret;
int c = (V[EA] ? EA : EB);
if (!V[c]) return {};
while (c != S) {
ret.push_back(c);
c = pv[c];
}
ret.push_back(S);
reverse(ret.begin(), ret.end());
return ret;
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int N, M;
cin >> N >> M;
for (int i = 1; i <= M; ++i) {
int a, b;
cin >> a >> b >> E[i];
G[a].emplace_back(b, i);
G[b].emplace_back(a, i);
P[i] = {a, b};
}
DFS(1, 0);
int go = -1, id = 0;
for (int i = 1; i <= bn; ++i) {
if (BCC[i].size() == 1) continue;
int n = BCC[i].back().first - BCC[i][0].first;
if (go < n) {
go = n;
id = i;
}
}
auto [a, b] = P[BCC[id][0].second];
auto [c, d] = P[BCC[id].back().second];
no[b] = 1;
vector<int> P1 = BFS(a, c, d);
no[b] = 0;
for (int n : P1) no[n] = 1;
vector<int> P2 = BFS(no[c] ? d : c, b, 0);
for (int n : P2) P1.push_back(n);
cout << go << '\n';
cout << P1.size() << '\n';
for (int n : P1) cout << n << ' ';
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5912kb
input:
5 7 1 2 1 1 3 -2 2 3 1 3 4 3 4 5 1 1 5 -1 2 5 2
output:
5 4 1 5 4 3
result:
ok ok
Test #2:
score: -100
Wrong Answer
time: 36ms
memory: 17792kb
input:
99997 100000 12238 99016 352755196 99016 25485 -412473602 25485 2440 991507552 2440 31171 -181894654 36970 2440 -800167579 2440 41865 -148191946 96629 31171 847888506 36970 95740 395546542 27992 2440 647886610 99016 29557 369124914 80795 27992 -673871966 36970 3509 573208857 57672 29557 874406776 41...
output:
1959330954 22 95092 34883 46301 96778 37694 88289 30288 68523 54073 84997 89628 67966 84407 3463 72825 51491 87712 96230 22074 44442 4697 96048
result:
wrong answer Edge 96048-95092 does not appear in original graph