이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
using namespace std;
#define int long long
const int N = 203;
int inf = 1e15;
int dp[N][N];
vector<vector<int>> arr(N, vector<int>(N, inf));
vector<vector<int>> cost(N, vector<int>(N, -1));
vector<vector<int>> arr2(N, vector<int>(N, inf));
int n, m;
int floyd()
{
for (int i = 0; i <= n; i++)
{
for (int j = 0; j <= n; j++)
{
dp[i][j] = arr[i][j];
}
}
for (int k = 1; k <= n; k++)
{
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
}
}
}
return min(dp[1][n] + dp[n][1], inf);
}
signed main()
{
cin >> n >> m;
for (int i = 0; i <= n; i++)
{
arr[i][i] = 0;
}
for (int i = 0; i < m; i++)
{
int a, b, c, d;
cin >> a >> b >> c >> d;
if (c < arr[a][b])
{
arr2[a][b] = arr[a][b];
arr[a][b] = c;
}
cost[a][b] = d;
}
int ans = floyd();
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
if (cost[i][j] == -1)
continue;
int x = arr[j][i];
arr[j][i] = min(arr[j][i], arr[i][j]);
arr[i][j] = arr2[i][j];
ans = min(ans, floyd() + cost[i][j]);
arr[i][j] = arr[j][i];
arr[j][i] = x;
}
}
cout << (ans == inf ? -1 : ans) << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |