Bzoj 1898: [Zjoi2005]swamp Swamp crocodile

Source: Internet
Author: User

1898: [Zjoi2005]swamp Swamp crocodile time limit:5 Sec Memory limit:64 MB
submit:1085 solved:604
[Submit] [Status] [Discuss] Description

The Pantanal Marsh, known as the world's largest wetland, is in the southern part of Mato Grosso, central Brazil. Whenever the rainy season comes, here the blue waves, vitality, attracting many tourists. In order to make the play more interesting, people in the center of the pond built several dun foping and stone bridges, each stone bridge connected to two Dun foping, and every two dun foping between at most only one stone bridge. This site has not dared to open up after its creation, because there are many dangerous piranhas in the pond. Mr. Bean had a passion for adventure, and as soon as he heard the news, he rushed to the pond and wanted to be the first person to travel on a bridge. Although the beans love adventure, but also dare not to make jokes on their lives, so he began a careful field survey, and got some surprising conclusion: Piranha's travel route is cyclical, this cycle can only be 2,3 or 4 units of time. In each unit of time, piranhas can swim from one dun foping to another dun foping. Each to a dun foping, if the person above it will carry out an attack, otherwise continue its periodic movement. If not to Dun foping, it will not attack people. With the aid of advanced instruments, the beans quickly figured out the laws of all piranhas, and he began to design his own course of action. Every unit of time, he can only follow the stone bridge from one dun foping to another Dun foping, and can not stop in a dun foping, because standing motionless there will be other dangers. If peas and a piranha arrive at a dun foping at the same time, they will be attacked by piranhas, which he certainly does not want to happen. Now that the beans have been selected two Dun foping start and end, he wants to start from start, after K units of time to stand on the Dun foping end. Assuming that the DUN foping can be repeated (including start and end), he would ask you to help calculate how many of these routes (of course not being attacked by piranhas).

Input

Input file Total m + 2 + nfish line. The first line contains five positive integers n,m,start,end and K, each representing the number of Dun foping, the number of stone bridges, the number of Start dun foping and end Dun foping, and the unit time required for a route. The Dun foping is numbered with an integer of 0 to n–1. 2nd to M + 1, give information about the stone Bridge. Each line of two integers x and y,0≤x, y≤n–1, indicates that the stone bridge is connected to two Dun foping, numbered x and Y. The M + 2 line is an integer nfish that represents the number of piranhas. Section M + 3 to M + 2 + nfish line, each row gives information about a piranha. The first integer of each line is T,t = 2,3 or 4, which represents the Piranha's movement cycle. Next there is the number of T, which indicates the route of the piranha during a cycle. If t=2, next there are 2 numbers P0 and P1, piranha from P0 to P1, from P1 to P0, ... ;? If t=3, then there are 3 numbers of p0,p1 and P2, piranha from P0 to P1, P1 to P2, P2 to P0, ... ;? If t=4, then there are 4 numbers of p0,p1,p2 and P3, piranhas from P0 to P1, P1 to P2, P2 to P3, P3 to P0, ... When the beans start, all piranhas are on their route P0 position, please rest assured that this position will not be the start Dun foping.

Output

Output the number of routes, because this number can be very large, you just output the number divided by 10000 of the remainder of the line. "Convention"? 1≤n≤50? 1≤k≤2,000,000,000? 1≤nfish≤20

Sample Input6 8 1) 5 3
0 2
2 1
1 0
0 5
5 1
1 4
4 3
3 5
1
3 0 5 1

Sample Output2

"Sample description"
Moment 0123
Piranha Position 0510
Route 11,205
Route 21,435



HINT Source [Submit] [Status] [Discuss]

It is found that the time is 12 cycles, so we construct the adjacency matrix in 1~12 unit time, and then do the fast transfer of the matrix.

1#include <bits/stdc++.h>2 3 Const intSiz = -;4 Const intMoD =10000;5 6 intN, M, St, Ed, TM, FS, CL, lc[5];7 8 structMatrix9 {Ten     intS[siz][siz]; One      AInline Matrix (void) -     { -memset (s),0,sizeof(s)); the     } - }; -  -Inline matrixoperator*(matrix A, matrix B) + { - Matrix C; +      A      for(intK =1; K <= N; ++k) at          for(inti =1; I <= N; ++i)if(A.s[i][k]) -              for(intj =1; J <= N; ++J)if(B.s[k][j]) -(C.s[i][j] + = a.s[i][k] * B.s[k][j])%=MoD; -                  -     returnC; - } in  -Inline matrixoperator^ (Matrix A,intb) to { + Matrix C; -      the      for(inti =1; I <= N; ++i) *C.s[i][i] =1; $         Panax Notoginseng      for(; b; b >>=1, a = A *a) -         if(B &1) C = c *A; the          +     returnC; A } the  +Inlinevoidprint (matrix A) - { $Puts"Matrix"); $      -      for(inti =1; I <= N; ++i) -     { the          for(intj =1; J <= N; ++j) -printf"%d", A.s[i][j]);WuyiPuts""); the     } -      WuPuts""); - } About  $Matrix bas[ the], ans; -  -Signed Main (void) - { Ascanf"%d%d%d%d%d", &n, &m, &st, &ed, &TM); +      the++St; -++Ed; $      the      for(inti =1, X, y; I <= m; ++i) the     { thescanf"%d%d", &x, &y), ++x, + +y; the          -          for(intj =1; J <= A; ++j) inBas[j].s[x][y] =1, theBAS[J].S[Y][X] =1; the     } About      thescanf"%d", &FS); the      the      while(fs--) +     { -scanf"%d", &cl); the         Bayi          for(inti =1; I <= cl; ++i) thescanf"%d", LC +i); the              -          for(inti =1; I <= A; ++i) -         { the             intpos = lc[i% cl +1] +1; the              the              for(intj =1; J <= N; ++j) theBas[i].s[j][pos] =0; -         } the     } the      the      for(inti =1; I <= N; ++i)94bas[0].s[i][i] =1; the          the      for(inti =1; I <= A; ++i) thebas[0] = bas[0] *Bas[i];98          AboutAns = bas[0] ^ (TM/ A); -     101      for(inti =1; I <= TM% A; ++i)102Ans = ans *Bas[i];103         104printf"%d\n", ans.s[st][ed]); the}

@Author: Yousiki

Bzoj 1898: [Zjoi2005]swamp Swamp crocodile

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.