QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#792618 | #999. 边双连通分量 | zhazha21 | RE | 1ms | 7980kb | C++17 | 1.5kb | 2024-11-29 12:00:38 | 2024-11-29 12:00:40 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005, MAXM = 500005;
struct Node
{
int f, dfn, low, ebcc;
} no[MAXN];
struct Edge
{
int u, v, next;
} e[MAXM << 1];
int ep = 2;
void connect(int u, int v)
{
e[ep] = {u, v, no[u].f};
no[u].f = ep++;
}
int tot = 0;
vector<pair<int, int>> v;
stack<int> s;
vector<int> ebcc[MAXN];
int n1 = 0;
void tarjan(int a, int f)
{
no[a].dfn = no[a].low = ++tot;
s.push(a);
for (int d = no[a].f; d; d = e[d].next)
{
if ((d ^ f) == 1)
continue;
int b = e[d].v;
if (no[b].dfn)
no[a].low = min(no[a].low, no[b].dfn);
else
{
tarjan(b, d);
no[a].low = min(no[a].low, no[b].low);
}
}
if (no[a].low == no[a].dfn)
{
++n1;
while (!s.empty())
{
int b = s.top();
s.pop();
no[b].ebcc = n1;
ebcc[n1].push_back(b);
if (b == a)
break;
}
}
}
int main()
{
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++)
{
int u, v;
cin >> u >> v;
connect(u, v);
connect(v, u);
}
for (int i = 0; i < n; i++)
if (!no[i].dfn)
tarjan(i, 0);
cout << n1 << endl;
for (int i = 1; i <= n1; i++)
{
cout << ebcc[i].size() << " ";
for (auto j : ebcc[i])
cout << j << " ";
cout << endl;
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 7568kb
input:
4 5 0 2 0 1 3 0 2 1 2 3
output:
1 4 1 2 3 0
result:
ok OK
Test #2:
score: 0
Accepted
time: 1ms
memory: 7980kb
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 1 9 5 4 11 0 3 7 6 8 4 12 10 3 2
result:
ok OK
Test #3:
score: 0
Accepted
time: 0ms
memory: 7152kb
input:
2 2 0 1 1 0
output:
1 2 1 0
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...