infection

Time limit: 4s Memory limit: 1024MB Input: Output:

Athena is a grown-up now and is already one of the VIP (Very Important Party-goer)- s in the country of Slopia. As Slopia has had very efficient designers, the country has NN cities connected with N1N-1 bidirectional roads (Uj,Vj)(U_j,V_j) between them, such that it’s possible to travel between any 22 cities using only the roads.

However, last month the government in Slopia found out that there is a highly contagious infection going around and is now concerned with the well-being of the VIP-s. To that end, the government tracked down the precise plans of all MM party-goers: the day (since the beginning of the universe) they will start partying DiD_i, the city SiS_i they will start in, and the city TiT_i they will end in.

Since the trendy way to party is to party in a different city every night, each partygoer ii will arrive in Slopia on the evening of day DiD_i in city SiS_i and party there that night, then they will continue by going from city to city, travelling one road per day, following the shortest path to TiT_i and attending one party every night in the city they are currently at. After partying in TiT_i, they will take a flight out of Slopia on the next morning and this will end their party-tour.

Additionally the Slopia government has acquired information about whether each party-goer had the infection at the beginning of their party-tour, denoted by IiI_i. Since parties are a very social endeavour, if someone has the infection at a party in some city, everyone else who is partying in the same city on the same night gets the infection. Since the infection has no cure yet, each infected person stays infected throughout the remainder of their party-tour.

The Slopia government wants to calculate how many nights each party-goer will spend infected during their party-tour. It is up to you to help them by implementing an efficient solution to this problem.

Implementation details

You have to implement the function solve:

std::vector<int> solve(
	std::vector<std::pair<int, int>> R,
	std::vector<long long> D,
	std::vector<int> S,
	std::vector<int> T,
	std::vector<bool> I,
);
  • RR: vector of N1N-1 pairs of integers – the 22 cities UjU_j and VjV_j connected by road jj;
  • DD: vector of MM integers – the start day of party-goer ii;
  • SS: vector of MM integers – the start city of party-goer ii;
  • TT: vector of MM integers – the final city of party-goer ii;
  • II: vector of MM booleans – the initial infection status of party-goer ii, denoted as a boolean with 11 meaning infected and 00 meaning non-infected.

This function will be called once per test and must return a vector of MM integers – the number of nights party-goer ii will spend infected.

Constraints and clarifications

  • 1N,M150 0001 \leq N,M \leq 150 \ 000
  • 0Di10120 \leq D_i \leq 10^{12}
  • 0Uj,Vj,Si,Ti<N0 \leq U_j, V_j, S_i, T_i < N
  • Ii{0,1}I_i \in \{0, 1\}
Subtask Points Required subtasks N,MN,M Other constraints
0 0 - - Sample test.
1 5 - 100\leq 100 Di=0D_i = 0
2 6 1 5 000\leq 5 \ 000 Di=0D_i = 0
3 7 0-2 5 000\leq 5 \ 000 -
4 5 - 150 000\leq 150 \ 000 Di=106iD_i = 10^6 \cdot i
5 20 - 150 000\leq 150 \ 000 (Uj,Vj)=(j,j+1),Di=0(U_j, V_j) = (j, j+1), D_i = 0
6 19 5 150 000\leq 150 \ 000 (Uj,Vj)=(j,j+1)(U_j, V_j) = (j, j+1)
7 18 0-3 100 000\leq 100 \ 000 -
8 20 0-7 150 000\leq 150 \ 000 -

Example

stdin

9 5
0 1
1 2
2 3
3 4
4 5
3 6
6 7
6 8
1 0 5 1
3 5 7 0
4 5 7 0
8 7 8 0
10 0 1 0

stdout

6
0
4
3
0

Explanation

Slopia infrastructure:

The party-routes of all VIP-s are shown in the following table, where the days on which each person had the infection are in bold.

- 0 1 2 3 4
0 - - - - -
1 0 - - - -
2 1 - - - -
3 2 5 - - -
4 3 4 5 - -
5 4 3 4 - -
6 5 6 3 - -
7 - 7 6 - -
8 - - 7 7 -
9 - - - 6 -
10 - - - 8 0
11 - - - - 1

Sample grader

Input format:

  • N MN \ M
  • U0 V0U_0 \ V_0
  • U1 V1U_1 \ V_1
  • ...
  • UN2 VN2U_{N-2} \ V_{N-2}
  • D0 S0 T0 I0D_0 \ S_0 \ T_0 \ I_0
  • ...
  • DM1 SM1 TM1 IM1D_{M-1} \ S_{M-1} \ T_{M-1} \ I_{M-1}

Output format:

  • Ans0Ans_0
  • Ans1Ans_1
  • ...
  • AnsM1Ans_{M-1}

Log in or sign up to be able to send submissions!