티스토리 뷰
17835번: 면접보는 승범이네
첫째 줄에 도시의 수 N(2 ≤ N ≤ 100,000), 도로의 수 M(1 ≤ M ≤ 500,000), 면접장의 수 K(1 ≤ K ≤ N)가 공백을 두고 주어진다. 도시는 1번부터 N번까지의 고유한 번호가 매겨진다. 다음 M개의 줄에 걸쳐
www.acmicpc.net
[C++] 17835 면접보는 승범이네
#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) v.erase(unique(v.begin(), v.end()), v.end())
typedef long long ll;
using namespace std;
int V,E,K,u,v;
ll w;
vector<pli> arr[100001];
priority_queue<pli,vector<pli>,greater<pli>> pq;
vector<ll> dist(100001,LONG_LONG_MAX);
void dijkstra(){
while(!pq.empty()){
ll cost = pq.top().first;
int here = pq.top().second;
pq.pop();
if(dist[here]<cost) continue;
for(auto there : arr[here]){
ll nextcost = there.first + cost;
int nextnode = there.second;
if(dist[nextnode]>nextcost){
dist[nextnode]=nextcost;
pq.push({nextcost,nextnode});
}
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>V>>E>>K;
for(int i=0;i<E;i++){
cin>>u>>v>>w;
arr[v].push_back({w,u});
}
for(int i=0;i<K;i++){
cin>>u;
pq.push({0LL,u});
dist[u]=0LL;
}
dijkstra();
int idx=0;
ll cost=INT_MIN;
for(int i=1;i<=V;i++){
if(cost<dist[i]){
cost=dist[i];
idx=i;
}
}
cout<<idx<<'\n'<<cost<<'\n';
return 0;
}
'백준' 카테고리의 다른 글
백준 소스코드 [C++] 1162 도로포장 (0) | 2021.03.30 |
---|---|
백준 소스코드 [C++] 11952 좀비 (0) | 2021.03.30 |
백준 소스코드 [C++] 10021 Watering the Fields (0) | 2021.03.29 |
백준 소스코드 [C++] 16398 행성 연결 (0) | 2021.03.29 |
백준 소스코드 [C++] 20010 악덕 영주 혜유 (0) | 2021.03.28 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- 최단경로문제
- MeTal
- 벨만포드 알고리즘
- 다익스트라 시간복잡도
- WWDC19
- State Restoration
- observeOn
- test coverage
- 최대 매칭
- 에드몬드 카프 알고리즘
- 강한 순환 참조
- 최단경로 문제
- IOS
- WWDC17
- CPU와 Memory
- 코딩대회
- 벨만포드 시간복잡도
- 부스트캠프 6기
- HIG
- WWDC16
- 네트워크 플로우
- 컴퓨터 추상화
- 네트워크 유량
- WWDC21
- 포드 풀커슨 알고리즘
- mach-o
- CompositionalLayout
- rxswift
- Testable
- 최단경로 알고리즘
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 |
글 보관함