Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Author: Sergey Kopeliovich (Burunduk30@gmail.com)
- * Случайное блуждание от случайной точки на глубину 10n
- * Score: 96
- */
- #include <cstdio>
- #include <cstdlib>
- #include <cassert>
- #define forn(i, n) for (int i = 0; i < (int)(n); i++)
- const int N = 200;
- const int M = N * N;
- int n, m, x[N], ind[M][3], e[M][3];
- int main() {
- assert(scanf("%d%d", &n, &m) == 2 && n <= N && m <= M);
- forn(i, m)
- forn(j, 3)
- scanf("%d%d", &ind[i][j], &e[i][j]), ind[i][j]--;
- for (int cnt = 0;; cnt++) {
- forn(i, n)
- x[i] = rand() % 2;
- forn(_, 10 * n) {
- int bad = 0;
- forn(j, m) {
- int good = (x[ind[j][0]] == e[j][0] || x[ind[j][1]] == e[j][1] || x[ind[j][2]] == e[j][2]);
- if (!good) {
- int t = rand() % 3;
- bad = 1, x[ind[j][t]] = e[j][t];
- }
- }
- if (!bad) {
- forn(i, n)
- putchar('0' + x[i]);
- fprintf(stderr, "cnt = %d\n", cnt);
- return 0;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement