******************************* *** The hack uses generator *** ******************************* ** Command line arguments ** 100000 11 1 1 ** Generated test ** ** Generator source ** #include #include #include #include #include #include using namespace std; const int MAXN = 1000005, RANDOM = 0, LONG = 1, SHORT = 2; int N, W, MAXW, P, TYPE, nlist [MAXN]; pair edges [MAXN]; char line [1000]; int main (int argc, char **argv) { // int _seed; srand (time (NULL) * (long long) &_seed); srand (1); FILE *out = fopen (argc > 1 ? argv [1] : "tree.txt", "w"); printf ("N, max weight, type, prob\n"); fgets (line, sizeof (line), stdin); int scan = sscanf (line, "%d %d %d %d", &N, &MAXW, &TYPE, &P); if (scan <= 2) TYPE = RANDOM; if (scan == 3) { P = TYPE; TYPE = MAXW; } for (int i = 0; i < N; i++) nlist [i] = i; random_shuffle (nlist, nlist + N); for (int i = 1; i < N; i++) { int parent = -1; if (TYPE == RANDOM) parent = nlist [rand () % i]; if (TYPE == LONG) { for (int j = i - 1; j >= 0 && parent == -1; j--) if (j == 0 || rand () % 100 < P) parent = nlist [j]; } else if (TYPE == SHORT) { for (int j = 0; j < i && parent == -1; j++) if (j == i - 1 || rand () % 100 < P) parent = nlist [j]; } edges [i] = make_pair (nlist [i], parent); if (rand () & 1) swap (edges [i].first, edges [i].second); } random_shuffle (edges + 1, edges + N); fprintf (out, "%d\n", N); for (int i = 1; i < N; i++) if (scan == 1 || scan == 3) fprintf (out, "%d %d\n", edges [i].first + 1, edges [i].second + 1); else fprintf (out, "%d %d %d\n", edges [i].first + 1, edges [i].second + 1, rand () % MAXW + 1); return 0; }