일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- kotlin
- 오블완
- JanusWebRTCGateway
- taint
- JanusWebRTCServer
- 헥사고날아키텍처 #육각형아키텍처 #유스케이스
- tolerated
- k8s #kubernetes #쿠버네티스
- 개성국밥
- 달인막창
- PytestPluginManager
- 자원부족
- Value too long for column
- terminal
- JanusWebRTC
- 티스토리챌린지
- vfr video
- 코루틴 컨텍스트
- pytest
- PersistenceContext
- JanusGateway
- table not found
- 깡돼후
- preemption #
- VARCHAR (1)
- mp4fpsmod
- 겨울 부산
- python
- Spring Batch
- 코루틴 빌더
너와 나의 스토리
(BOJ) 6118 숨바꼭질 본문
문제: https://www.acmicpc.net/problem/6118
문제 풀이:
- 다익스트라 돌려서 1에서 각 점까지의 최단 거리 구함
- 구해놓은 dist를 처음부터 끝까지 보면서 제일 큰 수와 그 수의 개수를 찾음
소스 코드:
#include <iostream> #include <queue> #include <vector> #include <string.h> #include <algorithm> #define inf 987654321 using namespace std; typedef pair<int, int> P; int n, m,dist[20001],t,cnt; bool visit[20001]; int main() { ios::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); cin >> n >> m; vector<vector<int>> adj; adj.resize(n + 1); for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); } fill(dist, dist + n + 1, inf); priority_queue<P> pq; dist[1] = 0; pq.push({ 0,1 }); while (!pq.empty()) { int cur; do { cur = pq.top().second; pq.pop(); } while (!pq.empty() && visit[cur]); if (visit[cur]) break; visit[cur] = true; for (auto& i : adj[cur]) { if (dist[i] > dist[cur] + 1) { dist[i] = dist[cur] + 1; pq.push({ -dist[i],i }); } } } dist[0] = 0; for (int i = 1; i <= n; i++) { if (dist[t] < dist[i]) { t = i; cnt = 1; } else if (dist[t] == dist[i]) cnt++; } cout << t << " " << dist[t] <<" "<< cnt << '\n'; return 0; } |
'Algorithm > 다익스트라 알고리즘 (Dijkstra's Algorithm)' 카테고리의 다른 글
(BOJ) 13911 집 구하기 (0) | 2019.05.23 |
---|---|
(BOJ) 14618 총깡 총깡 (1) | 2019.05.19 |
(BOJ) 10282 해킹 (0) | 2019.05.14 |
(BOJ) 6593 상범 빌딩 (0) | 2019.02.28 |
(BOJ) 16681 등산 (0) | 2019.01.19 |