Skip to content

Commit d907cc0

Browse files
committed
ABC238を追加
1 parent bd255fd commit d907cc0

File tree

533 files changed

+35172
-30
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

533 files changed

+35172
-30
lines changed

Diff for: AtCoderBeginnerContest237/E/Program.cs

+50-30
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,55 @@ namespace AtCoder {
99
public class SolveExecuter {
1010
public static void Main() {
1111
var solver = new Solver();
12-
solver.Solve();
12+
solver.Solve2();
1313
}
1414
}
1515

1616
public class Solver {
17-
public void Solve() {
17+
public void Solve2() {
18+
var NM = ria();
19+
var N = NM[0];
20+
var M = NM[1];
21+
var Hs = ria();
22+
var UVs = new List<(int U, int V)>();
23+
for (int i = 0; i < M; i++)
24+
{
25+
var UV = ria();
26+
UVs.Add((UV[0], UV[1]));
27+
}
28+
29+
var dijkstra = new Dijkstra(N + 1);
30+
foreach (var (U, V) in UVs)
31+
{
32+
int HU = Hs[U - 1];
33+
int HV = Hs[V - 1];
34+
35+
int higherIndex = HU > HV ? U : V;
36+
int lowerIndex = HU > HV ? V : U;
37+
int higherH = Hs[higherIndex - 1];
38+
int lowerH = Hs[lowerIndex - 1];
39+
40+
int diff = higherH - lowerH;
41+
dijkstra.Add(higherIndex, lowerIndex, 0);
42+
dijkstra.Add(lowerIndex, higherIndex, diff);
43+
}
44+
45+
var result = dijkstra.GetMinCost(1);
46+
47+
int maxCostIndex = 1;
48+
var costs = result["cost"];
49+
for (int i = 1; i < costs.Length; i++)
50+
{
51+
if(costs[i] > costs[maxCostIndex]) {
52+
maxCostIndex = i;
53+
}
54+
55+
}
56+
57+
Console.WriteLine(costs[maxCostIndex] + Hs[maxCostIndex - 1]);
58+
}
59+
60+
public void Solve1() {
1861
var NM = ria();
1962
var N = NM[0];
2063
var M = NM[1];
@@ -47,32 +90,9 @@ public void Solve() {
4790
dijkstra.Add(lowerIndex, higherIndex, -2 * diff + costOffset);
4891
}
4992

50-
var result = dijkstra.GetMinCost(1, costOffset);
51-
var costs = result["cost"];
52-
Console.WriteLine(costs.Skip(1).Max());
53-
54-
// var prevs= result["prev"];
55-
56-
// int maxCostIndex = 0;
57-
// long maxCost = long.MinValue;
58-
// for (int i = 1; i <= N; i++)
59-
// {
60-
// var cost = costs[i];
61-
// if (cost <= maxCost) continue;
62-
//
63-
// maxCost = cost;
64-
// maxCostIndex = i;
65-
// }
66-
//
67-
// long ans = costs[maxCostIndex];
68-
// var prev = prevs[maxCostIndex];
69-
// while (prev != 0)
70-
// {
71-
// prev = prevs[prev];
72-
// ans -= costOffset;
73-
// }
74-
//
75-
// Console.WriteLine(ans);
93+
// var result = dijkstra.GetMinCost(1, costOffset);
94+
// var costs = result["cost"];
95+
// Console.WriteLine(costs.Skip(1).Max());
7696
}
7797

7898
static String rs(){return Console.ReadLine();}
@@ -550,7 +570,7 @@ public void Add(int a, int b, long cost = 1)
550570
/// 最短経路のコストを取得
551571
/// </summary>
552572
/// <param name="start">開始頂点</param>
553-
public Dictionary<string, long[]> GetMinCost(int start, int costOffset)
573+
public Dictionary<string, long[]> GetMinCost(int start)
554574
{
555575
// コストをスタート頂点以外を無限大に
556576
var cost = new long[N];
@@ -576,7 +596,7 @@ public Dictionary<string, long[]> GetMinCost(int start, int costOffset)
576596
if (cost[e.to] > v.cost + e.cost)
577597
{
578598
// 既に記録されているコストより小さければコストを更新
579-
cost[e.to] = v.cost + e.cost - costOffset;
599+
cost[e.to] = v.cost + e.cost;
580600
prev[e.to] = v.index;
581601
q.Enqueue(new Vertex(e.to, cost[e.to]));
582602
}
0 Bytes
Binary file not shown.
532 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
532 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
532 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

Diff for: AtCoderBeginnerContest238/A/A.csproj

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp3.1</TargetFramework>
6+
</PropertyGroup>
7+
8+
</Project>

0 commit comments

Comments
 (0)