QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#398526#1000. 边三连通分量TalaodiWA 438ms76412kbC++237.6kb2024-04-25 14:33:492024-04-25 14:33:50

Judging History

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

  • [2024-04-25 14:33:50]
  • 评测
  • 测评结果:WA
  • 用时:438ms
  • 内存:76412kb
  • [2024-04-25 14:33:49]
  • 提交

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) {
			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: 0ms
memory: 29020kb

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: 4ms
memory: 29248kb

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: 413ms
memory: 76412kb

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: -100
Wrong Answer
time: 438ms
memory: 71332kb

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:

156963
13747 0 4 5 21 33 50 67 87 100 108 112 116 134 135 136 138 142 151 157 164 173 180 184 193 203 246 251 267 273 279 292 293 297 313 381 409 410 424 430 432 456 491 544 555 565 584 609 644 652 660 667 680 707 722 727 729 767 773 782 785 813 819 839 840 844 856 880 882 883 901 944 954 955 967 97...

result:

wrong answer # of tecc is differ - expected: '156961', found: '156963'