Language: C++

import std.stdio;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;

int lsb(int x) {
    int c = 0;
    while (x > 0) {
        x >>= 1;
        c++;
    }
    return c;
}

int popcount(int x) {
    int c = 0;
    while (x > 0) {
        if (x & 1) c++;
        x >>= 1;
    }
    return c;
}
 
void main() {
    int N, M;
    int[][] G;
    int[][] S;
    int init;

    bool input() {
        scanf("%d %d\n", &N, &M);
        if (N == 0 && M == 0) return false;
        G = new int[][N];
        S = new int[][N];
        foreach (i; 0 .. M) {
            int s, t; scanf("%d %d\n", &s, &t);
            s--; t--;
            G[s] ~= t;
            G[t] ~= s;
        }
        foreach (i; 0 .. N) {
            G[i] = G[i].sort;
        }
        init = 0;
        foreach (i; 0 .. N) {
            int s; scanf("%d", &s);
            init |= (s << i);
        }
        foreach (i; 0 .. N) {
            int k; scanf("%d\n", &k);
            foreach (j; 0 .. k) {
                int r; scanf("%d", &r);
                r--;
                S[i] ~= r;
            }
            S[i] = S[i].sort;
        }
        return true;
    }

    void solve() {
        if (! (init & 1)) {
            writeln("Help me!");
            return;
        }
        struct P {
            int v, bit;
        }
        const X = P(-1, -1);
        auto prev = new P[][](N, 1 << N);
        bool bfs() {
            foreach (i; 0 .. N) prev[i][] = X;
            DList!P Q;
            Q.insert(P(0, init));
            while (!Q.empty) {
                P p = Q.front; Q.removeFront;
                if (p.v == N - 1 && p.bit == (1 << (N - 1))) {
                    return true;
                }
                foreach (v; S[p.v]) {
                    int bit;
                    if (p.bit & (1 << v)) {
                        bit = p.bit - (1 << v);
                    } else {
                        bit = p.bit + (1 << v);
                    }
                    if (prev[p.v][bit] != X) continue;
                    prev[p.v][bit] = p;
                    Q.insert(P(p.v, bit));
                }
                foreach (v; G[p.v]) {
                    if (prev[v][p.bit] != X) continue;
                    if (p.bit & (1 << v)) {
                        prev[v][p.bit] = p;
                        Q.insert(P(v, p.bit));
                    }
                }
            }
            return false;
        }
        if (bfs) {
            int v = N - 1, bit = 1 << (N - 1);
            string[] path;
            while (v != 0 || bit != init) {
                int v1 = prev[v][bit].v;
                int bit1 = prev[v][bit].bit;
                if (v == v1) {
                    assert(popcount(bit ^ bit1) == 1);
                    string fstr = "Switch " ~ (bit > bit1 ? "on" : "off") ~ " room %d.";
                    path ~= format(fstr, lsb(bit ^ prev[v][bit].bit));
                } else {
                    path ~= format("Move to room %d.", v + 1);
                }
                //writefln("%d %b -> %d %b", v1, bit1, v, bit);
                v = v1;
                bit = bit1;
            }
            writefln("You can go home in %d steps.", path.length);
            path.reverse;
            foreach (p; path) {
                writeln(p);
            }
        } else {
            bool r() {
                foreach (i; 0 .. (1 << N)) {
                    if (prev[N - 1][i] != X) {
                        return true;
                    }
                }
                return false;
            }
            writeln( r ? "You can not switch off all lights." : "Help me!" );
        }
    }

    while (input) {
        solve;
    }
}

Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import std.stdio;
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:2:1: error: 'import' does not name a type
    2 | import std.c.stdio;
      | ^~~~~~
a.cc:2:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:3:1: error: 'import' does not name a type
    3 | import std.range;
      | ^~~~~~
a.cc:3:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:4:1: error: 'import' does not name a type
    4 | import std.array;
      | ^~~~~~
a.cc:4:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:5:1: error: 'import' does not name a type
    5 | import std.functional;
      | ^~~~~~
a.cc:5:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:6:1: error: 'import' does not name a type
    6 | import std.algorithm;
      | ^~~~~~
a.cc:6:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:7:1: error: 'import' does not name a type
    7 | import std.conv;
      | ^~~~~~
a.cc:7:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:8:1: error: 'import' does not name a type
    8 | import std.container;
      | ^~~~~~
a.cc:8:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:9:1: error: 'import' does not name a type
    9 | import std.math;
      | ^~~~~~
a.cc:9:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:10:1: error: 'import' does not name a type
   10 | import std.numeric;
      | ^~~~~~
a.cc:10:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:11:1: error: 'import' does not name a type
   11 | import std.string;
      | ^~~~~~
a.cc:11:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:12:1: error: 'import' does not name a type
   12 | import std.c.string;
      | ^~~~~~
a.cc:12:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:13:1: error: 'import' does not name a type
   13 | import std.regex;
      | ^~~~~~
a.cc:13:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:14:1: error: 'import' does not name a type
   14 | import std.typecons;
      | ^~~~~~
a.cc:14:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:34:1: error: '::main' must return 'int'
   34 | void main() {
      | ^~~~
a.cc: In function 'int main()':
a.cc:36:8: error: structured binding declaration cannot have type 'int'
   36 |     int[][] G;
      |        ^~
a.cc:36:8: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
a.cc:36:8: error: empty structured binding declaration
a.cc:36:10: error: expected initializer before '[' token
   36 |     int[][] G;
      |          ^
a.cc:37:8: error: structured binding declaration cannot have type 'int'
   37 |     int[][] S;
      |        ^~
a.cc:37:8: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
a.cc:37:8: error: empty structured binding declaration
a.cc:37:10: error: expected initializer before '[' token
   37 |     int[][] S;
      |          ^
a.cc:40:15: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
   40 |     bool input() {
      |               ^~
a.cc:40:15: note: remove parentheses to default-initialize a variable
   40 |     bool input() {
      |               ^~
      |               --
a.cc:40:15: note: or replace parentheses with braces to value-initialize a variable
a.cc:40:18: error: a function-definition is not allowed here before '{' token
   40 |     bool input() {
      |                  ^
a.cc:71:18: error: a function-definition is not allowed here before '{' token
   71 |     void solve() {
      |                  ^
a.cc:146:12: error: 'input' was not declared in this scope
  146 |     while (input) {
      |            ^~~~~
a.cc:147:9: error: 'solve' was not declared in this scope
  147 |         solve;
      |         ^~~~~