Squawk Virus
InterviewTime limit1sMemory limit256 MB
Starting from user s, propagate squawk counts along links for t minutes and report how many squawks are sent at time t.
- Level
Easy3 of 10
- Topics
- Dynamic programming, Graph
- Solved
- No attempts yet
Problem
The social networking site Twitface is under attack by a virus. The virus spreads from user to user and floods the network with traffic. Users normally send messages to each other by hand, and such a message is called a squawk, but an infected squawk copies itself with no user action.
A user who receives an infected squawk sends one infected squawk to every neighbor in the network exactly one minute later. If a user receives several squawks at the same moment, one minute later it sends that many squawks to each of its neighbors.
Consider the network below. User 0 is linked to users 1 and 3, and user 2 is linked to users 1, 3 and 4.

If user 0 is infected at time , then at users 1 and 3 receive one squawk each, at users 0 and 2 receive two squawks each, and at users 1 and 3 receive four squawks each while user 4 receives two. The number of squawks sent at times 1, 2 and 3 is 2, 4 and 10.
You are given the layout of the network and the first infected user. Find how many squawks are sent at time . At , count the single squawk that infected user .
Input
The first line has four integers , , , : the number of users (), the number of links between users (), the index of the first infected user (), and the elapsed time in minutes ().
Each of the next lines has two integers and (), meaning that users and are linked. Links work in both directions, and no link is given twice.
Output
Print the number of squawks sent at time .