티스토리 뷰
백준 소스코드 [C++] 13907 세금
#include <iostream>
#include <algorithm>
#include <queue>
#include <string.h>
#include <limits.h>
#include <vector>
#include <math.h>
#include <stack>
#include <bitset>
#include <string>
#include <set>
#include <map>
#include <unordered_map>
#include <sstream>
#include <cstdlib>
#define all(v) v.begin(), v.end()
#define pii pair<int, int>
#define pli pair<ll, int>
#define make_unique(v) sort(all(v)), v.erase(unique(all(v), v.end())
typedef long long ll;
using namespace std;
#define MAX 987654321
int V, E, K, v, e, weight;
vector <pii>adj[1001];
int res[1001][1001];
int src,sink;
struct Node{
int idx,depth,cost;
Node(int idx,int depth,int cost){
this->idx=idx;
this->depth=depth;
this->cost=cost;
}
bool operator<(const Node& N) const{
return this->cost > N.cost;
}
};
void dijkstra(){
for(int i=1;i<=V;i++){
for(int j=0;j<=1000;j++)
res[i][j]=MAX;
}
priority_queue<Node> pq;
pq.push(Node(src,0,0));
res[src][0]=0;
while(!pq.empty()){
int here = pq.top().idx;
int depth = pq.top().depth;
int cost = pq.top().cost;
pq.pop();
if (depth==V || res[here][depth++]<cost) continue;
for(auto ith: adj[here]){
int nextcost = cost + ith.second;
int there = ith.first;
if(res[there][depth]>nextcost){
res[there][depth]=nextcost;
pq.push(Node(there,depth,nextcost));
}
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> V >> E >> K;
cin>>src>>sink;
for (int i = 0;i < E;i++) {
cin >> v >> e >> weight;
adj[v].push_back({ e,weight });
adj[e].push_back({ v,weight });
}
dijkstra();
vector<pii> dest;
for(int depth=0;depth<=1000;depth++)
if(res[sink][depth]!=MAX) dest.push_back({depth,res[sink][depth]});
int tax=0,temp;
for(int i=0;i<=K;i++){
int val=INT_MAX;
for(auto a: dest) val=min(val,a.first*tax+a.second);
cout<<val<<'\n';
if(i==K) break;
cin>>temp;
tax+=temp;
}
return 0;
}
'백준' 카테고리의 다른 글
백준 소스코드 [C++] 17071 숨바꼭질 5 (0) | 2021.04.12 |
---|---|
백준 소스코드 [C++] 2325 개코전쟁 (0) | 2021.04.08 |
백준 소스코드 [C++] 1738 골목길 (0) | 2021.04.04 |
백준 소스코드 [C++] 1208 부분수열의 합 2 (0) | 2021.04.02 |
백준 소스코드 [C++] 14225 부분수열의 합 (0) | 2021.04.02 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- CPU와 Memory
- 벨만포드 시간복잡도
- 최단경로 알고리즘
- 벨만포드 알고리즘
- rxswift
- observeOn
- 에드몬드 카프 알고리즘
- MeTal
- 코딩대회
- WWDC17
- 다익스트라 시간복잡도
- 강한 순환 참조
- 최단경로문제
- mach-o
- IOS
- Testable
- State Restoration
- 최대 매칭
- HIG
- 네트워크 유량
- test coverage
- 포드 풀커슨 알고리즘
- 컴퓨터 추상화
- WWDC16
- CompositionalLayout
- 최단경로 문제
- 네트워크 플로우
- 부스트캠프 6기
- WWDC21
- WWDC19
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
글 보관함