이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
//#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
using namespace std;
typedef pair < long long, long long > pll;
typedef pair < int, int > pii;
typedef unsigned long long ull;
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;
typedef long long ll;
typedef double db;
const int inf = 1e9, maxn = 208, mod = 1e9 + 7, N = 5e4 + 11;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 555;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;
int n, m, a[N], b[N], c[N], d[N], p[maxn], Bad;
priority_queue < pii, vpii, greater < pii > > q;
ll F[maxn][maxn], D[maxn];
vpii g[2][maxn];
bool I[N];
void Floyd () {
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
if (i != j)
F[i][j] = INF;
for (int i = 1; i <= m; ++i)
F[a[i]][b[i]] = min(F[a[i]][b[i]], (ll)c[i]);
for (int k = 1; k <= n; ++k)
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
F[i][j] = min(F[i][j], F[i][k] + F[k][j]);
}
ll Dijkstra (int s, int f, int j) {
memset(p, -1, sizeof(p));
for (int i = 1; i <= n; ++i)
D[i] = INF;
while (sz(q))
q.pop();
D[s] = 0;
q.push(mp(0ll, s));
while (sz(q)) {
int v = q.top().f, w = q.top().s;
if (Bad && v == f)
return D[f];
q.pop();
if (w != D[v])
continue;
for (auto X : g[j][v]) {
int to = X.f, i = X.s;
if (i != Bad && D[to] > D[v] + c[i]) {
D[to] = D[v] + c[i];
p[to] = i;
q.push(mp(D[to], to));
}
}
}
if (!Bad) {
for (int i = 1; i <= n; ++i)
if (p[i] > -1)
I[p[i]] = 1;
}
return D[f];
}
main () {
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; ++i) {
scanf("%d%d%d%d", &a[i], &b[i], &c[i], &d[i]);
g[0][a[i]].pb({b[i], i});
g[1][b[i]].pb({a[i], i});
}
Floyd();
Dijkstra(1, n, 0);
Dijkstra(n, 1, 0);
Dijkstra(1, n, 1);
Dijkstra(n, 1, 1);
ll ans = min(INF, F[1][n] + F[n][1]);
for (int i = 1; i <= m; ++i) {
if (I[i]) {
Bad = i;
g[0][b[i]].pb({a[i], m + 1});
c[m + 1] = c[i];
ans = min(ans, Dijkstra(1, n, 0) + Dijkstra(n, 1, 0) + d[i]);
g[0][b[i]].ppb();
} else {
ll d1 = min(F[1][n], F[1][b[i]] + F[a[i]][n] + c[i]);
ll d2 = min(F[n][1], F[n][b[i]] + F[a[i]][1] + c[i]);
ans = min(ans, d1 + d2 + d[i]);
}
}
if (ans == INF)
ans = -1;
printf("%lld\n", ans);
}
컴파일 시 표준 에러 (stderr) 메시지
ho_t4.cpp:104:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main () {
^
ho_t4.cpp: In function 'int main()':
ho_t4.cpp:105:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &m);
~~~~~^~~~~~~~~~~~~~~~
ho_t4.cpp:107:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d%d", &a[i], &b[i], &c[i], &d[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |