CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • All Contests
    • June Long 2012
    • May Cook-Off
    • May Long 2012
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » February 2010 Contest » Toll Trolls

Toll Trolls

Problem code: M4

  • All Submissions

All submissions for this problem are available.

The problem statement has been updated.

Johnny has gone on a short excursion to the island of Bitland, and found himself with plenty of time to spare for sight-seeing. As a matter of fact, he does really have any itinerary at hand. All he would like to do is to walk around a bit, without spending too much money in the process.

The cities of Bitland are connected by a network of one way streets. If there exists a road leading directly from city A to city B, then there also exists a road directly from city B to city A. There maybe any number (possibly zero) of parallel roads between any two cities. However, it is possible to reach any city starting from any other city (possibly indirectly, going through other cities on the way).

Now, the trouble is that all of the roads in Bitland are privately owned, and toll trolls have been hired to guard them and collect the dues. What's worse, the trolls are moody and will in some circumstances change the sum of the toll charged for using a road...

Johnny starts his sight-seeing tour from the capital of Bitland. He always leaves each city by the cheapest outgoing road, i.e. the one which currently has the lowest toll. However, as soon as Johnny has used the road from A to B, the toll troll in charge of it increases the toll for the road, setting it at exactly 1 Bitlandian dinar more than the toll currently being charged on the most expensive of the roads leaving city A.

Johnny has been walking around the towns of Bitland for a while, and he is getting a little bored. Help him answer the following question: what is the toll he is going to pay when traversing the k-th road of his tour?

Input

The first line of input contains two integers: n, the number of towns in Bitland and m, the number of pairs of roads connecting them (1 <= n <= 105, 0<= m <=105). Each of the m-th following lines contains four integers A B cAB cBA, denoting the identifier of city A, the identifier of city B, the initial toll on the road from A to B, and the initial toll on the road from B to A (1 <= A < B<= n, 1 <= cAB, cBA <= 109). All tolls are expressed in dinars. You may assume that the initial toll values for all of the roads are different, and that the city labeled 1 is the capital of Bitland.

The next line of input contains the number t of queries asked by Johnny, t <= 104. Each of the following t lines contains a single integer k (1 <= k <= 1012).

Output

For each of the values of k given at input, print a line containing the toll paid by Johnny when traversing the k-th road along his route.

Example

Input:
3 2
1 2 5 10
1 3 11 7
4
1
2
3
5

Output:
5
10
11
12


Author: admin
Date Added: 15-01-2010
Time Limit: 1 - 3 sec
Source Limit: 50000 Bytes
Languages: ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, ERL, F#, FORT, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TEXT, WSPC


  • Submit

Comments

  • Login or Register to post a comment.

The input specification says

pieguy @ 2 Feb 2010 12:30 PM

The input specification says 1<=n and 0<=m, but how can poor Johnny go anywhere if there are no roads?

he can't, so anserw is  0

Chotkos @ 2 Feb 2010 03:23 PM

he can't, so anserw is  0

Why 0? He doesn't pay a toll

triplem @ 2 Feb 2010 03:44 PM

Why 0? He doesn't pay a toll of 0. The toll is nonexistent, so the output is unspecified.

The problem statement states

Brian Drake @ 2 Feb 2010 03:46 PM

The problem statement states that "... it is possible to reach any city starting from any other city (possibly indirectly, going through other cities on the way)". Therefore, if there are no roads, then there must be only one city, and then "poor Johnny" will indeed be unable to go anywhere. The way I see it, in this case, the input would be invalid unless t = 0.

At least one test case seems

gmark @ 3 Feb 2010 01:11 PM

At least one test case seems to have repeated edges between vertices. According to the problem statement this is not allowed. Please check.

@Mark On what basis do you

Brian Drake @ 3 Feb 2010 01:34 PM

@Mark On what basis do you claim that there seem to be repeated edges?

@Brian On the basis that my

gmark @ 3 Feb 2010 02:04 PM

@Brian On the basis that my solution fails with an assertion error if I make a test for repeated edges, and otherwise gets wrong answer.

I request the CodeChef team

balajiganapath @ 3 Feb 2010 05:57 PM

I request the CodeChef team to check the test cases as suggested above

Checking.

i0exception @ 3 Feb 2010 06:17 PM

Checking.

Also, m will not be 0.

i0exception @ 3 Feb 2010 06:17 PM

Also, m will not be 0.

guys is thr a probem with the

ramthegreatcv @ 4 Feb 2010 01:28 AM

guys is thr a probem with the test cases? or is thr some spl case i am missing ??

My program is giving the same output as my bruteforce solution in all my test cases. Pls give some comments

I am having the same

balajiganapath @ 4 Feb 2010 07:32 AM

I am having the same problem.

Also Mark has said above that the test cases have repeated edges which is invalid.

Statement updated. Sorry for

i0exception @ 4 Feb 2010 04:03 PM

Statement updated. Sorry for the inconvenience.

""There maybe any number

sumitb @ 4 Feb 2010 10:46 PM

""There maybe any number (possibly zero) of parallel roads between any two cities.""

What does the updated statement signifies?

Is it means that input can be in the form of:

1 2 5 10

1 2 10 2

Please comment

Yes.

triplem @ 5 Feb 2010 01:59 AM

Yes.

Will the k queries in the end

shrikant169 @ 5 Feb 2010 04:48 PM

Will the k queries in the end always be in ascending order as in the test problem??

@Shrikant You can test that

Brian Drake @ 5 Feb 2010 05:08 PM

@Shrikant You can test that yourself. Submit a program that does nothing but read the input and check whether the queries are in ascending order, then depending on whether or not they are, either make the program crash (e.g. by dividing by zero) (so the judge will say Run-time Error) or exit normally (so the judge will say Wrong Answer).

Does anyone really trust the problem statements in this contest anymore?

It would still be good to get an answer from the admin/problem setter but don't count on it.

@Admin Will the k queries in

pankaj22 @ 5 Feb 2010 05:12 PM

@Admin

Will the k queries in the end always be in ascending order as in the test problem??

IMPORTANT : The time limit

admin @ 5 Feb 2010 06:40 PM

IMPORTANT :

The time limit for this problem has been increased for some of the test cases as we felt that it was too strict. A rejudge is in progress.

@Brian, @pankaj The input is

admin @ 5 Feb 2010 06:41 PM

@Brian, @pankaj The input is exactly as specified in the problem statement. Don't make assumptions about anything else.

This is hilarious.  I submit

pieguy @ 6 Feb 2010 01:41 AM

This is hilarious.  I submit on Overlapping disks.  Time limit exceeded.  A few hours later the time limit is increased and I pass the rejudge.  I submit this problem.  Time limit exceeded.  A few hours later the exact same thing happens.  I wonder what will happen on Motorbike Racing...

I strongly feel they would

sppraveen @ 6 Feb 2010 01:57 AM

I strongly feel they would increase motorbike racing also! I dont think they have checked the data enough before the contest. May be if pieguy submits a solution for motorbike racing and if he gets TLE , admin would increase time.

Which is why I wait until the

tomek @ 6 Feb 2010 02:27 AM

Which is why I wait until the constraints settle in the middle of the contest.

Nice tomek! I have seen many

sppraveen @ 6 Feb 2010 02:59 AM

Nice tomek! I have seen many top participants doing that and it makes perfect sense.

I am getting WA and I am

pankaj22 @ 7 Feb 2010 08:54 AM

I am getting WA and I am officially frustrated now. Could someone please confirm whether while judging, in the input, there would be only one such network of roads or can it be more than one i.e. will there be only one test case or multiple test cases in one file?

I can't think of any other reason why I am getting WA :-(

The input section makes this

triplem @ 7 Feb 2010 09:20 AM

The input section makes this clear.

What is the current time

tmzani @ 10 Feb 2010 07:27 AM

What is the current time limit? It says 2 seconds however I've seem successful submissions with more 3 seconds.

"He always leaves each city

tmzani @ 10 Feb 2010 07:30 AM

"He always leaves each city by the cheapest outgoing road, i.e. the one which currently has the lowest toll."

What happen if two roads have the lowest same price? The decision may affect the final answer.

Read the FAQ. And the problem

triplem @ 10 Feb 2010 07:47 AM

Read the FAQ. And the problem statement.

m newbie hereits my first

anant4coding @ 10 Feb 2010 04:48 PM

m newbie here

its my first time

can u please tell me how to take input

whether as .txt file or somhw else???

@Admin   Can you please check

kunaljain @ 10 Feb 2010 07:26 PM

@Admin

 

Can you please check why my every runtime is shown as RUNTIME ERROR( Other ) ?
Even if it has only

assert(false);

 

like in submission 185616

@Thiago The time limit is 2

Brian Drake @ 11 Feb 2010 01:20 PM

@Thiago The time limit is 2 seconds per file; the time shown for a submission is the total time for all files that were processed (the remaining files will not be processed if there is a runtime error or the submission exceeds the time limit). However, the admin did say above that the time limit for some test cases was increased.

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold
CodeChef is a global programming communityCodeChef hosts online programming competitions
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming challenges that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out other programmers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting the CodeChef Forums and Wiki section.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. You can also host a coding contest for your institute on CodeChef, organize an algorithm event and be a guest author on our blog.

Go For Gold

The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com