QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#398386#1000. 边三连通分量_l_l_WA 280ms67556kbC++142.6kb2024-04-25 11:22:322024-04-25 11:22:33

Judging History

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

  • [2024-04-25 11:22:33]
  • 评测
  • 测评结果:WA
  • 用时:280ms
  • 内存:67556kb
  • [2024-04-25 11:22:32]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500005;
typedef unsigned long long ull;
vector<int> G[MAXN];
int dfn[MAXN], low[MAXN], instk[MAXN], times;
int scc[MAXN], btot; stack<int> stk;
void dfs1(int u, int f) {
	dfn[u] = low[u] = ++times; instk[u] = 1; stk.push(u); for (int v : G[u]) {
		if (v == f) {f = -1; continue;}
		if (dfn[v] == 0) dfs1(v, u), low[u] = min(low[u], low[v]);
		else if (instk[v]) low[u] = min(low[u], dfn[v]);
	}
	if (dfn[u] == low[u]) {
		int y; btot++; do {
			y = stk.top(); stk.pop(); instk[y] = 0; scc[y] = btot;
		} while (y != u);
	}
}
map<ull, int> mp; map<ull, pair<int, int> > etmp; ull exor[MAXN]; int fa[MAXN];
mt19937_64 rnd(time(0));
void dfs2(int u, int f) {
	dfn[u] = 1; instk[u] = 1; fa[u] = f; for (int v : G[u]) {
		if (scc[v] != scc[u]) continue;
		if (v == f) {f = -1; continue;}
		if (dfn[v] == 0) dfs2(v, u), exor[u] ^= exor[v];
		else if (instk[v]) {
			ull tmp = rnd(); etmp[tmp] = {u, v};
			exor[u] ^= tmp; exor[v] ^= tmp;
		}
	}
	instk[u] = 0;
}
set<pair<int, int> > bann;
void dfs3(int u, int f) {
	dfn[u] = 2; for (int v : G[u]) {
		if (scc[v] != scc[u]) continue;
		if (v == f) {f = -1; continue;}
		if (dfn[v] == 1) {
			set<int> resv; dfs3(v, u);
			if (etmp.find(exor[v]) != etmp.end()) {
				bann.insert({u, v}); bann.insert({v, u});
				auto x = etmp[exor[v]]; bann.insert(x);
				swap(x.first, x.second); bann.insert(x);
			}
			else if (mp.find(exor[v]) != mp.end()) {
				int w = mp[exor[v]];
				bann.insert({u, v}); bann.insert({v, u});
				bann.insert({w, fa[w]}); bann.insert({fa[w], w});
			}
			else mp[exor[v]] = v;
		}
	}
	stk.push(u);
}
vector<vector<int>> ans;
void dfs4(int u, int f, vector<int> &res) {
	res.push_back(u); dfn[u] = 3; for (int v : G[u]) {
		if (scc[v] != scc[u]) continue;
		if (v == f) {f = -1; continue;}
		if (bann.find({u, v}) != bann.end()) continue;
		if (dfn[v] == 2) dfs4(v, u, res);
	}
}
int main() {
	int n, m; scanf("%d %d", &n, &m);
	for (int i = 1; i <= m; i++) {
		int u, v; scanf("%d %d", &u, &v); if (u == v) continue;
		G[u].push_back(v); G[v].push_back(u);
	}
	for (int i = 0; i < n; i++) if (dfn[i] == 0) dfs1(i, i);
	memset(dfn, 0, sizeof dfn);
	for (int i = 0; i < n; i++) if (dfn[i] == 0) dfs2(i, i), dfs3(i, i);
	for (int i = 0; i < n; i++) if (dfn[i] == 2) {
		vector<int> res; dfs4(i, i, res); ans.push_back(res);
	}
	for (auto &x : ans) sort(x.begin(), x.end());
	sort(ans.begin(), ans.end(), [](vector<int> &x, vector<int> &y) {return x[0] < y[0];});
	printf("%d\n", (int)ans.size());
	for (auto &x : ans) {
		printf("%d ", (int)x.size());
		for (auto y : x) printf("%d ", y); puts("");
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 23636kb

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: 21632kb

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: 280ms
memory: 67556kb

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:

159966
1 0 
38298 1 2 3 4 9 12 13 17 22 46 51 56 61 70 78 84 99 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 272 274 282 283 284 289 295 300 305 313 323 358 359 363 366 375 384 386 387 392 396 403 408 410 414 418 421 426 429 435 ...

result:

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