We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents cb6d3e8 + 6a320ab commit c02253aCopy full SHA for c02253a
kuyhochung/1. 매주 문제풀이/45주차/5214_환승.cpp
@@ -0,0 +1,46 @@
1
+#include <iostream>
2
+#include <vector>
3
+#include <queue>
4
+using namespace std;
5
+#define INF 1e9
6
+
7
+int n, k, m;
8
+int visited[101001];
9
+vector<vector <int > > graph(101001);
10
11
+int main() {
12
+ ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
13
+ cin >> n >> k >> m;
14
15
+ for (int i = 1; i <= m; i++) {
16
+ for (int j = 0; j < k; j++) {
17
+ int temp;
18
+ cin >> temp;
19
+ graph[temp].push_back(i + 100000);
20
+ graph[i + 100000].push_back(temp);
21
+ }
22
23
24
+ for (int i = 2; i < 101001; i++) {
25
+ visited[i] = INF;
26
27
+ visited[1] = 0;
28
29
+ queue<int> q;
30
+ q.push(1);
31
32
+ while (!q.empty()) {
33
+ int c = q.front();
34
+ q.pop();
35
36
+ for (int i = 0; i < graph[c].size(); i++) {
37
+ if (visited[graph[c][i]] > visited[c] + 1) {
38
+ visited[graph[c][i]] = visited[c] + 1;
39
+ q.push(graph[c][i]);
40
41
42
43
44
+ cout << (visited[n] / 2) + 1;
45
+ return 0;
46
+}
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments