QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#399074#1000. 边三连通分量ningagoWA 230ms76804kbC++146.4kb2024-04-25 21:27:472024-04-25 21:27:49

Judging History

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

  • [2024-04-25 21:27:49]
  • 评测
  • 测评结果:WA
  • 用时:230ms
  • 内存:76804kb
  • [2024-04-25 21:27:47]
  • 提交

answer

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <cctype>
#include <set>
#include <bitset>

namespace uvu
{
#define LOCAL ____________DONT_DEFINE_ME____________
#define ll long long
#define inf 0x3f3f3f3f
// #define int long long
// #define inf 0x3f3f3f3f3f3f3f3fll
#define infll 0x3f3f3f3f3f3f3f3fll
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define gline debug("now is #%d\n", __LINE__)
#define pii std::pair <int, int>
#define mkp std::make_pair
#define fi first
#define se second
char _ST_;
const int BUFSIZE = (1 << 20);
char ibuf[BUFSIZE], *iS = ibuf, *iT = ibuf;
char obuf[BUFSIZE], *oS = obuf, *oT = obuf + BUFSIZE;
char getc()
{
#ifdef LOCAL
	return getchar();
#else
	if(iS == iT) iT = (iS = ibuf) + fread(ibuf, 1, BUFSIZE, stdin);
	return iS == iT ? EOF : *iS++;
#endif
#define getchar ERR
}

void Flush() { fwrite(obuf, 1, oS - obuf, stdout); oS = obuf; }
struct Flusher { ~Flusher(){ Flush(); } }iamflusher;

void putc(char c)
{
#ifdef LOCAL
	putchar(c);
#else
	*oS++ = c;
	if(oS == oT) Flush();
#endif
#define putchar ERR
}

template <typename T = int> T read()
{
	T x = 0, f = 1; char c = getc();
	for(; !isdigit(c); c = getc()) if(c == '-') f = -1;
	for(;  isdigit(c); c = getc()) x = (x << 3) + (x << 1) + (c ^ 48);
	return x * f;
}

template <typename T> void print(T x, char c)
{
static int sta[BUFSIZE], top;
	top = 0;
	if(x < 0) putc('-'), x = -x;
	if(!x) sta[top = 1] = 0;
	for(; x; x /= 10) sta[++top] = x % 10;
	for(; top; ) putc(sta[top--] ^ 48);
	if(c) putc(c);
}

int readstr(char *s, int base)
{
	int idx = base - 1; char c = getc();
	for(; !(isdigit(c) || isalpha(c) || c == '#' || c == '?'); c = getc());
	for(;   isdigit(c) || isalpha(c) || c == '#' || c == '?' ; c = getc()) s[++idx] = c;
	return idx - base + 1;
}

void printf(const char *s) { for(; *s; s++) putc(*s); }
template <typename T, typename ... Args>
void printf(const char *s, T x, Args ... rest)
{
	for(; *s; s++)
	{
		if(*s != '%') { putc(*s); continue; }
		s++; if(*s == 'd') print(x, 0);
		else if(*s == 'c') putc(x);
		printf(s + 1, rest ...);
		return;
	}
}

template <typename T> void ckmax(T &x, T y) { x = x > y ? x : y; }
template <typename T> void ckmin(T &x, T y) { x = x < y ? x : y; }
#define mod 998244353
// #define mod 1000000007
int sm(int x) { return x >= mod ? x - mod : x; }
void plus_(int &x, int y) { x = sm(x + y); }
void mul_(int &x, int y) { x = 1ll * x * y % mod; }
int ksm(int a, int b) { int res = 1; for(; b; b >>= 1, mul_(a, a)) if(b & 1) mul_(res, a); return res; }

#define N 1000010
int n, m;
int h[N], e[N << 1], ne[N << 1], idx = -1;
void add_edge(int x, int y) { ne[++idx] = h[x]; h[x] = idx, e[idx] = y; }
void add(int x, int y) { add_edge(x, y), add_edge(y, x); }
int dfn[N], low[N]; bool bridge[N], bridge3[N];

void tarjan(int k, int in_edge)
{
	low[k] = dfn[k] = ++dfn[0];
	for(int i = h[k]; ~i; i = ne[i])
	{
		if(i == in_edge) continue;
		int nx = e[i];
		if(!dfn[nx]) 
		{
			tarjan(nx, i ^ 1);
			ckmin(low[k], low[nx]);
			if(low[nx] > dfn[k]) bridge[i >> 1] = bridge3[i >> 1] = 1;
		}
		else ckmin(low[k], dfn[nx]);
	}
}

#define ui unsigned int
ui sd = 'x' + 'i' + 'n' + 'y' + 'u' + 'e';
ui rnd()
{
	sd ^= sd << 11;
	sd ^= sd >> 7;
	sd ^= sd << 13;
	return sd;
}

ui edgeval[N], val[N], dt[N], dts[N];
int fdfn[N], intree[N], par[N];
std::map <ui, bool> mp;
bool spe[N];
void dfs0(int k, int in_edge)
{
	fdfn[dfn[k] = ++dfn[0]] = k;
	for(int i = h[k]; ~i; i = ne[i])
	{
		int nx = e[i]; if(bridge[i >> 1] || i == in_edge) continue;
		if(dfn[nx])
		{
			if(dfn[nx] > dfn[k]) continue;
			mp[edgeval[i >> 1] = rnd()] = 1;
			val[nx] ^= edgeval[i >> 1];
			val[k] ^= edgeval[i >> 1];
			// printf("(%d %d) [%d %d] (%d)\n", k, nx, val[nx], val[k], edgeval[i >> 1]);
			continue;
		}
		par[nx] = k;
		dfs0(nx, i ^ 1);
		intree[i >> 1] = 1;
		val[k] ^= val[nx];
	}

}
std::pair <ui, int> sta[N]; int top;
void dfs1(int k, int fa, int in_edge)
{
	// printf("val[%d] = %d\n", k, val[k]);
	if(fa) sta[++top] = mkp(val[k], in_edge);//, printf("val[%d %d] = %d\n", fa, k, val[k]);
	if(fa && mp[val[k]]) 
	{
		// ui v = rnd();
		// dt[fa] ^= v;
		// dt[k] ^= v;
		spe[k] = 1;
		// printf("spe %d\n", k);
	}
	for(int i = h[k]; ~i; i = ne[i])
	{
		int nx = e[i]; if(!intree[i >> 1] || i == in_edge) continue;
		dfs1(nx, k, i ^ 1);
	}
}

int tot; bool vis[N];
std::vector <int> vec[N];
std::map <ui, int> id;
int p[N];
void dfs2(int k, int fa, ui all)
{
	if(spe[k]) all = rnd();
	dts[k] ^= dts[fa];
	for(int i = h[k]; ~i; i = ne[i]) if(intree[i >> 1] && e[i] != fa) dfs2(e[i], k, all), dt[k] ^= dt[e[i]];
	ui v = dt[k] ^ dts[k] ^ all;
	// printf("v[%d] = %d (%d %d)\n", k, v, dts[k], dt[k]);
	if(!id[v]) id[v] = ++tot;
	vec[id[v]].push_back(k);
}

void solve()
{
	memset(h, idx = -1, sizeof(h));
	n = read(), m = read();
	for(int i = 1, x, y; i <= m; i++) 
	{
		x = read(), y = read();
		x++; y++;
		if(x != y) add(x, y);
	}
	for(int i = 1; i <= n; i++) if(!dfn[i]) tarjan(i, -1);
	memset(dfn, 0, sizeof(dfn));
	for(int r = 1; r <= n; r++) if(!dfn[r])
	{
		dfs0(r, -1);
		dfs1(r, top = 0, -1);
		std::stable_sort(sta + 1, sta + 1 + top);
		for(int l = 1, r; l <= top; l = r + 1)
		{
			for(r = l; r < top && sta[r + 1].fi == sta[l].fi; r++);
			if(l == r) continue;
			ui v = rnd();
			std::reverse(sta + l, sta + r + 1);
			for(int i = l; i <= r; i++) 
			{
				int k = e[sta[i].se ^ 1];
				// printf("[%d %d] ", fa, k);
				if(i != l) dts[k] ^= v;//, printf("dts[%d] ^= %d\n", fa, v);
				v = rnd();
				if(i != r) dts[k] ^= v;//, printf("dts[%d] ^= %d\n", k, v);
			}
			// putc('\n');
		}
		dfs2(r, 0, rnd());
	}
	for(int i = 1; i <= tot; i++) std::sort(vec[p[i] = i].begin(), vec[i].end());
	std::sort(p + 1, p + 1 + tot, [&](int x, int y) -> bool { return vec[x][0] < vec[y][0]; });
	printf("%d\n", tot);
	for(int _ = 1; _ <= tot; _++)
	{
		printf("%d ", vec[p[_]].size());
		// for(int k : vec[p[_]]) print(k, ' ');
		for(int k : vec[p[_]]) print(k - 1, ' ');
		putc('\n');
	}
}

void init()
{
	
}

char _ED_;

void mian()
{
	debug("%.3f MB\n", abs(&_ST_ - &_ED_) / 1024.0 / 1024);
	init();
	int T;
	for(T = 1; T; solve(), T--);
}

#ifdef int
	#undef int
#endif
}

int main()
{
	// freopen("tmp.in", "r", stdin);
	// freopen("tmp.out", "w", stdout);
	uvu::mian(); return 0;
}

详细

Test #1:

score: 100
Accepted
time: 7ms
memory: 41548kb

input:

4 5
0 2
0 1
3 0
2 1
2 3

output:

3
2 0 2 
1 1 
1 3 

result:

ok OK

Test #2:

score: 0
Accepted
time: 5ms
memory: 41844kb

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:

6
1 0 
3 1 5 9 
4 2 3 10 12 
2 4 11 
1 6 
2 7 8 

result:

ok OK

Test #3:

score: -100
Wrong Answer
time: 230ms
memory: 76804kb

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...

output:

156851
1 0 
43148 1 2 3 4 9 12 13 17 22 36 46 51 52 56 58 61 70 74 77 78 84 98 99 102 117 123 130 133 136 141 161 164 172 174 175 177 184 189 190 192 195 212 220 221 225 232 233 234 246 256 262 267 268 270 272 274 282 283 284 289 295 300 303 305 313 323 358 359 363 366 367 375 384 386 387 392 396 40...

result:

wrong answer # of tecc is differ - expected: '156853', found: '156851'