bzoj1875: [sdoi2009]hh go for a walk

Source: Internet
Author: User

Finally a ... In the morning according to his previous writing has been WA. In the afternoon, I changed a qwq.

#include <cstdio> #include <cstring> #include <iostream> #include <algorithm>using namespace STD; #define REP (I,s,t) for (int. i=s;i<=t;i++) #define DWN (i,s,t) for (int i=s;i>=t;i--) #define CLR (x,c) memset (X,c, sizeof (x)) int read () {int X=0;char C=getchar (), while (!isdigit (c)) C=getchar (), while (IsDigit (c)) x=x*10+c-' 0 ', c= GetChar (); return x;} const int MOD=45989;CONST int Nmax=25;const int maxn=125;int n,m,t,a,b;int u[maxn],v[maxn],id[maxn],f[maxn];struct Matrix{int A[maxn][maxn];matrix () {clr (a,0);}    Matrix operator* (const matrix &o) const {matrix RHS;    Rep (I,1,m) Rep (j,1,m) Rep (k,1,m) rhs.a[i][j]= (rhs.a[i][j]+a[i][k]*o.a[k][j])%mod; return RHS;}} A,b;int Main () {N=read (), M=read (), T=read (), A=read (), B=read (); t--; REP (i,1,m) {u[i]=read (), V[i]=read (); U[i+m]=v[i],v[i+m]=u[i];id[i]=id[i+m]=i;} m*=2; Rep (I,1,m) Rep (j,1,m) if (id[i]!=id[j]&&v[i]==u[j]) b.a[i][j]=1; REP (i,1,m) a.a[i][i]=1;while (T) {if (t&1) a=a*b;b=b*b; T>>=1;} REP (i,1,m) if (u[i]==a) F[i]=1;int Ans=0; Rep (i,1,m) if (v[i]==b) Rep (j,1,m) ans= (Ans+a.a[j][i]*f[j])%mod;printf ("%d\n", ans); return 0;}

  

1875: [Sdoi2009]hh go for a walk time limit:20 Sec Memory limit:64 MB
submit:1300 solved:610
[Submit] [Status] [Discuss] Description

HH has a constant habit, like hundred steps after a meal. The so-called hundred step Walk, is a walk, is in a certain time, through a certain distance. But at the same time HH is a person who likes to change, so he will not immediately follow the road just walked back. And because HH is a person who likes to change, so he walks the path every day is not exactly the same, he wants to know how many ways he has to walk. Now give your school map (assuming that each road is the same length is 1), ask the length of T, from a given location A to a given location B total number of eligible paths

Input

First line: five integer n,m,t,a,b. where n indicates the number of intersections in the school, m indicates the number of roads in the school, T indicates the distance that HH wants to walk, a is the starting point for a walk, and B represents the end of the walk. The next m line, a set of Ai,bi per row, represents a road from the intersection AI to the intersection Bi. The data guarantees AI = Bi, but there is no guarantee that there is at most one route connected between any two intersections. The intersection number is from 0 to n−1. All data in the same row is separated by a space, and there is no extra space at the end of the line. There are no extra empty lines. Answer modulus 45989.

Output

A line that represents the answer.

Sample Input4 5 3) 0 0
0 1
0 2
0 3
2 1
3 2Sample Output4HINT

For 30% of data, n≤4,m≤10,t≤10. For 100% of data, n≤20,m≤60,t≤2^30,0≤a,b

Source

Day1

[Submit] [Status] [Discuss]

bzoj1875: [sdoi2009]hh go for a walk

Related Article

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.