2010 Canadian Computing Competition, Stage 2
Day 1, Problem 1: Barking Dogs!
You live in a neighbourhood of dogs. Dogs like dogs. Dogs like barking even better. But best of all, dogs like barking when other dogs bark.
Each dog has a collection of dogs that can hear him/her. Each dog has a delay time in barking if they hear another dog bark.
Dog 1 always starts barking first, and this first bark occurs during second number 0.
Your job is to figure out how many times each dog has barked in the first T seconds (inclusive). You can assume that sound travels instantly from the mouth of one dog into the ear of another.
Each dog spends any given second doing one of three things: sleeping, waiting, or barking. If dog i hears a bark during second n when it is sleeping, the dog wakes up and waits during seconds n + 1 through n + wi − 1 inclusive, barks during second n + wi, then goes back to sleep from second n + wi + 1 onward. If a dog hears a bark during a second in which it is waiting or barking, it ignores the bark.
During second number 0, all the dogs except Dog 1 are sleeping.
The first line of input is D (1 ≤ D ≤ 1000), the number of dogs in the neighbourhood.
The next D lines each contain an integer wi (1 ≤ wi ≤ 1000) representing the time (in seconds) that dog i waits before barking upon hearing a bark.
The next line contains the number F (1 ≤ F < 10000). On each of the next F lines, there are two integers: i and j, representing that when dog i barks, dog j hears this bark. It is never the case that i = j.
The next line (which is the last line of input) contains the integer T (1 ≤ T ≤ 1000), the number of seconds during which your program is to monitor the dogs.
Produce one line of output for each dog in order from dog 1 to dog D. On line i, output the number of seconds between 0 and T inclusive that dog i spent barking.
Sample Input 1
3 1 1 3 3 1 2 2 3 3 1 10
Sample Output 1
3 2 2
Sample Input 2
3 3 1 3 3 1 2 2 3 3 1 10
Sample Output 2
2 2 1
Point Value: 10
Time Limit: 2.00s
Memory Limit: 256M
Added: May 19, 2010
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3