Be sjy with brush question # #

Source: Internet
Author: User

Notes
"Problem description"
Given a sequence of length m, the subscript number is 1~m. Each element of the sequence is 1~n.
Integer. The cost of defining a sequence is

You can now select two numbers x and Y, and change all x in sequence a to Y. X can be equal to Y.
The minimum possible cost of requesting a sequence.
"Input Format"
Enter the first line containing two integers n and M. The second line contains a m-space-delimited integer, which represents the ordinal
Column A.
"Output Format"
The output line contains an integer that represents the minimum cost of the sequence.
"Sample Input 1"
4 6
1 2 3 4 3 2
"Sample Output 1"
3
"Sample Input 2"
10 5
9 4 3) 8 8
"Sample Output 1"
6
"Sample Interpretation"
In Example 1, the optimal strategy is to change 4 to 3. In Example 2, the optimal strategy is to change 9 to 4.
"Data size and conventions"

For 30% of data, n,m<=100.
For 60% of data, n,m≤2000.
For 100% of data, 1≤n,m≤100,000.

Castle
"Problem description"
Given an undirected connected graph of N-point m-bars, each edge has edge rights. We need to get from the M-bar.
Elect n−1 to form a tree. The shortest path length from point 1th to each node in the original image is Di,
The shortest path length from point 1th to each node in the tree is?? , the tree should be satisfied for any node
I, all have di = Si.
Please find out the number of options to choose n−1.
"Input Format"
The first line of input contains two integers n and M.
Next m line, each line contains three integers u, V and W, describes a connection node U and V and the edge right is
The side of W.
"Output Format"
The output line contains an integer that represents the result of the schema number for the 2^31−1 modulo.
"Sample Input"
3 3
1 2 2
1 3 1
2 3 1
"Sample Output"
2
"Data size and conventions"
For 20% of data, 2<=n<=5,m<=10.
For 50% of data, the number of scenarios that meet the criteria does not exceed 10000.
For 100% of data, 2≤n≤1000,n-1≤m≤n (N-1)/2,1<=w<=100.

#include <iostream>#include<cstdio>#include<cstring>#include<queue>#defineMAXN 1000#defineMAXM 500000#defineMoD 1<<31-1using namespaceStd;typedefLong LongLL;intM,n;intW[MAXN][MAXN], S[MAXN][MAXN], NUM[MAXN], D[MAXN]; LL DIS[MAXN], Sum[maxn], ans (1); Queue<int>que;intMain () {Ios::sync_with_stdio (false); CIN>> N >>m;  for(intI=1; i<=m;i++) {        intU,v,value;cin>>u>>v>>value; W[U][V]= W[v][u] =value; s[u][++num[u]] =v; s[v][++NUM[V]] =u; }     for(intI=1; i<=n;i++) Dis[i] =0x7fffff; Que.push (1);d [1] =1;d is[1] =0;  Do{        inth = Que.front ();d [h] =0;        Que.pop ();  for(intI=1; i<=num[h];i++){            if(Dis[s[h][i] > Dis[h] +W[h][s[h][i]]) {Dis[s[h][i]]= Dis[h] +W[h][s[h][i]]; if(!D[s[h][i]]) {Que.push (S[h][i]), D[s[h][i]=1; }            }        }    } while(!que.empty ()); Que= queue<int>(); memset (d,0,sizeof(d)); Que.push (1), d[1] =1, sum[1] =1;  Do{        inth = Que.front ();d [h] =0;        Que.pop ();  for(intI=1; i<=num[h];i++){            if(Dis[s[h][i]] = = dis[h]+W[h][s[h][i]]) {Sum[s[h][i]]= = mod? Sum[s[h][i]] =1: sum[s[h][i]]++; if(!D[s[h][i]]) {Que.push (S[h][i]), D[s[h][i]=1; }            }        }    } while(!que.empty ());  for(intI=1; i<=n;i++) ans= (Ans*sum[i])%m; cout<< ans <<Endl; return 0;} 
Castle.cpp

Be sjy with brush question # #

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.