이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define Task "PATHLIB"
#define ll long long
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FOD(i, a, b) for (int i = (a); i >= (b); i--)
#define F first
#define S second
typedef pair<int, int> ii;
typedef pair<ll, int> li;
const int N = 2e5 + 6;
const int INF = 1e9;
const int MOD = 1e9 + 7;
template<class X, class Y>
bool minimize(X &x, Y y) {
if (x > y) {
x = y;
return true;
} else return false;
}
template<class X, class Y>
bool maximize(X &x, Y y) {
if (x < y) {
x = y;
return true;
} else return false;
}
int numNode, numEdge;
int startSchool, endSchool;
int startLibrary, endLibrary;
vector<ii> adj[N];
map<int, bool> isChange[N];
int trace[N];
ll dijkstra(int s, int e) {
priority_queue<li, vector<li>, greater<li>> pq;
pq.push({0, s});
vector<ll> dist(numNode + 1, (ll)1e18);
dist[s] = 0;
trace[s] = -1;
while (!pq.empty()) {
int u = pq.top().S, du = pq.top().F;
pq.pop();
if (u == e) return du;
if (dist[u] < du) continue;
for (auto e : adj[u]) {
int v = e.F, c = e.S;
if (dist[v] > dist[u] + c) {
dist[v] = dist[u] + c;
pq.push({dist[v], v});
trace[v] = u;
}
}
}
return -1;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if (fopen(Task".INP", "r")) {
freopen(Task".INP", "r", stdin);
freopen(Task".OUT", "w", stdout);
}
cin >> numNode >> numEdge;
cin >> startSchool >> endSchool;
cin >> startLibrary >> endLibrary;
FOR(i, 1, numEdge) {
int u, v, c;
cin >> u >> v >> c;
adj[u].push_back({v, c});
adj[v].push_back({u, c});
}
ll cost = dijkstra(startSchool, endSchool);
int node = endSchool;
while (trace[node] != -1) {
isChange[node][trace[node]] = isChange[trace[node]][node] = 1;
node = trace[node];
}
FOR(u, 1, numNode)
for (auto &e : adj[u]) {
int v = e.F;
if (isChange[u][v]) e.S = 0;
}
cout << dijkstra(startLibrary, endLibrary);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:83:8: warning: unused variable 'cost' [-Wunused-variable]
83 | ll cost = dijkstra(startSchool, endSchool);
| ^~~~
commuter_pass.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".INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:70:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
70 | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |