个人训练赛(11,17周日)

这次考试感觉状态还可以,就是有点着急了。希望下次能更进一步 

B.Consecutive Integers

Problem Statement

 

Snuke has N integers: 1,2,[ldots],N. He will choose K of them and give those to Takahashi.

How many ways are there to choose K consecutive integers?

Constraints

 

  • All values in input are integers.
  • 1≤KN≤50

Input

 

Input is given from Standard Input in the following format:

N K

Output

 

Print the answer.

Sample Input 1

 

3 2

Sample Output 1

 

2

There are two ways to choose two consecutive integers: (1,2) and (2,3).

Sample Input 2

 

13 3

Sample Output 2

 

11

题意:给你1到n总共有你个数,从这n个数里面选取k个数要求k个数还是连续的,让你求一共有多少总方法.

思路:公式n-k+1即可

#include<bits/stdc++.h>

using namespace std;

int main(){
	int n,k;
	cin>>n>>k;
	cout<<n-k+1<<endl;
	
	
	
	
	
	
	return 0;
}

c.ModSum

Problem Statement

 

For an integer N, we will choose a permutation {P1,P2,…,PN} of {1,2,…,N}.

Then, for each i=1,2,…,N, let Mi be the remainder when i is divided by Pi.

Find the maximum possible value of M1+M2+[cdots]+MN.

Constraints

 

  • N is an integer satisfying 1≤N≤109.

Input

 

Input is given from Standard Input in the following format:

N

Output

 

Print the maximum possible value of M1+M2+[cdots]+MN.

Sample Input 1

 

2

Sample Output 1

 

1

When the permutation {P1,P2}={2,1} is chosen, M1+M2=1+0=1.

Sample Input 2

 

13

Sample Output 2

 

78

Sample Input 3

 

1

Sample Output 3

 

0

题意:给你一个数n,然后然后让你求一个1到n的排列,1到n的数排完后记为(pi........)mi为(i%pi),然后让你求mi相加的最大值。

思路;pi为1到n的数,然后i也是1到n的数。保证pi比i大1即可,最后i对应n,pi对应1;对1到n-1进行相加即可。n*(n-1)/2

#include<bits/stdc++.h>

using namespace std;

//vector<long long > ve;
int main(){
	long long n;
	cin>>n;
	long long res;
	res=n*(n-1)/2;
	
	cout<<res<<endl;
	
	
	return 0;
}

 

F,Monsters Battle Royale

Problem Statement

 

There are N monsters, numbered 1,2,…,N.

Initially, the health of Monster i is Ai.

Below, a monster with at least 1 health is called alive.

Until there is only one alive monster, the following is repeated:

  • A random alive monster attacks another random alive monster.
  • As a result, the health of the monster attacked is reduced by the amount equal to the current health of the monster attacking.

Find the minimum possible final health of the last monster alive.

Constraints

 

  • All values in input are integers.
  • 2≤N≤105
  • 1≤Ai≤109

Input

 

Input is given from Standard Input in the following format:

N
A1 A2 … AN

Output

 

Print the minimum possible final health of the last monster alive.

Sample Input 1

 

4
2 10 8 40

Sample Output 1

 

2

When only the first monster keeps on attacking, the final health of the last monster will be 2, which is minimum.

Sample Input 2

 

4
5 13 8 1000000000

Sample Output 2

 

1

Sample Input 3

 

3
1000000000 1000000000 1000000000

Sample Output 3

 

1000000000

题意:现在有n个怪物,他们互相打斗,最后只有一个怪物存活,求最后一个怪物最小能有多少血,它们打斗的规则是被攻击者受到的伤害是攻击者现在有的血量。

思路:从小到大进行排列n个怪物最开始的血,然后最小的怪物一直打其他的怪物(也就是对其他的怪物进行求余),然后再进行从小到大排列,一直循环即可。

#include<bits/stdc++.h>

using namespace std;


typedef long long ll;
const int maxn=2e5+10;
ll a[maxn];
vector<ll> ve;
int main(){
	ll n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	ll len=n;
//	for(int i=0;i<n;i++){
//		cout<<a[i]<<endl;
//	}
//cout<<len;
	while(true){
//		cout<<len<<endl;
		for(int i=1;i<len;i++){
			int t=a[i]%a[0];
			if(t>0) ve.push_back(t);
		}
		ve.push_back(a[0]);
		len=ve.size();
//		cout<<len<<endl;
		sort(ve.begin(),ve.end());
//		for(int i=0;i<len;i++){
//			cout<<ve[i]<<endl;
//		}
//		cout<<endl;
		for(int i=0;i<len;i++){
			a[i]=ve[i];
		}
//		cout<<len<<endl;
		if(len==1) break;
		ve.clear();
	}
	cout<<a[0]<<endl;
	return 0;
}

G.Powerful Discount Tickets

Problem Statement

 

Takahashi is going to buy N items one by one.

The price of the i-th item he buys is Ai yen (the currency of Japan).

He has M discount tickets, and he can use any number of them when buying an item.

If Y tickets are used when buying an item priced X yen, he can get the item for 

X
2Y

 (rounded down to the nearest integer) yen.

What is the minimum amount of money required to buy all the items?

Constraints

 

  • All values in input are integers.
  • 1≤N,M≤105
  • 1≤Ai≤109

Input

 

Input is given from Standard Input in the following format:

N M
A1 A2 … AN

Output

 

Print the minimum amount of money required to buy all the items.

Sample Input 1

 

3 3
2 13 8

Sample Output 1

 

9

We can buy all the items for 9 yen, as follows:

  • Buy the 1-st item for 2 yen without tickets.
  • Buy the 2-nd item for 3 yen with 2 tickets.
  • Buy the 3-rd item for 4 yen with 1 ticket.

Sample Input 2

 

4 4
1 9 3 5

Sample Output 2

 

6

Sample Input 3

 

1 100000
1000000000

Sample Output 3

 

0

We can buy the item priced 1000000000 yen for 0 yen with 100000 tickets.

Sample Input 4

 

10 1
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000

Sample Output 4

 

9500000000

题意:现在你想买n个物品,有m张卷,每张卷可以打5折,让你求最小花的钱的数。

思路:用优先队列把物品的价钱存起来,每次都对价钱最贵的进行打折。

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
int main(){
	ll n,m;
	ll k;
	ll t;
	cin>>n>>m;
	priority_queue<ll>q;
	for(int i=0;i<n;i++){
		cin>>k;
		q.push(k);	
	}
	while(m--){
		t=q.top()/2;
		q.pop();
		q.push(t);
	}
	ll sum=0;
	while(!q.empty()){
		sum+=q.top();
		q.pop();
	}
	cout<<sum<<endl;
	return 0;
}

HAttack Survival

 

Problem Statement

 

Takahashi has decided to hold fastest-finger-fast quiz games. Kizahashi, who is in charge of making the scoreboard, is struggling to write the program that manages the players' scores in a game, which proceeds as follows.

A game is played by N players, numbered 1 to N. At the beginning of a game, each player has K points.

When a player correctly answers a question, each of the other N−1 players receives minus one (−1) point. There is no other factor that affects the players' scores.

At the end of a game, the players with 0 points or lower are eliminated, and the remaining players survive.

In the last game, the players gave a total of Q correct answers, the i-th of which was given by Player Ai. For Kizahashi, write a program that determines whether each of the N players survived this game.

Constraints

 

  • All values in input are integers.
  • 2≤N≤105
  • 1≤K≤109
  • 1≤Q≤105
  • 1≤AiN (1≤iQ)

Input

 

Input is given from Standard Input in the following format:

N K Q
A1
A2
.
.
.
AQ

Output

 

Print N lines. The i-th line should contain Yes if Player i survived the game, and No otherwise.

Sample Input 1

 

6 3 4
3
1
3
2

Sample Output 1

 

No
No
Yes
No
No
No

In the beginning, the players' scores are (3,3,3,3,3,3).

  • Player 3 correctly answers a question. The players' scores are now (2,2,3,2,2,2).
  • Player 1 correctly answers a question. The players' scores are now (2,1,2,1,1,1).
  • Player 3 correctly answers a question. The players' scores are now (1,0,2,0,0,0).
  • Player 2 correctly answers a question. The players' scores are now (0,0,1,−1,−1,−1).

Players 1,2,4,5 and 6, who have 0 points or lower, are eliminated, and Player 3 survives this game.

Sample Input 2

 

6 5 4
3
1
3
2

Sample Output 2

 

Yes
Yes
Yes
Yes
Yes
Yes

Sample Input 3

 

10 13 15
3
1
4
1
5
9
2
6
5
3
5
8
9
7
9

Sample Output 3

 

No
No
No
No
Yes
No
No
No
Yes
No

题意:现在有n个人玩游戏,每个人初始有k分,现在有q个正确的回答,第i个正确的回答是由ai给出的,让你对于每个人如果他还有分(>0)输出yes否则输出NO,游戏规则是一个人回答正确一个问题,其他n-1个人都-1分

思路:用一个字典来存他们开始的分数,然后用另外的字典来存他们答题的数量t,最后每个人的分数是k-(q-t)、

#include<bits/stdc++.h>

using namespace std;


typedef long long ll;
const int maxn=2e5+10;
ll a;
//vector<ll> ve;
map<int,int>ma1;
map<int,int>ma2;
int main(){
	ll n,k,q;
	cin>>n>>k>>q;
	for(int i=1;i<=n;i++){
		ma1[i]=k;
	}
	for(int i=1;i<=q;i++){
		cin>>a;
//		for(int j=1;j<=n;j++){
//			if(j!=a[i]) ma[j]--;
//		}
		ma2[a]++;
	}
	for(int i=1;i<=n;i++){
		ma1[i]-=(q-ma2[i]);
	}
	for(int i=1;i<=n;i++){
		if(ma1[i]>0) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}	
}

M.AB Substrings

Problem Statement

 

Snuke has N strings. The i-th string is si.

Let us concatenate these strings into one string after arranging them in some order. Find the maximum possible number of occurrences of AB in the resulting string.

Constraints

 

  • 1≤N≤104
  • 2≤|si|≤10
  • si consists of uppercase English letters.

Input

 

Input is given from Standard Input in the following format:

N
s1
\vdots
s_N

Output

 

Print the answer.

Sample Input 1

 

3
ABCA
XBAZ
BAD

Sample Output 1

 

2

For example, if we concatenate ABCABAD and XBAZ in this order, the resulting string ABCABADXBAZ has two occurrences of AB.

Sample Input 2

 

9
BEWPVCRWH
ZZNQYIJX
BAVREA
PA
HJMYITEOX
BCJHMRMNK
BP
QVFABZ
PRGKSPUNA

Sample Output 2

 

4

Sample Input 3

 

7
RABYBBE
JOZ
BMHQUVA
BPA
ISU
MCMABAOBHZ
SZMEHMA

Sample Output 3

 

4

题意:给你n个字符串,然后串联成一个字符串,,求串联成一个字符串中AB出现的最大次数

思路:先求每一个字符串中AB出现的次数,然后求每一个字符串第一个是B出现的次数tb和最后一个出现是A的次数ta,另外还需要考虑一个特殊的情况,首尾含有B或者A的字符串都是BA型的需要再减去1.

 

#include<bits/stdc++.h>

using namespace std;


typedef long long ll;
const ll maxn=1e5;
string str[maxn];
int idex;
void solve(string a ){
	int len=a.length();
	for(int i=0;i<len-2;i++){
		if(a[i]=='A'&&a[i+1]=='B') idex++;
	}
}
int main()
{
	int n;
	cin>>n;
	idex=0;
	int ta=0,tb=0;
	int ans;
	int res=0;
	for(int i=0;i<n;i++){
		cin>>str[i]; 
		int len=str[i].length();
		if(str[i][0]=='B') tb++;
		if(str[i][len-1]=='A') ta++;
		if(str[i][0]=='B'&&str[i][len-1]=='A') res+=1;
 	}
 	if(ta==res&&tb==res&&res!=0){
 		ans=min(ta,tb);
 		ans-=1;
	 }
	 else{
		ans=min(ta,tb);
	 }
	  
	for(int i=0;i<n;i++){
		solve(str[i]);
	}	
	idex+=ans;
	cout<<idex<<endl;
	return 0;
}

J.Kleene Inversion

Problem Statement

 

We have a sequence of N integers A~=~A0,~A1,~…,~AN−1.

Let B be a sequence of K×N integers obtained by concatenating K copies of A. For example, if A~=~1,~3,~2 and K~=~2, B~=~1,~3,~2,~1,~3,~2.

Find the inversion number of B, modulo 109+7.

Here the inversion number of B is defined as the number of ordered pairs of integers (i,~j)~(0≤i<jK×N−1) such that Bi>Bj.

Constraints

 

  • All values in input are integers.
  • 1≤N≤2000
  • 1≤K≤109
  • 1≤Ai≤2000

Input

 

Input is given from Standard Input in the following format:

N K
A0 A1 … AN−1

Output

 

Print the inversion number of B, modulo 109+7.

Sample Input 1

 

2 2
2 1

Sample Output 1

 

3

In this case, B~=~2,~1,~2,~1. We have:

  • B0>B1
  • B0>B3
  • B2>B3

Thus, the inversion number of B is 3.

Sample Input 2

 

3 5
1 1 1

Sample Output 2

 

0

A may contain multiple occurrences of the same number.

Sample Input 3

 

10 998244353
10 9 8 7 5 6 3 4 2 1

Sample Output 3

 

185297239

Be sure to print the output modulo 109+7.

题解:给一个序列里面有n个数,然后复制k次这个序列形成一个新的序列。求序列中前一个数比后一个数大的对数。,可以先算原来这个序列有几对再乘上k,再加上有来个原序列前一个原序列的数比后一个原序列的数大的个数*k*(k-1)/2

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
const ll mod=1e9+7;
ll a[5000];
int main()
{
	ll n,k;
	ll ans=0;
	ll temp=0;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=n;i<2*n;i++){
		a[i]=a[i-n];
	}
//	cout<<n;
	for(int i=0;i<n;i++){
		for(int j=n;j<2*n;j++){
			if(a[i]>a[j])ans++;
		}
//		cout<<ans<<" ";
		for(int k=i+1;k<n;k++){
//			if(k==n) continue;
			if(a[i]>a[k]) temp++;
		}
	}
//	cout<<ans<<" "<<temp<<endl;
	cout<<(((k*(k-1)/2)%mod*ans%mod)%mod+(temp*k)%mod)%mod; 
	return 0;
}

Counting of Trees

 

Problem Statement

 

Given is an integer sequence D1,…,DN of N elements. Find the number, modulo 998244353, of trees with N vertices numbered 1 to N that satisfy the following condition:

  • For every integer i from 1 to N, the distance between Vertex 1 and Vertex i is Di.

Notes

 

  • A tree of N vertices is a connected undirected graph with N vertices and N−1 edges, and the distance between two vertices are the number of edges in the shortest path between them.
  • Two trees are considered different if and only if there are two vertices x and y such that there is an edge between x and y in one of those trees and not in the other.

Constraints

 

  • 1≤N≤105
  • 0≤DiN−1

Input

 

Input is given from Standard Input in the following format:

N
D1 D2 … DN

Output

 

Print the answer.

Sample Input 1

 

4
0 1 1 2

Sample Output 1

 

2

For example, a tree with edges (1,2), (1,3), and (2,4) satisfies the condition.

Sample Input 2

 

4
1 1 1 1

Sample Output 2

 

0

Sample Input 3

 

7
0 3 2 1 2 2 1

Sample Output 3

 

24

题意:给你一个树有n个节点,然后输入根节点到第i个节点的距离,让你求有多少种这样的树。

思路:求树的深度,从深度为2开始,该深度(记为t)的节点数(x)的t-1的节点数(y)次方。也就是y的x次方,然后遍历深度想乘即可。

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
const ll mod=998244353;
const ll N=1e6;
int a[N];
int b[N];
ll pow_mod(ll a,ll b){
	ll res=1;
	while(b){
		if(b&1) res=res*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return res%mod;
}
int main()
{
	int n;
	cin>>n;
	int k;
	ll ans=0;
	cin>>k;
	if(k!=0){
		cout<<ans<<endl;
		return 0;
	}
	a[k]++;
	b[0]=k;
	for(int i=1;i<n;i++){
		cin>>k;
		b[i]=k;
		a[k]++;
	}
	if(a[0]>1){
		cout<<ans<<endl;
		return 0;
	}
	sort(b,b+n);
	for(int i=0;i<b[n-1];i++){
		if(a[i]==0){
			cout<<ans<<endl;
			return 0;
		}
	}
	ans=1;
	for(int i=1;i<=b[n-1];i++){
		ans=(ans%mod*pow_mod(a[i-1],a[i]))%mod;
	}
	cout<<ans<<endl;
	return 0;
}

Engines

 

Problem Statement

 

E869120 is initially standing at the origin (0,0) in a two-dimensional plane.

He has N engines, which can be used as follows:

  • When E869120 uses the i-th engine, his X- and Y-coordinate change by xi and yi, respectively. In other words, if E869120 uses the i-th engine from coordinates (X,Y), he will move to the coordinates (X+xi,Y+yi).
  • E869120 can use these engines in any order, but each engine can be used at most once. He may also choose not to use some of the engines.

He wants to go as far as possible from the origin. Let (X,Y) be his final coordinates. Find the maximum possible value of √X2+Y2 , the distance from the origin.

Constraints

 

  • 1≤N≤100
  • −1 000 000≤xi≤1 000 000
  • −1 000 000≤yi≤1 000 000
  • All values in input are integers.

Input

 

Input is given from Standard Input in the following format:

N
x1 y1
x2 y2
 : :
xN yN

Output

 

Print the maximum possible final distance from the origin, as a real value. Your output is considered correct when the relative or absolute error from the true answer is at most 10−10.

Sample Input 1

 

3
0 10
5 -5
-5 -5

Sample Output 1

 

10.000000000000000000000000000000000000000000000000

The final distance from the origin can be 10 if we use the engines in one of the following three ways:

  • Use Engine 1 to move to (0,10).
  • Use Engine 2 to move to (5,−5), and then use Engine 3 to move to (0,−10).
  • Use Engine 3 to move to (−5,−5), and then use Engine 2 to move to (0,−10).

The distance cannot be greater than 10, so the maximum possible distance is 10.

Sample Input 2

 

5
1 1
1 0
0 1
-1 0
0 -1

Sample Output 2

 

2.828427124746190097603377448419396157139343750753

The maximum possible final distance is 2√2 =2.82842…. One of the ways to achieve it is:

  • Use Engine 1 to move to (1,1), and then use Engine 2 to move to (2,1), and finally use Engine 3 to move to (2,2).

Sample Input 3

 

5
1 1
2 2
3 3
4 4
5 5

Sample Output 3

 

21.213203435596425732025330863145471178545078130654

If we use all the engines in the order 1→2→3→4→5, we will end up at (15,15), with the distance 15√2 =21.2132… from the origin.

Sample Input 4

 

3
0 0
0 1
1 0

Sample Output 4

 

1.414213562373095048801688724209698078569671875376

There can be useless engines with (xi,yi)=(0,0).

Sample Input 5

 

1
90447 91000

Sample Output 5

 

128303.000000000000000000000000000000000000000000000000

Note that there can be only one engine.

Sample Input 6

 

2
96000 -72000
-72000 54000

Sample Output 6

 

120000.000000000000000000000000000000000000000000000000

There can be only two engines, too.

Sample Input 7

 

10
1 2
3 4
5 6
7 8
9 10
11 12
13 14
15 16
17 18
19 20

Sample Output 7

 

148.660687473185055226120082139313966514489855137208

题意:给你n个点,然后让你从里面选取几个点,各坐标(x,y)相加得到一个点到原点的距离最大;

思路:可以把这n个点看成n个向量,然后就是求向量的模,当两个向量相加时,两向量夹角越小和向量的模越大。因此可以采用极角排序,暴力求得。atan2(y,x)y在前面,求得的取值范围是-π到π,这个题还要注意的是要循环一圈。

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
const ll maxn=110;
//struct node{
//	ll x;
//	ll y;
//	double angle;
//	friend bool operator<(node a,node b){
//		return a.angle<b.angle;
//	}
//}point[maxn];
struct node{
	ll x;
	ll y;
	double angle;
}point[maxn];
bool cmp(node a,node b){
	return a.angle<b.angle;
}
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>point[i].x>>point[i].y;
		point[i].angle=atan2(point[i].y,point[i].x);
	}
	sort(point,point+n,cmp);
	ll ans=0;
	for(int i=0;i<n;i++){
		ll dx=point[i].x,dy=point[i].y;
		ans=max(ans,dx*dx+dy*dy);
		for(int j=(i+1)%n;j!=i;j=(j+1)%n){
			dx+=point[j].x;dy+=point[j].y;
			ans=max(ans,dx*dx+dy*dy);
		}
	}
	double res=sqrt(ans);
//	cout<<<<endl;
	printf("%.14f\n",res);
	return 0;
}

上面那个对结构体内部重载也需要sort一下。

Shortest Path on a Line

 

Problem Statement

 

We have N points numbered 1 to N arranged in a line in this order.

Takahashi decides to make an undirected graph, using these points as the vertices. In the beginning, the graph has no edge. Takahashi will do M operations to add edges in this graph. The i-th operation is as follows:

  • The operation uses integers Li and Ri between 1 and N (inclusive), and a positive integer Ci. For every pair of integers (s,t) such that Lis<tRi, add an edge of length Ci between Vertex s and Vertex t.

The integers L1,…,LMR1,…,RMC1,…,CM are all given as input.

Takahashi wants to solve the shortest path problem in the final graph obtained. Find the length of the shortest path from Vertex 1 to Vertex N in the final graph.

Constraints

 

  • 2≤N≤105
  • 1≤M≤105
  • 1≤Li<RiN
  • 1≤Ci≤109

Input

 

Input is given from Standard Input in the following format:

N M
L1 R1 C1
:
LM RM CM

Output

 

Print the length of the shortest path from Vertex 1 to Vertex N in the final graph. If there is no shortest path, print -1 instead.

Sample Input 1

 

4 3
1 3 2
2 4 3
1 4 6

Sample Output 1

 

5

We have an edge of length 2 between Vertex 1 and Vertex 2, and an edge of length 3 between Vertex 2and Vertex 4, so there is a path of length 5 between Vertex 1 and Vertex 4.

Sample Input 2

 

4 2
1 2 1
3 4 2

Sample Output 2

 

-1

Sample Input 3

 

10 7
1 5 18
3 4 8
1 3 5
4 7 10
5 9 8
6 10 5
8 10 3

Sample Output 3

 

28

题意:现在有n个点,然后在输入m条边和边权,但是这m条边是在一个 区间内选取的,然后让你求1到n的最大距离。

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <functional>

using namespace std;

const int N = 1010, M = 2000010, INF = 1000000000;

int n, m;
int dist[N];    // 存储每个点到起点的距离
int h[N], e[M], v[M], ne[M], idx;   // 数组模拟邻接表

void add(int a, int b, int c)
{
    e[idx] = b, v[idx] = c, ne[idx] = h[a], h[a] = idx++;
}

void dijkstra_heap()
{
    priority_queue < pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> heap;
    for (int i = 1; i <= n; i++) dist[i] = INF;
    dist[1] = 0;
    heap.push(make_pair(dist[1], 1));
    while (heap.size())
    {
        pair<int, int> t = heap.top();
        heap.pop();
        if (t.first > dist[t.second]) continue;
        for (int i = h[t.second]; i != -1; i = ne[i])
            if (dist[e[i]] > t.first + v[i])
            {
                dist[e[i]] = t.first + v[i];
                heap.push(make_pair(dist[e[i]], e[i]));
            }
    }
}

int main()
{
    memset(h, -1, sizeof h);
    cin >> m >> n;
    for (int i = 0; i < m; i++)
    {
        int a, b, c;
        cin >> a >> b >> c;
        add(a, b, c);
        add(b, a, c);
    }
    dijkstra_heap();
    cout << dist[n] << endl;
    return 0;
}

在这个基础上每条边加一个权值即可

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值