Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

奇怪了 怎么老是奇奇怪怪的WA RE。。。过了的看看

Posted by alpc12 at 2007-01-18 06:19:10 on Problem 2230
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator