diff --git "a/13_\354\265\234\353\213\250\352\262\275\353\241\234/1238.cpp" "b/13_\354\265\234\353\213\250\352\262\275\353\241\234/1238.cpp" new file mode 100644 index 0000000..092b77f --- /dev/null +++ "b/13_\354\265\234\353\213\250\352\262\275\353\241\234/1238.cpp" @@ -0,0 +1,74 @@ +//13_최단경로 필수 2번:1238.cpp + +#include +#include +#include +#include + +using namespace std; + +const int INF = INT_MAX; + +int main() +{ + ios_base::sync_with_stdio(false); + cin.tie(nullptr); + + int v, e, x; + cin >> v >> e >> x; + + vector>> graph(v + 1); + + for (int i = 0; i < e; ++i) + { + int a, b, cost; + cin >> a >> b >> cost; + graph[a].emplace_back(b, cost); + } + + auto dijkstra = [&](int start) + { + priority_queue, vector>, greater>> pq; + vector distance(v + 1, INF); + + pq.push({0, start}); + distance[start] = 0; + + while (!pq.empty()) + { + int dist = pq.top().first; + int now = pq.top().second; + pq.pop(); + + if (distance[now] < dist) continue; + + for (const auto& edge : graph[now]) + { + int node_index = edge.first; + int node_cost = edge.second; + int cost = dist + node_cost; + + if (distance[node_index] > cost) + { + distance[node_index] = cost; + pq.push({cost, node_index}); + } + } + } + + return distance; + }; + + int result = 0; + + for (int i = 1; i <= v; ++i) + { + vector go = dijkstra(i); + vector back = dijkstra(x); + result = max(result, go[x] + back[i]); + } + + cout << result << "\n"; + + return 0; +} diff --git "a/13_\354\265\234\353\213\250\352\262\275\353\241\234/15685.cpp" "b/13_\354\265\234\353\213\250\352\262\275\353\241\234/15685.cpp" new file mode 100644 index 0000000..f43621f --- /dev/null +++ "b/13_\354\265\234\353\213\250\352\262\275\353\241\234/15685.cpp" @@ -0,0 +1,65 @@ +//13_최단경로 필수 1번:15685.cpp + +#include +#include + +using namespace std; + +bool map[101][101] = {false}; +int dx[] = {1, 0, -1, 0}; +int dy[] = {0, -1, 0, 1}; +int ans = 0; + +void dragonCurve(int x, int y, int d, int g); + +int main() +{ + ios_base::sync_with_stdio(false); + cin.tie(NULL); + + int n; + cin >> n; + + for (int i = 0; i < n; i++) + { + int x, y, d, g; + cin >> x >> y >> d >> g; + dragonCurve(x, y, d, g); + } + + for (int i = 0; i < 100; i++) + { + for (int j = 0; j < 100; j++) + { + if (map[i][j] && map[i][j + 1] && map[i + 1][j] && map[i + 1][j + 1]) + { + ans++; + } + } + } + + cout << ans << "\n"; + + return 0; +} + +void dragonCurve(int x, int y, int d, int g) +{ + vector d_list; + d_list.push_back(d); + + for (int i = 1; i <= g; i++) + { + for (int j = d_list.size() - 1; j >= 0; j--) { + d_list.push_back((d_list[j] + 1) % 4); + } + } + + map[y][x] = true; + for (int direction : d_list) + { + x += dx[direction]; + y += dy[direction]; + map[y][x] = true; + } +} diff --git "a/13_\354\265\234\353\213\250\352\262\275\353\241\234/1865.cpp" "b/13_\354\265\234\353\213\250\352\262\275\353\241\234/1865.cpp" new file mode 100644 index 0000000..d48135d --- /dev/null +++ "b/13_\354\265\234\353\213\250\352\262\275\353\241\234/1865.cpp" @@ -0,0 +1,2 @@ +//13_최단경로 도전 2번:1865.cpp + diff --git "a/13_\354\265\234\353\213\250\352\262\275\353\241\234/2458.cpp" "b/13_\354\265\234\353\213\250\352\262\275\353\241\234/2458.cpp" new file mode 100644 index 0000000..c0fbdf5 --- /dev/null +++ "b/13_\354\265\234\353\213\250\352\262\275\353\241\234/2458.cpp" @@ -0,0 +1,58 @@ +//13_필수3: 2458.cpp + +#include +#include +#include + +using namespace std; + +const int INF = 999999999; + +int main() +{ + ios_base::sync_with_stdio(false); + cin.tie(nullptr); + + int n, m; + cin >> n >> m; + + vector> dist(n + 1, vector(n + 1, INF)); + + for (int i = 1; i <= m; ++i) + { + int a, b; + cin >> a >> b; + dist[a][b] = 1; + } + + for (int k = 1; k <= n; ++k) + { + for (int i = 1; i <= n; ++i) + { + for (int j = 1; j <= n; ++j) + { + dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]); + } + } + } + + int ans = 0; + + for (int i = 1; i <= n; ++i) + { + int cnt = 0; + + for (int j = 1; j <= n; ++j) + { + if (dist[i][j] != INF || dist[j][i] != INF) { + cnt++; + } + } + + if (cnt == n - 1) ans++; + } + + cout << ans << "\n"; + + return 0; +} diff --git "a/13_\354\265\234\353\213\250\352\262\275\353\241\234/\355\225\251\354\212\271\355\203\235\354\213\234\354\232\224\352\270\210.cpp" "b/13_\354\265\234\353\213\250\352\262\275\353\241\234/\355\225\251\354\212\271\355\203\235\354\213\234\354\232\224\352\270\210.cpp" new file mode 100644 index 0000000..53408cd --- /dev/null +++ "b/13_\354\265\234\353\213\250\352\262\275\353\241\234/\355\225\251\354\212\271\355\203\235\354\213\234\354\232\224\352\270\210.cpp" @@ -0,0 +1 @@ +//13_최단경로 도전 1번:합승택시요금.cpp