You are not logged in. Please login at www.codechef.com to post your questions!

×

Feasible Relations

Feasible Relations

Solution Link

I have used Union-find data structure and the basic idea is to first process all queries having '=' and then processing all queries with "!=". I am getting SIGSEGV error For 4 out of 7 testcases could anybody tell where am i going wrong???

asked 12 Aug, 23:36

divik544's gravatar image

3★divik544
2526
accept rate: 6%

i am unaware about the oop memory related concepts in c++ so is it due to them

(12 Aug, 23:38) divik5443★

Your approach is correct. The problem lies in the if block on line 75

if(uf.root(a)==uf.root(b))
{
    ans="NO";
    break;
}

When this condition is triggered you are breaking out the loop where you are taking input. So you're moving onto the next test case without completely reading the inputs of the current test case. This naturally causes the actual leftover input to differ from the expected format which results in runtime error.

Just remove the if block and your code runs fine, since you are checking all "!=" cases later anyway from the qu vector! :)

link

answered 13 Aug, 00:22

meooow's gravatar image

6★meooow
3.7k38
accept rate: 49%

awesome thanks it worked!! :)

(13 Aug, 06:34) divik5443★
toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×281
×70

question asked: 12 Aug, 23:36

question was seen: 63 times

last updated: 13 Aug, 06:34