"Problem description"
Given a single point? An undirected graph of edges with edge rights on each edge. We need to get from the side of the bar.
Elected? − 1, constituting a tree. The shortest path length from point 1th to each node in the original image is?? ,
The shortest path length from point 1th to each node in the tree is?? , the tree should be satisfied for any node
?, all have?? =??.
Would you please ask for the election? − Number of 1-side scenarios.
"Input Format"
The first line of input contains two integers?.
Next row, each row contains three integers?、? and?, describes a connection node? and the Edge right is
? The side.
"Output Format"
The output line contains an integer representing the result of the 2 31−1 modulo of the scheme number.
"Sample Input"
7 ·
1 2 2
1 3 1
2 3 1
"Sample Output"
2
"Data size and conventions"
32≤? ≤5, huh? ≤10.
For 50% of data, the number of scenarios that meet the criteria does not exceed 10000.
For 100% of data, 2≤? ≤1000, huh? −1≤? ≤
?? −1
2
, 1≤? ≤100.
Ideas:
According to the simulation in the title
Run first, SPFA. Single Source Shortest circuit
Then, for each point, enumerate all the points connected to it.
If the dis value of the point connected to it plus the weighted value of the edge equals its dis value
The value of this point plus one
After all the points have been enumerated
Assign a value of 0 to a value of 1.
Then the value of all points is multiplied
You can come up with answers
But
You think this is a positive solution?
Don't forget to take the MoD (because I don't have 40 points)
A mod is a positive solution.
Come on, on the code:
#include <queue>#include<cstdio>#include<cstring>#include<iostream>using namespacestd;structNode {int from, To,dis,next;};structNode edge[1000005];Const Long Long intMod=2147483647;intnum_head,num_edge,num_1=0, head[1001];intdis_1[1001],tree_leaf[1001],num_leaf=1;Long Long intAns_edge=1;Long Long intnum_edge_tree[1001];CharWord;BOOLif_in_tree[1001];queue<int>Q;inlinevoidEdge_add (int from,intTo,intdis) {num_1++; Edge[num_1].to=to ; Edge[num_1].dis=dis; Edge[num_1]. from= from; Edge[num_1].next=head[ from]; head[ from]=num_1;} InlinevoidRead_int (int&now_001) {now_001=0; word=GetChar (); while(word>'9'|| word<'0') word=GetChar (); while(word>='0'&&word<='9') {now_001=now_001*Ten+(int) (word-'0'); Word=GetChar (); }}voidMAP_SPFA () {BOOLif_in_spfa[1001]; memset (Dis_1,127/3,sizeof(Dis_1)); memset (IF_IN_SPFA,false,sizeof(IF_IN_SPFA)); dis_1[1]=0; if_in_spfa[1]=true; Q.push (1); intcur_1,cur_2; while(!Q.empty ()) {cur_1=Q.front (); for(inti=head[cur_1];i!=0; i=Edge[i].next) { if(dis_1[cur_1]+edge[i].dis<Dis_1[edge[i].to]) {Dis_1[edge[i].to]=dis_1[cur_1]+Edge[i].dis; if(!If_in_spfa[edge[i].to]) {Q.push (edge[i].to); If_in_spfa[edge[i].to]=true; }}} If_in_spfa[cur_1]=false; Q.pop (); }}intMain () {Read_int (Num_head), Read_int (Num_edge); int from, To,dis; for(intI=1; I<=num_edge; i++) {Read_int ( from), Read_int (To), read_int (DIS); Edge_add ( from, To,dis); Edge_add (To, from, dis); } MAP_SPFA (); for(intj=1; j<=num_head;j++) { for(inti=head[j];i!=0; i=Edge[i].next) { if(edge[i].dis+dis_1[j]==Dis_1[edge[i].to]) {Num_edge_tree[edge[i].to]++; Num_edge_tree[edge[i].to]%=MoD; } } } for(intI=1; i<=num_head;i++)if(num_edge_tree[i]==0) num_edge_tree[i]=1; for(intI=1; i<=num_head;i++) {Ans_edge*=Num_edge_tree[i]; Ans_edge%=MoD; } cout<<ans_edge<<Endl; return 0;}
Castle (Spfa+cheng)