structEdge { int u, v, w; Edge(int u, int v, int w) : u(u), v(v), w(w) {} };
// 6k - 2 顶点,3k ^ 2 + 4k - 4 边 inlinevoidgen(int k){ constint INF = 2147483647; constint q = k - 1, n = 6 * k - 2; constint src = 0, dst = 1; int a = 2; constint sb = a, se = (a += k); constint tb = a, te = (a += k); constint ub = a, ue = (a += 2 * q); constint vb = a, ve = (a += 2 * q); std::vector<Edge> edges; for (int s = (sb); s < (se); s++) edges.push_back(Edge(src, s, k)); for (int t = (tb); t < (te); t++) edges.push_back(Edge(t, dst, k)); for (int s = (sb); s < (se); s++) for (int t = (tb); t < (te); t++) edges.push_back(Edge(s, t, 1)); edges.push_back(Edge(src, ub, INF)); edges.push_back(Edge(vb, dst, INF)); for (int u = (ub); u < (ue - 1); u++) edges.push_back(Edge(u, u + 1, INF)); for (int v = (vb); v < (ve - 1); v++) edges.push_back(Edge(v + 1, v, INF)); for (int u = ub + 1; u < ue; u += 4) for (int t = (tb); t < (te); t++) edges.push_back(Edge(u, t, k)); for (int u = ub + 3; u < ue; u += 4) for (int s = (sb); s < (se); s++) edges.push_back(Edge(u, s, k)); for (int v = vb + 1; v < ve; v += 4) for (int s = (sb); s < (se); s++) edges.push_back(Edge(s, v, k)); for (int v = vb + 3; v < ve; v += 4) for (int t = (tb); t < (te); t++) edges.push_back(Edge(t, v, k)); std::cout << n << ' ' << edges.size() << ' ' << src + 1 << ' ' << dst + 1 << '\n'; srand(clock() * time(0)); std::random_shuffle(edges.begin(), edges.end()); for (int i = 0; i < (int)edges.size(); i++) { std::cout << edges[i].u + 1 << ' ' << edges[i].v + 1 << ' ' << edges[i].w << '\n'; } }
intmain(constint argc, constchar *argv[]){ if (argc < 2) { std::cerr << "invalid input!!!"; return0; } int k = atoi(argv[1]); gen(k); return0; }