BZOJ3792: Running

Source: Internet
Author: User

Exercises

Feel the hang out of Xiang ...

Obviously we can think of the points in the matrix multiplication as the edges in the original.

First write opertor in the struct actually can only take a variable?

Put it outside, and then you have to add a quote?

Then the title is not clear, how to calculate the heavy side? Well, then I know that the heavy side counts two.

Then did not open ll, did not take the mold to contribute once wa ...

Code:

1#include <cstdio>2#include <cstdlib>3#include <cmath>4#include <cstring>5#include <algorithm>6#include <iostream>7#include <vector>8#include <map>9#include <Set>Ten#include <queue> One#include <string> A #defineINF 1000000000 - #defineMAXN 500 - #defineMAXM 500+100 the #defineEPS 1e-10 - #definell Long Long - #definePA pair<int,int> - #defineFor0 (i,n) for (int i=0;i<= (n); i++) + #defineFor1 (i,n) for (int i=1;i<= (n); i++) - #defineFor2 (i,x,y) for (int i= (x); i<= (y); i++) + #defineFor3 (i,x,y) for (int i= (x); i>= (y); i--) A #defineFor4 (i,x) for (int i=head[x],y;i;i=e[i].next) at #defineMoD 45989 - using namespacestd; - inline ll read () - { -ll x=0, f=1;CharCh=GetChar (); -      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} in      while(ch>='0'&&ch<='9') {x=Ten*x+ch-'0'; ch=GetChar ();} -     returnx*F; to } + intn,m,s,tot,cnt,num[maxn],c[maxn][2]; - structMatrix the { *     intD[MAXN][MAXN]; $Matrix () {memset (d,0,sizeof(d));}Panax Notoginseng }a,b; -Inline matrixoperator* (Matrix &x,matrix &y) the { + Matrix Z; A For1 (i,m) the For1 (j,m) + For1 (k,m) -(Z.d[i][j]+=x.d[i][k]*y.d[k][j])%=MoD; $     returnZ; $ } -Inlinevoidprint (Matrix x) - { theFor1 (i,m) For1 (j,m) cout<<i<<' '<<j<<' '<<x.d[i][j]<<Endl; - }Wuyi voidKSM (ll y) the { -      for(; y;y>>=1, a=a*a) Wu      if(y&1) b=b*A; - } About intMain () $ { -Freopen ("Input.txt","R", stdin); -Freopen ("output.txt","W", stdout); -N=read (); M=read (); S=read (); ll Q=read (); tot=1; A For1 (i,m) +     { the         intX=read (), y=read (); -c[++tot][0]=x;c[tot][1]=y; $c[++tot][0]=y;c[tot][1]=x; the     } them=tot; theFor1 (i,m) For1 (j,m)if(I!=j&&i!= (j^1) &&c[i][1]==c[j][0]) a.d[i][j]=1; theFor1 (i,m) b.d[i][i]=1; -KSM (q1); inFor1 (I,M)if(c[i][0]==s) num[++cnt]=i; the For1 (i,n) the     { About         intans=0; theFor1 (J,M)if(c[j][1]==i) theFor1 (K,CNT) (Ans+=b.d[num[k]][j])%=MoD; theprintf"%d\n", ans); +     } -     return 0; the}
View Code 3792: Run time limit:10 Sec Memory limit:256 MB
submit:48 solved:21
[Submit] [Status] Description

Xiao Bai is very fond of running, so he often runs on campus (actually want to see beauty ~). The campus can be seen by n regions, connected by M-roads. We started out in a small white morning but didn't know how to run. Small White has a habit, will not follow the road just passed back (such as from A to B through the C road, the next time, no longer along C from B return a).
Xiao Bai wants to know from the place where he started, through the Q Road, to reach each point of the program number. This makes it convenient for him to choose.

Input

The first row of 3 integers n,m,s,q. Indicates that there are N regions, M roads, starting from S, need to go through the Q route.
The following m lines, two integers per line, indicate a path between A and B.

Output

Total n rows, one integer per line representing the number of scenarios from S to I (mod 45989)

Sample Input10 20 9 10
1 5
5 10
10 4
10 2
10 7
4 3
10 9
2 8
5 6
6 1
2 10
6 U
9 10
9 6
7 3
7 3
9 |
1 8
9 7
4 5Sample Output17420
41928
35701
40814
31937
22933
5754
15848
43620
10819
HINT

n<=30 m<=60 q<=10^16

BZOJ3792: Running

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.