이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define For(i,a,b) for(int i = a; i <= b; i++)
#define Ford(i,a,b) for(int i = a; i >= b; i--)
#define ll long long
#define ii pair<ll,ll>
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define RRH(v) v.resize(unique(all(v)) - v.begin())
using namespace std;
const int N = 1e6+7;
const int M = 1e9+7;
const ll oo = 1e18;
int n, m;
ll d[N], d2[N];
struct data {
int v, c, p;
};
vector<data> g[N];
void dij() {
For (i, 2, n) d[i] = oo;
d[1] = 0;
priority_queue<ii, vector<ii>, greater<ii>> q;
q.push({0ll, 1});
while (q.size() > 0) {
ii k = q.top();
q.pop();
if (d[k.se] != k.fi) continue;
unordered_map<ll,ll> ma, min_c;
for (auto x: g[k.se]) min_c[x.c] = oo;
for (auto x: g[k.se]) {
ma[x.c] += x.p;
min_c[x.c] = min(min_c[x.c], d[x.v]);
}
for (auto x: g[k.se]) {
if (d[x.v] > k.fi + x.p) {
d[x.v] = k.fi + x.p;
q.push({d[x.v], x.v});
}
if (d[x.v] > k.fi + ma[x.c] - x.p) {
d[x.v] = d[k.fi] + ma[x.c] - x.p;
q.push({d[x.v], x.v});
}
if (d[x.v] > min_c[x.c] + ma[x.c] - x.p) {
d[x.v] = min_c[x.c] + ma[x.c] - x.p;
q.push({d[x.v], x.v});
}
}
}
if (d[n] >= oo) d[n] = -1;
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
#define TASK ""
if (fopen (".inp", "r")) {
freopen (".inp", "r", stdin);
freopen (".out", "w", stdout);
}
if(fopen(TASK".inp", "r")) {
freopen(TASK".inp", "r", stdin);
freopen(TASK".out", "w", stdout);
}
cin >> n >> m;
For (i, 1, m) {
int u, v, c, p; cin >> u >> v >> c >> p;
g[u].push_back({v, c, p});
g[v].push_back({u, c, p});
}
dij();
cout << d[n] << '\n';
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int main()':
Main.cpp:64:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
64 | freopen (".inp", "r", stdin);
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~
Main.cpp:65:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
65 | freopen (".out", "w", stdout);
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
Main.cpp:68:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
68 | freopen(TASK".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:69:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
69 | freopen(TASK".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |