Error in C++ code logic -


i given graph consisting of n nodes , m edges. pair of nodes u, v called if , if can go node u v , return v u without using edge more once. need add @ 1 edge graph make pairs of nodes good. added edge can between 2 vertices connected edges. not allowed add self loops (edge node n node n). guaranteed graph connected.

input
n , m in first line. each of next m lines contains 2 space separated integers x , y, denoting there edge between node x , y.

output
output "yes" (without quotes) if possible make pairs of node adding @ 1 edge. output "no" (without quotes) otherwise.

example`

input: 4 4 3 2 1 3 2 1 1 4 output: yes 

my logic: count edges not create cycle end. eg: edge(1,4) in above example. this, count instances of particular node in input , if equal 1, particular node end. if have more 2 ends, answer "no".

my code:

#include <cstdio> #include <iostream> using namespace std;  int main() {      int n,m,num[100010] = {0},temp1,temp2,i,ctr = 0; //array range correct     scanf("%d%d",&n,&m);     while(m--) //taking nodes     {         scanf("%d%d",&temp1, &temp2); //node positions inputted         num[temp1]++; //counting node instances         num[temp2]++; //^^     }     for(i=1;i<=n;i++)     {            if(num[i] == 1) //if node instances 1, end node         ctr++;          //in case, increment counter.     }     if(n==1 || m==0 || ctr>2)         printf("no\n");     else         printf("yes\n");     return 0; }  

on submitting this, incorrect answer. there fault in logic or missing testcases?


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -