Skip to content

Commit 09eb184

Browse files
authored
Create 2477. Minimum Fuel Cost to Report to the Capital 13 feb
2477. Minimum Fuel Cost to Report to the Capital
1 parent 251559a commit 09eb184

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
class Solution {
2+
public:
3+
vector<vector<int>> edges;
4+
vector<bool> visit;
5+
long long ret=0;
6+
int count(int cur,int k){
7+
int cnt=1;
8+
visit[cur]=true;
9+
for(auto i:edges[cur]){
10+
if(visit[i]==false){
11+
cnt+= count(i,k);
12+
}
13+
}
14+
if(cur!=0){
15+
ret+=((cnt+k-1)/k);
16+
17+
}
18+
return cnt;
19+
}
20+
21+
long long minimumFuelCost(vector<vector<int>>& roads, int seats) {
22+
int n =roads.size();
23+
edges.resize(n+1);
24+
visit.resize(n+1);
25+
for(auto road:roads){
26+
edges[road[0]].push_back(road[1]);
27+
edges[road[1]].push_back(road[0]);
28+
}
29+
count(0,seats);
30+
return ret;
31+
}
32+
};

0 commit comments

Comments
 (0)