QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#588187 | #906. 强连通分量 | shiqiaqiaya | WA | 369ms | 67788kb | C++17 | 2.7kb | 2024-09-25 05:29:04 | 2024-09-25 05:29:04 |
Judging History
answer
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/priority_queue.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define int long long
using ll = long long;
mt19937_64 rd(time(0));
template <class K, class C = less<>> using paring_heap = __gnu_pbds::priority_queue<K, C>;
template <class K, class V = null_type, class C = less<>> using rb_tree = tree<K, V, C, rb_tree_tag, tree_order_statistics_node_update>;
template <class T, class ... A> void debug(const T & t, const A & ... a) { cerr << "[" << t, ((cerr << ", " << a), ...), cerr << "]\n"; }
const ll mod = [](bool n) { return n ? 998244353 : 1e9 + 7; } (1);
template <ll mod = mod> ll binpow(ll a, ll b, ll res = 1) {
for (a %= mod; b; b >>= 1, (a *= a) %= mod) {
if (b & 1) (res *= a) %= mod;
}
return res;
}
template <class type = int, int len = 2> struct Tarjan_SC : vector<vector<signed>> {
vector<array<type, len>> e;
vector<signed> dfn, scc, low, vis;
vector sc = {};
Tarjan_SC(int n, int m) : vector(n), e(m), dfn(n), scc(n), low(n), vis(n) {}
void operator()(stack<signed> s = {}, int tot_dfn = 0) { // !! 会包含 0 , 可能 0 会成孤岛
for (int rt = 0; rt < size(); rt++) {
auto self = [&](auto && self, int u) -> void {
s.emplace(u), vis[u] = 1, dfn[u] = low[u] = ++tot_dfn;
for (auto & i : at(u)) {
int v = e[i][0] ^ e[i][1] ^ u;
if (!dfn[v]) self(self, v), low[u] = min(low[u], low[v]);
else if (vis[v]) low[u] = min(low[u], dfn[v]);
}
if (dfn[u] == low[u]) for (sc.emplace_back(); !sc.back().size() || sc.back().back() != u; s.pop()) {
scc[s.top()] = sc.size() - 1, vis[s.top()] = 0, sc.back().emplace_back(s.top());
}
};
if (!dfn[rt]) self(self, rt), s = {};
}
}
};
void QAQ() {
int n, m;
cin >> n >> m;
Tarjan_SC adj(n, m);
for (int i = 0, u, v; i < m; i++) {
cin >> u >> v;
adj[u].push_back(i);
adj.e[i] = {u, v};
}
adj();
cout << adj.sc.size() << "\n";
for (auto & x : adj.sc) {
sort(x.begin(), x.end(), greater<>());
}
sort(adj.sc.begin(), adj.sc.end(), greater<>());
for (auto & x : adj.sc) {
cout << x.size() << " ";
for (auto & v : x) {
cout << v << " ";
}
cout << "\n";
}
}
signed main() {
cin.tie(0) -> sync_with_stdio(0);
int t = 1;
// cin >> t;
for (cout << fixed << setprecision(12); t--; QAQ());
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3896kb
input:
6 7 1 4 5 2 3 0 5 5 4 1 0 3 4 2
output:
4 1 5 2 4 1 2 3 0 1 2
result:
ok OK
Test #2:
score: -100
Wrong Answer
time: 369ms
memory: 67788kb
input:
500000 500000 389812 410922 255712 339244 274009 248522 347288 199231 235313 301629 469588 84917 364188 449407 392348 436920 26220 198288 162188 468965 274222 92196 463222 408478 231663 467768 382681 38083 412497 160479 280851 268689 101149 25450 62271 9177 38892 268598 273853 250782 191939 89247 40...
output:
499590 1 499999 1 499998 1 499997 1 499996 1 499995 1 499994 1 499993 1 499992 1 499991 1 499990 1 499989 1 499988 1 499987 1 499986 1 499985 1 499984 1 499983 1 499982 1 499981 1 499980 1 499979 1 499978 1 499977 1 499976 1 499975 1 499974 1 499973 1 499972 1 499971 1 4...
result:
wrong answer 389812 is later than 410922, but there is an edge (389812, 410922)