답안 #644386

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
644386 2022-09-24T14:44:23 Z vovamr Praktični (COCI18_prakticni) C++17
130 / 130
112 ms 22744 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fi first
#define se second
#define ll long long
#define ld long double
#define sz(x) ((int)(x).size())
#define all(x) 	(x).begin(), (x).end()
#define pb push_back
#define mpp make_pair
#define ve vector
using namespace std;
using namespace __gnu_pbds;
template<class T> using oset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll inf = 1e18; const int iinf = 1e9;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T> inline bool chmin(T& a, T b) { return (a > b ? a = b, 1 : 0); }
template <typename T> inline bool chmax(T& a, T b) { return (a < b ? a = b, 1 : 0); }

const int N = 1e5 + 10;
ve<array<int,3>> gr[N];
int x[N], used[N];

ve<array<int,4>> rest;
inline void dfs(int v, int p) {
	used[v] = 1;
	for (auto &[to, w, id] : gr[v]) {
		if (!used[to]) {
			x[to] = x[v] ^ w;
			dfs(to, v);
		}
		else if (used[to] == 1 && to != p) {
			rest.pb({v, to, w, id});
		}
	}
	used[v] = 2;
}

const int D = 31;
int bs[D];
inline void add(int x) {
	for (int i = D - 1; ~i; --i) {
		if (x >> i & 1 ^ 1) continue;
		if (!bs[i]) { bs[i] = x; break; }
		x ^= bs[i];
	}
}

ve<int> list[N];
inline void represent(int x, int id) {
	for (int i = D - 1; ~i; --i) {
		if (x >> i & 1 ^ 1) continue;
		::list[i].pb(id);
		x ^= bs[i];
	}
}

inline void solve() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; ++i) {
		int v, u, w;
		cin >> v >> u >> w, --v, --u;
		gr[v].pb({u, w, i});
		gr[u].pb({v, w, i});
	}
	dfs(0, 0);
	for (auto &[v, u, w, id] : rest) {
		int val = w ^ x[v] ^ x[u];
		add(val);
	}

	for (auto &[v, u, w, id] : rest) {
		int val = w ^ x[v] ^ x[u];
		represent(val, id);
	}

	ve<pair<int,ve<int>>> answer;
	for (int i = 0; i < D; ++i) {
		if (!sz(::list[i])) continue;
		answer.pb({bs[i], ve<int>(0)});

		for (auto &id : ::list[i]) {
			answer.back().se.pb(id + 1);
		}
	}

	cout << sz(answer) << '\n';
	for (auto &[x, vec] : answer) {
		cout << x << " " << sz(vec) << " ";
		for (auto &id : vec) cout << id << " ";
		cout << '\n';
	}
}

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int q = 1; // cin >> q;
	while (q--) solve();
	cerr << fixed << setprecision(3) << "Time execution: " << (double)clock() / CLOCKS_PER_SEC << endl;
}

Compilation message

parkticni.cpp: In function 'void add(int)':
parkticni.cpp:46:14: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   46 |   if (x >> i & 1 ^ 1) continue;
      |       ~~~~~~~^~~
parkticni.cpp: In function 'void represent(int, int)':
parkticni.cpp:55:14: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   55 |   if (x >> i & 1 ^ 1) continue;
      |       ~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 9288 KB Output is correct
2 Correct 28 ms 9264 KB Output is correct
3 Correct 8 ms 6228 KB Output is correct
4 Correct 8 ms 5844 KB Output is correct
5 Correct 51 ms 13004 KB Output is correct
6 Correct 55 ms 12464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 6996 KB Output is correct
2 Correct 14 ms 7188 KB Output is correct
3 Correct 17 ms 7548 KB Output is correct
4 Correct 19 ms 8064 KB Output is correct
5 Correct 48 ms 12740 KB Output is correct
6 Correct 30 ms 9836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 10356 KB Output is correct
2 Correct 43 ms 11680 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 12308 KB Output is correct
2 Correct 86 ms 19012 KB Output is correct
3 Correct 3 ms 5076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 11040 KB Output is correct
2 Correct 46 ms 11604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 15292 KB Output is correct
2 Correct 29 ms 9292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 13200 KB Output is correct
2 Correct 78 ms 17648 KB Output is correct
3 Correct 50 ms 11876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 86 ms 18208 KB Output is correct
2 Correct 112 ms 22744 KB Output is correct
3 Correct 95 ms 20584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 7680 KB Output is correct
2 Correct 24 ms 8596 KB Output is correct
3 Correct 62 ms 14516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 72 ms 14444 KB Output is correct
2 Correct 59 ms 10376 KB Output is correct
3 Correct 109 ms 18964 KB Output is correct