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

×

[closed] 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
40317
accept rate: 12%

closed 26 Aug, 15:53

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

(12 Aug, 23:38) divik5443★

The question has been closed for the following reason "The question is answered, right answer was accepted" by divik544 26 Aug, 15:53


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

5★meooow ♦
5.5k411
accept rate: 47%

awesome thanks it worked!! :)

(13 Aug, 06:34) divik5443★

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:

×317
×82

question asked: 12 Aug, 23:36

question was seen: 159 times

last updated: 26 Aug, 15:53