kk
This commit is contained in:
@@ -5,6 +5,7 @@ import java.util.*;
|
|||||||
class Solution {
|
class Solution {
|
||||||
|
|
||||||
long res = 0;
|
long res = 0;
|
||||||
|
int sum = 0;
|
||||||
|
|
||||||
public long minimumFuelCost(int[][] roads, int seats) {
|
public long minimumFuelCost(int[][] roads, int seats) {
|
||||||
List<Integer>[] map = new List[roads.length + 1];
|
List<Integer>[] map = new List[roads.length + 1];
|
||||||
@@ -27,10 +28,43 @@ class Solution {
|
|||||||
if (i != from) {
|
if (i != from) {
|
||||||
int childSum = dfs(i, start, seats, map);
|
int childSum = dfs(i, start, seats, map);
|
||||||
cur += childSum;
|
cur += childSum;
|
||||||
res += (childSum + seats - 1)/seats;
|
res += (childSum + seats - 1) / seats;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return cur;
|
return cur;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
// 1466. 重新规划路线
|
||||||
|
public int minReorder(int n, int[][] connections) {
|
||||||
|
List<Integer>[] list = new List[n];
|
||||||
|
List<Integer>[] otherList = new List[n];
|
||||||
|
for (int i = 0; i < list.length; i++) {
|
||||||
|
list[i] = new ArrayList<>();
|
||||||
|
otherList[i] = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int[] ints : connections) {
|
||||||
|
list[ints[0]].add(ints[1]);
|
||||||
|
otherList[ints[1]].add(ints[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
dfs(0, -1, list, otherList);
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void dfs(int now, int parent, List<Integer>[] list, List<Integer>[] otherList) {
|
||||||
|
for (int i = 0; i < list[now].size(); i++) {
|
||||||
|
if (list[now].get(i) != parent) {
|
||||||
|
sum++;
|
||||||
|
dfs(list[now].get(i), now, list, otherList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < otherList[now].size(); i++) {
|
||||||
|
if (otherList[now].get(i) != parent) {
|
||||||
|
dfs(otherList[now].get(i), now, list, otherList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user