#include <stdio.h> #include <string.h> int n, d[101][101], v[101]; void find(int now) { int i; for (i = 1; i <= n; i++) if (d[now][i] && !v[i]) { v[i] = 1; find(i); } } int main() { while (scanf("%d", &n) && n) { int i, j; memset(d, 0, sizeof(d)); while (scanf("%d", &i) && i) while (scanf("%d", &j) && j) d[i][j] = 1; scanf("%d", &i); while (i--) { scanf("%d", &j); memset(v, 0, sizeof(v)); find(j); int cnt = 0; for (j = 1; j <= n; j++) cnt += !v[j]; printf("%d", cnt); for (j = 1; j <= n; j++) if (!v[j]) printf(" %d", j); puts(""); } } return 0; }
Hello, I am a CS student from Taiwan.
I am learing English and Programming.
I'll save source code of some problems or small programs without comments in this blog.
I would recommend you not to read solution from others before you solved the problem.
(這邊專門存放沒有任何註解的小程式/OJ題目程式碼)
2013年3月28日
UVa 280 - Vertex
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言