Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
奇怪了 怎么老是奇奇怪怪的WA RE。。。过了的看看#include <stdio.h> #include <memory.h> const int N = 10010; const int M = 50010; struct Edge{int jj;Edge * next;bool vst;}e[M]; Edge * head[N]; void DFS(int x) { Edge * p = head[x]; while(p != NULL) { if(p->vst == 0) { p->vst = 1; DFS(p->jj); } p = p->next; } printf("%d\n", x+1); //放在遍历前面亦可 } int main() { int n, m, i, u, v, t = 0; scanf("%d %d", &n, &m); memset(head, 0, n*sizeof(Edge*) ); for(i = 0; i < m; i++) { scanf("%d %d", &u, &v); --u; --v; e[t].jj = v; e[t].next = head[u]; e[t].vst = 0; head[u] = &e[t++]; e[t].jj = u; e[t].next = head[v]; e[t].vst = 0; head[v] = &e[t++]; } DFS(0); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator