이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define f(i, l, r) for (int i = l; i <= r; i++)
#define debug(x) cout << #x << '=' << (x) << endl
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define ff first
#define ss second
using PLL = pair<ll, ll>;
using VL = vector<ll>;
using VLL = vector<pair<ll, ll>>;
// -------------------------------------------------------------------------------
constexpr int mod = 1e9 + 7;
void setIO(const string &name = "") {
ios_base::sync_with_stdio(0);
cin.tie(0);
if (sz(name)) {
freopen((name + ".in").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
}
}
// -------------------------------------------------------------------------------
// ------------------------Template End ------------------------------------------
// -------------------------------------------------------------------------------
struct Edge {
ll color, changePrice, to;
Edge(ll t, ll c, ll p) : color(c), changePrice(p), to(t) {
}
};
int main() {
setIO();
ll n, m;
cin >> n >> m;
vector<vector<Edge>> adj(n);
vector<map<ll, ll>> colorCount(n);
ll a, b, c, p;
for (int i = 0; i < m; i++) {
cin >> a >> b >> c >> p;
a--, b--;
adj[a].push_back(Edge(b, c, p));
adj[b].push_back(Edge(a, c, p));
colorCount[a][c] += p;
colorCount[b][c] += p;
}
priority_queue<pair<ll, ll>> pq;
vector<ll> dist(n, 1e18);
dist[0] = 0;
pq.push({0, 0});
ll distNow, node;
while (!pq.empty()) {
tie(distNow, node) = pq.top();
distNow = -distNow;
pq.pop();
if (dist[node] != distNow) continue;
for (auto edge: adj[node]) {
ll len = 0;
if (colorCount[node][edge.color] != edge.changePrice) {
len += min(edge.changePrice, colorCount[node][edge.color] - edge.changePrice);
}
if (dist[node] + len < dist[edge.to]) {
dist[edge.to] = dist[node] + len;
pq.push({-dist[edge.to], edge.to});
}
}
}
if (dist[n - 1] == 1e18) {
cout << "-1";
} else cout << dist[n - 1];
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'void setIO(const string&)':
Main.cpp:25:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
25 | freopen((name + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
26 | freopen((name + ".out").c_str(), "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... |