QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#342739#906. 强连通分量Ishy#WA 0ms28192kbC++142.5kb2024-03-01 16:05:322024-03-01 16:05:34

Judging History

你现在查看的是最新测评结果

  • [2024-03-01 16:05:34]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:28192kb
  • [2024-03-01 16:05:32]
  • 提交

answer

// Sea, You & Me
#include<bits/stdc++.h>
#define LL long long
#define DB double
#define MOD 1000000007
#define ls(x) (x << 1)
#define rs(x) (x << 1 | 1)
#define lowbit(x) ((-x) & x)
#define MP make_pair
#define MT make_tuple
#define VI vector<int>
#define VL vector<LL>
#define VII VI::iterator
#define VLI VL::iterator
#define all(x) x.begin(), x.end()
#define EB emplace_back
#define PII pair<int, int>
#define SI set<int>
#define SII SI::iterator
#define fi first
#define se second
using namespace std;
template<typename T> void chkmn(T &a, const T b) { (a > b) && (a = b); }
template<typename T> void chkmx(T &a, const T b) { (a < b) && (a = b); }
void Inc(int &a, const int &b) { ((a += b) >= MOD) && (a -= MOD); }
void Dec(int &a, const int &b) { ((a -= b) < 0) && (a += MOD); }
void Mul(int &a, const int &b) { a = 1LL * a * b % MOD; }
void Sqr(int &a) { a = 1LL * a * a % MOD; }
int inc(const int &a, const int &b) { return (a + b >= MOD) ? a + b - MOD : a + b; }
int dec(const int &a, const int &b) { return (a - b < 0) ? a - b + MOD : a - b; }
int mul(const int &a, const int &b) { return 1LL * a * b % MOD; }
int sqr(const int &a) { return 1LL * a * a % MOD; }
int qwqmi(int x, int k = MOD - 2)
{
	int res = 1;
	while(k)
	{
		if(k & 1) Mul(res, x);
		k >>= 1, Sqr(x);
	}
	return res;
}
template<typename T> void read(T &x)
{
	x = 0;
	int f = 1;
	char ch = getchar();
	while(!isdigit(ch))
	{
		if(ch == '-')
			f = -1;
		ch = getchar();
	}
	while(isdigit(ch))
	{
		x = (x << 1) + (x << 3) + (ch ^ 48);
		ch = getchar();
	}
	x = x * f;
}
const int N = 5e5 + 5;
int n, m;
vector<int> G[N];
stack<int> stk;
bool instack[N];
int dfn[N], low[N], timestamp;
int colcnt = 0;
vector<int> vec[N];
void tarjan(int u)
{
	low[u] = dfn[u] = ++timestamp;
	stk.push(u), instack[u] = 1;
	for(auto v : G[u])
	{
		if(!dfn[v])
		{
			tarjan(v);
			chkmn(low[u], low[v]);
		}
		else if(instack[v])
			chkmn(low[u], dfn[v]);
	}
	if(low[u] == dfn[u])
	{
		++colcnt;
		int v = -1;
		while(v != u)
		{
			v = stk.top();
			stk.pop();
			instack[v] = 0;
			vec[colcnt].EB(v - 1);
		}
	}
}
int main()
{
	read(n), read(m);
	for(int i = 1; i <= m; ++i)
	{
		int x, y;
		read(x), read(y);
		++x, ++y;
		G[x].EB(y);
	}
	for(int i = 1; i <= n; ++i)
		if(!dfn[i]) tarjan(i);
	printf("%d\n", colcnt);
	for(int i = 1; i <= colcnt; ++i)
	{
		printf("%d ", (int)vec[i].size());
		for(auto x : vec[i]) printf("%d ", x);
		puts("");
	}
	return 0;
}




Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 28192kb

input:

6 7
1 4
5 2
3 0
5 5
4 1
0 3
4 2

output:

4
2 3 0 
1 2 
2 4 1 
1 5 

result:

wrong answer 5 is later than 2, but there is an edge (5, 2)