Aggressive Traveller

아직 제출이 없습니다시간 제한2초메모리 제한512 MB

문제

You are very eager to travel to many countries. There are NN countries in the world. MM distinct pairs of the countries have a travel route between the two countries. All the MM routes are one-way: if there is a route from AA to BB, you can move from country AA to country BB, but not from BB to AA unless there is another route from BB to AA. Now you are in country SS and set the goal of your travel to country TT. From SS to TT, you want to visit the countries as many times as possible.

However, there are some restrictions. There are KK countries which have strict security checks before you enter these countries. The flow of the security check of the ii-th restricted country c_ic\_i is as follows:

  1. You show your passport to an officer.

  2. The officer checks your passport. If at least one of the following two conditions is satisfied, your entrance is rejected:

    1. Your passport has two or more stamps of the same country.
    2. Your passport has more than r_ir\_i stamps.
  3. Otherwise your entrance is accepted. The officer stamps your passport with a stamp of country c_ic\_i.

  4. You enter the country c_ic\_i.

Note that in NKN-K countries other than KK restricted countries, passport checking is skipped so you can freely enter these countries but you must get a stamp of a country you enter. Also notice that you may be able to enter c_ic\_i at most twice, because you get a stamp after passport checking. Initially your passport has only a single stamp of country SS.

As an aggressive traveller, you want to maximize the number of stamps on your passport. You are going to start your travel from country SS and eventually finish the travel at country TT. Write a program that outputs the maximum number of stamps you can get on your passport when you reach TT. This number includes the stamps of countries SS and TT. If you cannot reach TT from SS, output 'UNREACHABLE' instead. Also, if you can indefinitely repeat to visit countries and then eventually reach TT, output 'INFINITY' instead. Note that you don't have to stop your travel when reaching TT and can visit TT multiple times.

입력

The input consists of a single test case in the format below.

NN MM KK SS TT

u_1u\_1 v_1v\_1

\vdots

u_Mu\_M v_Mv\_M

c_1c\_1 r_1r\_1

\vdots

c_Kc\_K r_Kr\_K

The first line contains five integers NN (3N1,0003 \le N \le 1,000), MM (2M10,0002 \le M \le 10,000), KK (1KN1 \le K \le N), SS (1SN1 \le S \le N), TT (1TN1 \le T \le N). NN is the number of countries. MM is the number of routes between pairs of countries. KK is the number of restricted countries. SS and TT are the countries you start your travel from and want to reach, respectively. The ii-th of following MM lines is the information of the ii-th route: you can move from countries u_iu\_i to country v_iv\_i (1u_i,v_iN1 \le u\_i, v\_i \le N). The jj-th of further following KK lines is the information of the jj-th restricted country: country c_jc\_j (1c_jN1 \le c\_j \le N) has the limit r_jr\_j (1r_j51 \le r\_j \le 5) of the number of stamps on your passport.

You can assume:

  • STS \le T,
  • no self-loop, i.e. u_iv_iu\_i \ne v\_i for 1iM1 \le i \le M,
  • no duplicate routes, i.e. u_iu_ju\_i \ne u\_j and/or v_iv_jv\_i \le v\_j for 1i<jM1 \le i < j \le M,
  • no duplicate restricted countries, i.e. c_ic_jc\_i \ne c\_j for 1i<jK1 \le i < j \le K, and
  • countries SS and TT are not restricted, i.e. c_jSc\_j \ne S and c_jTc\_j \le T for 1jK1 \le j \le K.

출력

Output the maximum number of stamps you can get on your passport during your travel from SS to TT. If you cannot reach TT from SS, output 'UNREACHABLE'. If you can get an infinite number of stamps on your passport, output 'INFINITY'.