QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#921090#1000. 边三连通分量Mysterious_CatWA 119ms51500kbC++172.4kb2025-02-28 20:04:132025-02-28 20:04:14

Judging History

This is the latest submission verdict.

  • [2025-02-28 20:04:14]
  • Judged
  • Verdict: WA
  • Time: 119ms
  • Memory: 51500kb
  • [2025-02-28 20:04:13]
  • Submitted

answer

#include <bits/stdc++.h>
#define u64 unsigned long long
using namespace std;

mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int N = 2e5 + 5;

int n, m, tot = 1, h[N], tid[N], id[N];
bool vis[N], visr[N], cut[N], used[N];
u64 val[N][10];
vector<int> ne[N];
vector<vector<int>> ans;

struct E {
	int v, nxt;
} e[N * 2];

void add(int u, int v) {
	e[++tot].v = v;
	e[tot].nxt = h[u];
	h[u] = tot;
}

void dfs(int u, int fr) {
	vis[u] = 1;
	for (int i = h[u]; i; i = e[i].nxt) {
		if ((i ^ 1) == fr) {
			continue;
		}
		int v = e[i].v;
		if (!vis[v]) {
			ne[u].emplace_back(v);
			tid[v] = i >> 1;
			dfs(v, i);
		} else if (!visr[i >> 1]) {
			visr[i >> 1] = 1;
			for (int j = 0; j < 10; j++) {
				u64 w = rnd();
				val[i >> 1][j] = w;
				val[tid[u]][j] ^= w;
				val[tid[v]][j] ^= w;
			}
		}
	}
}

void getval(int u) {
	for (int v : ne[u]) {
		getval(v);
		for (int j = 0; j < 10; j++) {
			val[tid[u]][j] ^= val[tid[v]][j];
		}
	}
}

bool cmp(int i, int j) {
	for (int k = 0; k < 10; k++) {
		if (val[i][k] != val[j][k]) {
			return val[i][k] < val[j][k];
		}
	}
	return 0;
}

bool chk(int i, int j) {
	bool res = 1;
	for (int k = 0; k < 10; k++) {
		res &= val[i][k] == val[j][k];
	}
	return res;
}

void find(int u, vector<int> &a) {
	used[u] = 1;
	a.emplace_back(u);
	for (int i = h[u]; i; i = e[i].nxt) {
		if (cut[i >> 1]) {
			continue;
		}
		int v = e[i].v;
		if (!used[v]) {
			find(v, a);
		}
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= m; i++) {
		int u, v;
		cin >> u >> v;
		u++, v++;
		add(u, v);
		add(v, u);
	}
	for (int i = 1; i <= n; i++) {
		if (vis[i]) {
			continue;
		}
		dfs(i, 0);
		getval(i);
	}
	for (int i = 1; i <= m; i++) {
		id[i] = i;
	}
	sort(id + 1, id + m + 1, cmp);
	for (int i = 1; i <= m; i++) {
		int l = i;
		while (i < m && chk(id[i], id[i + 1])) {
			i++;
		}
		bool ok = 1;
		if (l == i) {
			for (int j = 0; j < 10; j++) {
				ok &= !val[id[i]][j];
			}
		}
		if (ok) {
			for (int j = l; j <= i; j++) {
				cut[id[j]] = 1;
			}
		}
	}
	for (int u = 1; u <= n; u++) {
		if (!used[u]) {
			vector<int> a;
			find(u, a);
			ans.emplace_back(a);
		}
	}
	cout << ans.size() << '\n';
	for (auto &a : ans) {
		cout << a.size() << ' ';
		for (int u : a) {
			cout << u - 1 << ' ';
		}
		cout << '\n';
	}

	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 14076kb

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: 0ms
memory: 9932kb

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 9 5 
4 2 3 10 12 
2 4 11 
1 6 
2 7 8 

result:

ok OK

Test #3:

score: -100
Wrong Answer
time: 119ms
memory: 51500kb

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 81390 152391 78223 1190 196087 104884 125740 61682 16810 22549 15744 166078 169371 71694 66935 72680 87685 145847 184700 116905 146552 16020 165195 144529 29270 153807 102238 52505 188825 76879 197717 44047 113217 104640 183197 118244 106637 7263 191930 14241 102601 196826 84967 ...

result:

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