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

×

How to solve Spoj TOPOSORT problem?

Please tell me - How to solve Spoj TOPOSORT problem? I have tried to solve this but getting wrong at 12 number case.

My code.

asked 31 May '17, 03:06

rashedcs's gravatar image

2★rashedcs
49751755
accept rate: 4%

edited 31 May '17, 03:33


I have just solved this problem and was getting the same problem. The reason is that the question states -

If there is a solution print the correct ordering, the jobs to be done separated by a whitespace. If there are multiple solutions print the one, whose first number is smallest, if there are still multiple solutions, print the one whose second number is smallest, and so on.

To achieve this, you should use std::set instead of std::queue because then the vertices will always be taken in sorted order for processing and the goal of question will be achieved.

Also use scanf/printf as cin/cout will give you a TLE (just as it has given me).

The link to my solution (if you want to refer) is - http://ideone.com/l3Ynrz

Hope this helps.

link

answered 31 May '17, 09:23

prj18's gravatar image

3★prj18
561
accept rate: 50%

I have used same method as @prj18 but still getting TLE after test case #12 Link to code -> https://notepad.pw/dushyant7917-topsort

link

answered 18 Oct '17, 12:07

dushyant7917's gravatar image

5★dushyant7917
716
accept rate: 0%

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:

×1,217

question asked: 31 May '17, 03:06

question was seen: 624 times

last updated: 18 Oct '17, 12:07