1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| #include <bits/stdc++.h>
using i64 = long long; using u64 = unsigned long long; using u32 = unsigned; using u128 = unsigned __int128;
std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count()); int r(int a, int b) { return rnd() % (b - a + 1) + a; }
void graph(int n, int root = -1, int m = -1) { std::vector<std::array<int, 2>> t; for (int i = 2; i <= n; i++) { t.push_back({i, r(1, i - 1)}); } std::vector<std::array<int, 2>> edge; std::set<std::array<int, 2>> uni; if (root == -1) { root = r(1, n); } for (auto [x, y] : t) { x = (x + root + n - 1) % n + 1; y = (y + root + n - 1) % n + 1; edge.push_back({x, y}); uni.insert({x, y}); } if (m != -1) { for (int i = n; i <= m; i++) { while (true) { int x = r(1, n), y = r(1, n); if (x == y) { continue; } if (uni.count({x, y})) { continue; } edge.push_back({x, y}); uni.insert({x, y}); } } } std::shuffle(edge.begin(), edge.end(), rnd); for (auto [x, y] : edge) { std::cout << x << " " << y << " " << r(0, 1) << std::endl; } }
int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr);
return 0; }
|