QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#92238 | #999. 边双连通分量 | kyEEcccccc# | RE | 5ms | 13028kb | C++14 | 1.6kb | 2023-03-30 14:33:55 | 2023-03-30 14:33:57 |
Judging History
answer
// Author: kyEEcccccc
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#define F(i, l, r) for (int i = (l); i <= (r); ++i)
#define FF(i, r, l) for (int i = (r); i >= (l); --i)
#define MAX(a, b) ((a) = max(a, b))
#define MIN(a, b) ((a) = min(a, b))
#define SZ(a) ((int)((a).size()) - 1)
const int N = 100005, M = 500005;
int n, m, u[M], v[M];
vector<pair<int, int>> to[N];
int dfn[N], tot_dfn, low[N];
vector<int> sk; bool in_sk[N];
int co[N], tot_co;
void tarjan(int u, int pe)
{
low[u] = dfn[u] = ++tot_dfn;
sk.push_back(u); in_sk[u] = 1;
for (auto ee : to[u])
{
int v = ee.first, id = ee.second;
if (id == pe) continue;
if (dfn[v] == 0) tarjan(v, id), MIN(low[u], low[v]);
else if (in_sk[v]) MIN(low[u], dfn[v]);
}
if (low[u] == dfn[u])
{
++tot_co;
while (sk.back() != u)
{
int v = sk.back(); sk.pop_back();
in_sk[v] = 0;
co[v] = tot_co;
}
sk.pop_back();
in_sk[u] = 0;
co[u] = tot_co;
}
}
vector<int> vec[N];
signed main(void)
{
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
ios::sync_with_stdio(0), cin.tie(nullptr);
cin >> n >> m;
F(i, 1, m)
{
cin >> u[i] >> v[i];
++u[i], ++v[i];
to[u[i]].emplace_back(v[i], i);
to[v[i]].emplace_back(u[i], i);
}
F(i, 1, n) if (dfn[i] == 0) tarjan(i, 0);
F(i, 1, n) vec[co[i]].push_back(i);
cout << tot_co << '\n';
F(i, 1, tot_co)
{
cout << vec[i].size() << ' ';
F(j, 0, SZ(vec[i])) cout << vec[i][j] - 1 << " \n"[j == SZ(vec[i])];
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 5ms
memory: 12036kb
input:
4 5 0 2 0 1 3 0 2 1 2 3
output:
1 4 0 1 2 3
result:
ok OK
Test #2:
score: 0
Accepted
time: 5ms
memory: 13028kb
input:
13 21 4 5 8 7 12 3 3 10 1 5 10 2 0 0 11 4 2 12 9 1 9 0 7 8 7 6 9 1 8 2 12 10 11 0 8 6 3 2 5 9 4 11
output:
3 6 0 1 4 5 9 11 3 6 7 8 4 2 3 10 12
result:
ok OK
Test #3:
score: 0
Accepted
time: 1ms
memory: 11996kb
input:
2 2 0 1 1 0
output:
1 2 0 1
result:
ok OK
Test #4:
score: -100
Runtime Error
input:
200000 200000 127668 148778 77100 11865 85144 199231 39485 84917 102044 187263 130204 174776 26220 198288 162188 12078 92196 146334 120537 38083 150353 160479 18707 6545 101149 25450 62271 9177 38892 6454 11709 191939 89247 145109 140599 121858 197410 148980 55975 169098 128576 59852 68224 182347 89...