QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#569168 | #906. 强连通分量 | hly | WA | 1ms | 3812kb | C++11 | 1.2kb | 2024-09-16 21:05:45 | 2024-09-16 21:05:46 |
Judging History
answer
#include <iostream>
#include <stack>
#include <vector>
using namespace std;
vector<vector<int>> edges;
vector<int> dfn;
vector<int> low;
int dfn_count=0;
stack<int> s;
vector<bool> in_stack;
vector<vector<int>> SCCs;
void Tarjan(int v)
{
dfn[v]=++dfn_count;
low[v]=dfn_count;
in_stack[v]=true;
s.push(v);
for(auto i:edges[v])
{
if(dfn[i]!=0)
{
Tarjan(i);
low[v]=min(low[v],low[i]);
}
else if(in_stack[i]==true)
low[v]=min(low[v],low[i]);
}
if(dfn[v]==low[v])
{
vector<int> t;
//t.push_back(v);
while(s.top()!=v)
{
int s_top=s.top();
s.pop();
t.push_back(s_top);
in_stack[s_top]=false;
}
int s_top=s.top();
s.pop();
t.push_back(s_top);
in_stack[s_top]=false;
}
}
int main()
{
int N,M;
cin>>N>>M;
edges.resize(N);
dfn.resize(N,0);
low.resize(N);
in_stack.resize(N,false);
while(M-->0)
{
int a,b;
cin>>a>>b;
edges[a].push_back(b);
}
for(int i=0;i<N;i++)
if(dfn[i]!=0)
Tarjan(i);
cout<<SCCs.size()<<endl;
for(auto i:SCCs)
{
int n=i.size();
cout<<n;
for(int j=n-1;j>=0;j--)
{
cout<<" "<<i[j];
}
cout<<endl;
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3812kb
input:
6 7 1 4 5 2 3 0 5 5 4 1 0 3 4 2
output:
0
result:
wrong answer Integer 0 violates the range [1, 6]