if (!one) { bool used[N] = {}; int ref[N] = {};//指向此點的邊 queue < int > Q; for (i = 0; i < N; i++) for (j = 0; j < N; j++) if (adjM[i][j]) { used[i] = used[j] = true;//記錄這兩點有被用到 ref[j]++;//指向 j 的點增加 }
for (i = 0; i < N; i++) if (used[i] && !ref[i]) { Q.push(i); break; }
while (!Q.empty()) { int next = Q.front(); Q.pop(); putchar('A' + next); for (i = 0; i < N; i++) if (used[i] && adjM[next][i]) { ref[i]--; if (!ref[i]) Q.push(i); } } } else putchar(str1[0]);