3
int catMouseGame(vector<vector<int>> &graph) {5
vector<vector<int>> dp[2];6
vector<vector<int>> outdegree[2];7
queue<vector<int>> q; // q of {turn, mouse position, cat position} for topological sort9
dp[0] = vector<vector<int>>(N, vector<int>(N));10
dp[1] = vector<vector<int>>(N, vector<int>(N));11
outdegree[0] = vector<vector<int>>(N, vector<int>(N));12
outdegree[1] = vector<vector<int>>(N, vector<int>(N));15
for (int j = 0; j < N; ++j) {16
dp[0][0][j] = dp[1][0][j] = 1;20
for (int j = 1; j < N; ++j) {21
dp[0][j][j] = dp[1][j][j] = 2;26
for (int i = 0; i < N; ++i) {27
for (int j = 1; j < N; ++j) {28
outdegree[0][i][j] = graph[i].size();29
outdegree[1][i][j] = graph[j].size();32
for (auto &v : graph[0]) {33
for (int i = 0; i < N; ++i) {37
// run the topological sort from queue39
auto turn = q.front()[0];40
auto mouse = q.front()[1];41
auto cat = q.front()[2];44
if (turn == 0 && mouse == 1 && cat == 2) {45
// the result has been inferenced49
if (turn == 0) { // mouse's turn50
// v is the prev position of cat51
for (auto &v : graph[cat]) {56
if (dp[1][mouse][v] > 0) {60
if (dp[turn][mouse][cat] == 2) {61
// cat wants to move from v to `cat` position, and thus cat wins63
q.push({1, mouse, v});67
outdegree[1][mouse][v]--;68
if (outdegree[1][mouse][v] == 0) {70
q.push({1, mouse, v});73
} else { // cat's turn74
// v is the prev position of mouse75
for (auto &v : graph[mouse]) {76
if (dp[0][v][cat] > 0) {80
if (dp[turn][mouse][cat] == 1) {81
// mouse wants to move from v to `mouse` position and thus mouse88
outdegree[0][v][cat]--;89
if (outdegree[0][v][cat] == 0) {