1 / 2
Feb 2013

My code gets WA but I don't know why

/*
 * main.cpp
 *
 *  Created on: Feb 20, 2013
 *      Author: Sony
 */
#include <iostream>
#include <vector>
using namespace std;
vector<vector<int> > all ;
bool vis[10001];
bool DFS(int cur){
	//cout << cur << endl ;
	if(vis[cur] == 1)
		return 0 ;
	vis[cur] = 1;
	for (int i = 0; i < all[cur].size(); ++i) {
		DFS(all[cur][i]);
	}
	return 1 ;
}
int main(){
	memset(vis,0,sizeof(vis));
	int m,n ;
	scanf("%d%d",&m,&n);
	all.resize(m);
	int a,b;
	for (int i = 0; i < n; ++i) {
		scanf("%d%d",&a,&b);
		all[a-1].push_back(b-1);
	}
	if(m != n-1)
		printf("NO\n");
	return 0;
	bool answer = DFS(0);
	for (int i = 0; i < all.size(); ++i) {
		if(vis[i]==0)
			answer = 0 ;
	}
	if(answer==0)
		printf("NO\n");
	else
		printf("YES\n");
	return 0;
}
  • created

    Feb '13
  • last reply

    Feb '13
  • 1

    reply

  • 157

    views

  • 2

    users

It returns the wrong answer for the sample input. You appear to have m and n mixed up.