题目
[样例输入]
4
0 1 1
1 1 3
2 0
3 1 2
[样例输出]
0 1 8
1 2 7
2 4 5
3 3 6
代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| #include<stdio.h> #include<vector> using namespace std;
int n, m, v, e, i; vector<int> NUMS[50]; int d[50], f[50]; int time = 1; int start, ends;
void DFS(int start){ d[start] = time++; for(auto k : NUMS[start]){ if(d[k] == 0){ DFS(k); } } f[start] = time++; }
int main(void){ scanf("%d", &n); for(v = 0; v < n; v++){ scanf("%d %d", &start, &m); for(e = 0; e < m; e++){ scanf("%d", &ends); NUMS[start].push_back(ends); } }
for(i = 0; i < n; i++){ if(d[i] == 0){ DFS(i); } }
for(i = 0; i < n; i++){ printf("%d %d %d", i, d[i], f[i]); printf("\n"); } return 0; }
|