Don't write something.
Don't want to see a jerk jump right in the back.
0. Storage structure (your mother wrote this word.
adjacency Table & Insert Edge
struct edge{ int to,next,v;} E[M]; int Cnt,last[n]; void Insert (int A,int b,int c) { e[++cnt]= (Edge) {b,last[a],c} ; last[a]=cnt;} void link (int A,int b,int c) { insert (a,b,c); insert (b,a,c);}
1.
Close your eyes and touch a spfa
haha haha haha
BOOLInq[n];intDis[n];voidSPFA (intSintt) {Queue<int>Q; Inq[s]=true; FOR0 (i,n) dis[i]=inf; Dis[s]=0; Q.push (s); while(!Q.empty ()) { intC=Q.front (); Q.pop (); for(intI=last[c];i;i=E[i].next) { intv=e[i].to; if(dis[v]>dis[c]+e[i].v) {Dis[v]=dis[c]+e[i].v; if(!Inq[v]) {Q.push (v); INQ[V]=true; }}} Inq[c]=false; }}
2.Tarjan
• Every writing must be wrong ·
Shrinking loop algorithm
intScc,ind;intBel[n],ins[n],low[n],dfn[n];stack<int>s;voidTarjan (intv) {Low[v]=dfn[v]=++IND; S.push (v); Ins[v]=true; for(intI=last[v];i;i=E[i].next) { if(!dfn[e[i].to]) Tarjan (e[i].to), Low[v]=min (low[v],low[e[i].to]); Else if(Ins[e[i].to]) Low[v]=min (low[v],dfn[e[i].to]); } intnow=-1; if(dfn[x]==Low[x]) { ++SCC; while(now!=x&&!S.empty ()) { intt=s.top (); S.pop (); Ins[t]=false; Bel[t]=SCC; } }}
If anyone finds out this is wrong, tomorrow's a snack.
Here's the ejection mark.
Let's start with a little bit of tree-related stuff.
3.
LCA: Based on multiplication: ...
Based on RMQ: The two-point LCA is the most shallow node in the two-point DFS sequence. Well, then we just need to use the algorithm of the most valued query.
"I feel like my IQ is down.
4. Matrix Tree theorem
Non-graph Spanning tree count
Pre-Knowledge: Gaussian elimination, determinant
We construct a degree matrix D d (i,j) equal to the degree of I at i!=j, otherwise equal to 0
Constructs an adjacency matrix A
And then this diagram of the Kirchhoff (this name?) The matrix is g,g (i,j) =d (I,J)-A (I,J)
Then we calculate the determinant value, which is the number of spanning tree of this graph.
What time do you write tomorrow?
"Review" late-night review of the stupid graphic theory of the thing