이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <stack>
#include <unordered_map>
using namespace std;
typedef long long ll;
struct path {
vector<ll> way;
ll cost;
ll v;
path(){}
path(ll cost): cost(cost){}
};
bool operator>(path a, path b) {
return a.cost > b.cost;
}
path dijkstra(ll start, ll end, vector<vector<pair<ll, ll>>> graf) {
ll n = graf.size() - 1;
vector<bool> vis(n + 1);
vector<path> odw(n + 1, path(-1));
priority_queue<path, vector<path>, greater<path>> q;
path p;
p.v = start;
p.cost = 0;
p.way = {};
q.push(p);
while(!q.empty()) {
path el = q.top();
q.pop();
vis[el.v] = true;
for(pair<ll, ll> sas : graf[el.v]) {
if(vis[sas.first]) continue;
path n;
n.cost = sas.second;
n.v = sas.first;
n.way = el.way;
n.way.push_back(el.v);
q.push(n);
odw[n.v].cost = el.cost + sas.second;
odw[n.v].way = el.way;
odw[n.v].way.push_back(el.v);
}
}
return odw[end];
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n, m; cin >> n >> m;
ll s, t; cin >> s >> t;
ll u, v; cin >> u >> v;
vector<vector<pair<ll,ll>>> graf(n + 1);
for(int i = 0; i < m; i++) {
ll a, b, c; cin >> a >> b >> c;
graf[a].push_back({b, c});
graf[b].push_back({a, c});
}
vector<ll> stway = dijkstra(s, t, graf).way;
vector<pair<ll, ll>> kraw0;
for(int i = 0; i < n - 1; i++) {
kraw0.push_back({stway[i], stway[i + 1]});
}
for(int x = 0; x < n; x++) {
for(int y = 0; y < graf[x].size(); y++) {
for(pair<ll, ll> p : kraw0) {
if (p.first == x && p.second == graf[x][y].first) {
graf[x][y].second = 0;
} else if(p.second == x && p.first == graf[x][y].first) {
graf[x][y].second = 0;
}
}
}
}
ll w = dijkstra(u, v, graf).cost;
cout << w;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:78:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | for(int y = 0; y < graf[x].size(); y++) {
| ~~^~~~~~~~~~~~~~~~
# | 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... |