(๋ฐฑ์ค/c++) 1238 - ํํฐ / ์ต๋จ๊ฒฝ๋ก๊ทธ๋ํ, ํ๋ก์ด๋ ์์ฌ๐ coding test/โฝ ๋ฐฑ์ค2024. 8. 22. 17:12
Table of Contents
728x90
๋ฐ์ํ
"(๋ฐฑ์ค/c++) 1238 - ํํฐ / ์ต๋จ๊ฒฝ๋ก๊ทธ๋ํ, ํ๋ก์ด๋ ์์ฌ"
https://www.acmicpc.net/problem/1238
๐ solved.ac ๋์ด๋: ๊ณจ๋3
๐ธ ๋ฌธ์ ํต์ฌ
- ๋จ๋ฐฉํฅ ๋๋ก
- ๊ฐ๋ค๊ฐ ๋์์ค๋ ์ต๋จ๊ฒฝ๋ก
๐น ์ฃผ์ ์ฝ๋ ๋ถ๋ถ
- ํ๋์ค: form ~ stopper ์์์ ๋ถํฐ ๊ฒฝ์ ์ง๊น์ง ๋ฌดํ์ด๋ฉด, ์ฐ๊ฒฐ๋์ด ์์ง ์๋๋ค๋ ๋ป์ด๊ธฐ ๋๋ฌธ์ ๋ฌด์ํด์ฃผ์.
- ๋ ธ๋์ค: ์์์ ๋ถํฐ ๋์ฐฉ์ > ์์์ ๋ถํฐ ๊ฒฝ์ ์ง + ๊ฒฝ์ ์ง๋ถํฐ ๋์ฐฉ์ ์ด ๊ตฌ์กฐ๋ฅผ ์ธ์ฐ์ง ๋ง๊ณ ์ํ(relax)๋ฅผ ์ดํดํ์.
#include<iostream>
#include<vector>
#include<limits.h>
using namespace std;
//vector<pair<int, int>> students[1'001];
int students[1'001][1'001];
int result[1'001];
int main(void)
{
int n, m, x;
cin >> n >> m >> x;
for (int i = 1; i <= n; ++i)
{
for (int j = 1; j <= n; ++j)
{
students[i][j] = 10'000'001;
if (i == j)
{
students[i][j] = 0;
}
}
}
for (int i = 0; i < m; ++i)
{
int a, b, t;
cin >> a >> b >> t;
students[a][b] = t;
//students[a].push_back(make_pair(b, t));
}
for (int stopover = 1; stopover <= n; ++stopover)
{
for (int form = 1; form <= n; ++form)
{
if (students[form][stopover] == 10'000'001)
continue;
for (int to = 1; to <= n; ++to)
{
if (students[form][to] > students[form][stopover] + students[stopover][to])
{
students[form][to] = students[form][stopover] + students[stopover][to];
}
}
}
}
int result = 0;
for (int i = 1; i <=n; ++i)
{
if ((result < students[x][i] /*x->i*/ + students[i][x]) && i!=x)
{
result = students[x][i] /*x->i*/ + students[i][x];
}
}
cout << result;
return 0;
}
728x90
๋ฐ์ํ
'๐ coding test > โฝ ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
(๋ฐฑ์ค/c++) 1987 - ์ํ๋ฒณ/ DFS, ๋ฐฑํธ๋ํน (0) | 2024.08.27 |
---|---|
(๋ฐฑ์ค/c++) 10026 - ์ ๋ก์์ฝ / BFS, ๊ทธ๋ํ (0) | 2024.08.20 |
(๋ฐฑ์ค/c++) 11403 - ๊ฒฝ๋ก์ฐพ๊ธฐ / BFS, ๊ทธ๋ํ (0) | 2024.08.16 |
(๋ฐฑ์ค/c++) 11724 - ์ฐ๊ฒฐ ์์์ ๊ฐ์ / BFS, ๊ทธ๋ํ (0) | 2024.08.16 |
(๋ฐฑ์ค/c++) 14940 - ์ฌ์ด ์ต๋จ ๊ฑฐ๋ฆฌ / DFS, ๊ทธ๋ํ (0) | 2024.08.16 |
@DoctorSunAhna :: ํํฌ์ฝ๋ฅ
์ ํ๋ ๊ฒ ๋ณด๋ค ๋ซ๊ฒ ์ง
ํฌ์คํ ์ด ์ข์๋ค๋ฉด "์ข์์โค๏ธ" ๋๋ "๊ตฌ๋ ๐๐ป" ํด์ฃผ์ธ์!