QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#398527#1000. 边三连通分量TalaodiWA 202ms81908kbC++237.6kb2024-04-25 14:34:542024-04-25 14:34:55

Judging History

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

  • [2024-04-25 14:34:55]
  • 评测
  • 测评结果:WA
  • 用时:202ms
  • 内存:81908kb
  • [2024-04-25 14:34:54]
  • 提交

answer

#include <bits/stdc++.h>

namespace IO {
	template <class Stream>
	void write_int128(Stream& out, __int128 v) {
		if (v >= 10) {
			write_int128(out, v / 10);
		}
		out << (int) (v % 10);
	}

	template <class Stream>
	Stream& fmtbase(Stream& out, const char* format) {
		for (; *format; format++) {
			if (*format == '{' && *(format + 1) == '}') {
				throw std::invalid_argument("Error Number of Parameters!");
			}
			
			out << *format;
		}
		
		return out;
	}
	
	template <class Stream, class... Nxt>
	Stream& fmtbase(Stream& out, const char* format, const __int128& value, const Nxt&... nxt) {
		for (; *format; format++) {
			if (*format == '{' && *(format + 1) == '}') {
				write_int128(out, value);
				return fmtbase(out, format + 2, nxt...);
			} 
			
			out << *format;
		}
		
		throw std::invalid_argument("Error Number of Parameters!");
	}

	template <class Stream, class Fst, class... Nxt>
	Stream& fmtbase(Stream& out, const char* format, const Fst& value, const Nxt&... nxt) {
		for (; *format; format++) {
			if (*format == '{' && *(format + 1) == '}') {
				out << value;
				return fmtbase(out, format + 2, nxt...);
			} 
			
			out << *format;
		}
		
		throw std::invalid_argument("Error Number of Parameters!");
	}
	
	template <class... Ps>
	std::string to_string(const char* format, const Ps&... ps) {
		std::stringstream ss;
		fmtbase(ss, format, ps...);
		return ss.str();
	}

	template <class... Ps>
	std::ostream& fmtout(const char* format, const Ps&... ps) {
		return fmtbase(std::cout, format, ps...);
	}
	
	template <class... Ps>
	std::ostream& fmterr(const char* format, const Ps&... ps) {
		return fmtbase(std::cerr, format, ps...);
	}
	
	std::istream& allin() {
		return std::cin;
	}
	
	template <class Fst, class ... Nxt>
	std::istream& allin(Fst& fst, Nxt&... nxt) {
		std::cin >> fst;
		return allin(nxt...);
	}
	
	template <class Iter>
	std::istream& rangin(Iter begin, Iter end) {
		while (begin != end) {
			std::cin >> *begin;
			begin++;
		}
		
		return std::cin;
	}
	
	namespace Fast {
		bool sync = false;
		
		char buf[1 << 23];
		char *p1 = buf, *p2 = buf;
		
		void sync_with_ios(bool s) {
			sync = s;
		}
		
		inline char getchar() {
			if (sync) {
				return (char) std::cin.get();
			}
			else {
				return (p1 == p2) && (p2 = (p1 = buf) + fread(buf, 1, 1 << 22, stdin)), p1 == p2 ? EOF : *p1++;
			}
		}
		
		void read() { }
		
		template <class T, class... U>
		void read(T& x, U&... us) {
			x = 0;
			T pos = 1;
			
			char c = getchar();
			while (!isdigit(c)) {
				if (c == '-') {
					pos = -1;
				}
				
				c = getchar();
			}
			
			while (isdigit(c)) {
				x = 10 * x + c - '0';
				c = getchar();
			}
			
			x *= pos;
			read(us...);
		}
		
		template <class T>
		void write(const T& t) {
			if (t > 10) {
				write(t / 10);
			}
			
			std::cout << (int) (t % 10);
		}
	}
}

namespace Solve {
	using namespace IO;

	using ll = long long;
	using ul = unsigned long long;
	using db = double;
	using ld = long double;
	using ui = unsigned;
	using ib = __int128;
	using ub = __uint128_t;

	int const INF = std::numeric_limits<int>::max();
	int const NINF = std::numeric_limits<int>::min();
	ll const LINF = std::numeric_limits<ll>::max();
	ll const LNINF = std::numeric_limits<ll>::min();
	ld const EPS = 1e-8;

	std::mt19937_64 mt;

	ll rnd(ll l, ll r) {
		return std::uniform_int_distribution<ll>(l, r)(mt);
	}

	template <class T>
	inline int isz(const T& v) {
		return v.size();
	}

	template <class T>
	inline T& ckmx(T& a, T b) {
		return a < b ? (a = b) : a;
	}

	template <class T>
	inline T& ckmi(T& a, T b) {
		return b < a ? (a = b) : a;
	}

	int const N = 5e5 + 10;

	struct Edge {
		int x, y;
	};

	int n, m;
	std::vector<int> gr[N + 1];
	std::set<int> tr[N + 1];
	std::vector<Edge> out;
	int vis[N + 1];
	int dep[N + 1];
	int prt[N + 1];
	ul val[N + 1];
	std::set<int> outv;
	std::map<ul, int> id;
	std::vector<std::vector<int>> ans;

	void dfs(int x) {
		vis[x] = 1;
		int cnt = 0;
		for (auto& to : gr[x]) {
			if (vis[to]) {
				if (dep[to] < dep[x] - 1) {
					out.push_back({ x, to });
				}
				else if (dep[to] == dep[x] - 1) {
					cnt++;
					if (cnt > 1) {
						out.push_back({ x, to });
					}
				}
			}
			else {
				tr[x].insert(to);
				tr[to].insert(x);
				dep[to] = dep[x] + 1;
				prt[to] = x;
				// fmterr("tree {} {}\n", x, to);
				dfs(to);
			}
		}
	}

	void make_val(int x) {
		vis[x] = 1;
		for (auto& to : tr[x]) {
			if (to == prt[x]) {
				continue;
			}

			make_val(to);
			val[x] ^= val[to];
		}

		auto it = tr[x].begin();
		while (it != tr[x].end()) {
			if (*it != prt[x] && (outv.count(val[*it]) || val[*it] == 0)) {
				// fmterr("cut {} {}\n", x, (*it));
				tr[*it].erase(x);
				prt[*it] = 0;
				it = tr[x].erase(it);
			}
			else {
				it++;
			}
		}
	}

	void collect(int x, int fa, int ban, std::vector<int>& vs) {
		vs.push_back(x);
		for (auto& to : tr[x]) {
			if (to != fa && to != ban) {
				collect(to, x, ban, vs);
			} 
		}
	}

	void split(int x) {
		// fmterr("??? split {}\n", x);
		for (auto& to : tr[x]) {
			if (to == prt[x]) {
				continue;
			}
			split(to);
		}

		std::set<int> newv;
		auto it = tr[x].begin();
		while (it != tr[x].end()) {
			if (*it == prt[x]) {
				it++;
				continue;
			}

			if (id.count(val[*it])) {
				// fmterr("sha??1 {} {}\n", x, *it);
				ans.emplace_back();
				int ban = id[val[*it]];
				collect(*it, x, ban, ans.back());
				// for (auto& v : ans.back()) {
				// 	fmterr("{} ", v);
				// }
				// fmterr("\n");
				newv.insert(ban);
				tr[ban].erase(prt[ban]);
				prt[ban] = x;
				it = tr[x].erase(it);
				// fmterr("sha??2\n");
			}
			else {
				id[val[*it]] = *it;
				it++;
			}
		}
		for (auto& v : newv) {
			tr[x].insert(v);
		}
		// fmterr("??? split {} back\n", x);
	}

	void main() {
		std::cin >> n >> m;
		for (int i = 1; i <= m; i++) {
			int u, v;
			std::cin >> u >> v;
			u++;
			v++;
			gr[u].push_back(v);
			gr[v].push_back(u);
		}

		for (int i = 1; i <= n; i++) {
			if (!vis[i]) {
				dfs(i);
			}
		}

		for (auto& e : out) {
			auto t = mt();
			// fmterr("out {} {} {}\n", e.x, e.y, t);
			val[e.x] ^= t;
			val[e.y] ^= t;
			outv.insert(t);
		}

		memset(vis, 0, sizeof vis);
		for (int i = 1; i <= n; i++) {
			if (!vis[i]) {
				// fmterr("sha??? {}\n", i);
				make_val(i);
			}
		}

		for (int i = 1; i <= n; i++) {
			if (!prt[i]) {
				// fmterr("??? {}\n", i);
				id.clear();
				split(i);
				ans.emplace_back();
				// fmterr("ha?\n");
				collect(i, 0, 0, ans.back());
			}
		} 

		fmtout("{}\n", isz(ans));
		for (auto& v : ans) {
			std::sort(v.begin(), v.end());
		}
		std::sort(ans.begin(), ans.end());
		for (auto& v : ans) {
			assert(isz(v));
			fmtout("{} ", isz(v));
			for (auto& w : v) {
				fmtout("{} ", w - 1);
			}
			fmtout("\n");
		}
	}

	void init() {
		
	}

	void clear() {

	}
}

signed main() {
#ifndef ONLINE_JUDGE
	auto input_file = freopen("d.in", "r", stdin);
	auto output_file = freopen("d.out", "w", stdout);
#endif

	auto seed = std::chrono::high_resolution_clock::now().time_since_epoch().count();

	IO::fmterr("seed: {}\n", seed);
	Solve::mt.seed(seed);

	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout.tie(0);

	int t = 1;
	// std::cin >> t;

	Solve::init();

	for (int id = 1; id <= t; id++) {
		Solve::main();
		Solve::clear();
	}

#ifndef ONLINE_JUDGE
	std::cout.flush();
	fclose(input_file);
	fclose(output_file);
#endif

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 33952kb

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: 8ms
memory: 35064kb

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: 0
Accepted
time: 193ms
memory: 79904kb

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:

156853
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:

ok OK

Test #4:

score: 0
Accepted
time: 202ms
memory: 81008kb

input:

200000 200000
150762 148756
172967 108322
69862 125085
84513 111056
141009 156725
36311 103205
31879 79919
62895 63377
21697 115522
161610 160423
113104 10277
106927 168428
136657 198931
52292 164110
149020 7038
115111 112823
35584 124385
45429 191603
96444 30523
195578 149089
160105 58103
139792 27...

output:

156961
43040 0 1 3 4 5 8 11 16 21 23 27 33 42 45 50 59 63 67 74 75 87 91 100 108 112 114 116 123 129 134 135 136 138 140 142 145 151 155 156 157 163 164 167 172 173 176 180 184 191 193 197 203 204 205 208 212 219 220 233 246 250 251 262 265 266 267 271 273 278 279 286 291 292 293 297 299 303 306 307...

result:

ok OK

Test #5:

score: 0
Accepted
time: 188ms
memory: 81908kb

input:

200000 200000
53335 120202
193029 92221
8244 61648
50176 7825
97274 91479
85438 76999
26861 80116
162826 198446
160509 95916
143190 116619
121254 192931
121545 132273
149400 91882
97032 5048
179008 82221
187475 70697
159074 65868
158744 94466
120006 170635
36429 162768
61114 17876
131798 188508
1080...

output:

156803
43197 0 1 8 17 25 33 34 44 51 59 60 62 63 65 78 85 90 91 93 95 98 100 104 106 108 117 118 122 141 142 146 149 150 155 156 163 167 168 182 183 185 186 189 197 199 210 224 231 234 235 246 254 256 271 276 287 293 294 296 297 298 301 303 309 311 313 314 320 321 324 338 340 348 353 356 362 363 366...

result:

ok OK

Test #6:

score: 0
Accepted
time: 151ms
memory: 65828kb

input:

127669 148779
124640 77100
11865 117450
85144 68159
104241 39485
76372 84917
102044 56191
43704 26220
67216 31116
75749 123504
12078 92196
70006 15262
100591 74552
120537 38083
19281 29407
18707 6545
101149 25450
62271 9177
38892 6454
11709 119710
60867 89247
14037 9527
121858 66338
112298 81804
795...

output:

85614
1 0 
1 1 
1 2 
1 3 
1 4 
1 5 
1 6 
1 7 
1 8 
42056 9 11 12 15 19 21 22 35 36 44 47 50 51 52 62 63 64 65 66 67 73 74 77 78 79 80 84 87 90 91 93 96 97 100 105 111 112 119 123 125 128 130 131 132 136 139 140 144 150 151 155 157 160 161 164 166 172 173 175 176 177 179 181 184 188 190 195 200 212 2...

result:

ok OK

Test #7:

score: 0
Accepted
time: 131ms
memory: 68772kb

input:

150763 148757
108322 69862
125085 84513
111056 141009
36311 103205
31879 79919
62895 63377
21697 115522
113104 10277
106927 136657
52292 149020
7038 115111
112823 35584
124385 45429
96444 30523
149089 58103
139792 27250
15883 109949
69372 132387
141930 113408
65522 128254
138198 141969
42522 92075
1...

output:

119909
30855 0 1 3 4 5 8 11 12 16 21 23 27 33 42 45 48 50 56 63 67 72 74 75 79 87 89 91 100 108 114 116 118 123 132 134 135 136 138 140 142 144 145 151 155 156 163 164 166 167 172 173 176 184 193 197 204 205 212 217 219 220 226 233 246 251 256 262 266 267 269 271 273 278 279 286 291 292 293 294 297 ...

result:

ok OK

Test #8:

score: 0
Accepted
time: 94ms
memory: 57972kb

input:

53336 120203
26685 8244
50176 7825
31738 24370
25943 19902
11463 26861
29977 26309
14580 31754
1838 29437
30380 12118
51083 31633
1201 18328
26346 5295
48935 19027
31496 19906
41783 5048
47936 16685
5161 34107
15907 28002
332 27672
28930 39563
36429 31696
17876 726
42526 21682
35319 8727
17974 25252...

output:

9550
43787 0 3 4 5 6 8 9 10 11 14 15 17 18 22 23 24 25 26 27 28 29 30 32 33 34 36 37 38 39 40 41 43 44 45 47 48 49 50 51 52 54 55 56 57 58 59 60 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 78 79 80 82 83 84 85 86 88 89 90 91 92 93 94 95 96 97 101 102 103 104 105 106 107 108 109 110 111 112 114 115 ...

result:

ok OK

Test #9:

score: 0
Accepted
time: 45ms
memory: 40212kb

input:

17707 71661
1354 3272
13699 17294
16733 9246
14993 5758
7252 2983
3813 6121
10450 14069
8088 11201
857 4420
12788 2032
11938 1465
10322 15171
14688 1857
2309 2742
2013 13200
14142 16319
10541 1922
10368 1516
7994 9092
3327 5166
13484 2876
15472 13522
15622 13479
3361 15314
15464 14974
17637 7535
435...

output:

354
402 0 12 20 44 81 108 129 345 391 414 430 437 455 489 573 645 665 786 841 866 872 925 945 965 991 1023 1082 1094 1099 1136 1184 1187 1223 1227 1228 1248 1416 1420 1437 1473 1522 1543 1559 1576 1592 1628 1648 1728 1754 1842 1851 1880 1925 1930 1994 2087 2283 2384 2473 2488 2523 2537 2552 2610 268...

result:

ok OK

Test #10:

score: 0
Accepted
time: 8ms
memory: 34748kb

input:

4294 17517
1175 3250
314 389
4272 3633
2938 1831
1307 2818
3321 347
1205 1428
2354 1478
1003 3898
1587 3443
1122 1512
2512 3995
348 3280
2064 1022
1834 2958
4281 1863
689 3613
2115 3708
1645 1488
1601 4181
916 4276
128 2626
4147 2868
87 1411
1802 1451
1254 2010
2936 3120
1065 277
1121 3284
3655 2849...

output:

99
213 0 10 18 27 64 111 133 142 164 227 286 291 324 327 330 336 341 365 374 413 439 442 452 476 486 513 531 536 574 594 638 666 700 717 727 730 757 771 789 797 798 824 837 845 851 900 937 959 1015 1030 1032 1077 1090 1137 1144 1189 1198 1199 1222 1248 1280 1287 1299 1326 1335 1339 1355 1395 1470 14...

result:

ok OK

Test #11:

score: -100
Wrong Answer
time: 58ms
memory: 42892kb

input:

26686 105813
14774 5315
22701 21346
1398 13888
18566 18745
22298 6181
21347 10653
16500 23768
2329 5818
17512 16769
25519 338
12580 3064
19467 21665
3978 13202
23556 25178
195 9695
1472 13111
22925 24074
3026 13281
17666 14469
22007 18680
4159 13152
20431 23814
6671 10788
24433 13211
9794 12608
3264...

output:

554
486 0 39 149 150 162 265 490 498 524 713 943 950 1068 1138 1152 1161 1314 1376 1401 1479 1525 1664 1720 1744 1781 1785 1842 1846 1904 2084 2129 2146 2166 2266 2303 2378 2424 2438 2460 2487 2493 2511 2514 2547 2567 2705 2788 2794 2815 2969 3020 3032 3109 3187 3189 3227 3246 3283 3350 3363 3367 34...

result:

wrong answer # of tecc is differ - expected: '553', found: '554'