이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN = 1e5 + 2;
int n, m;
bool check[MAXN] = {false};
int val[MAXN] = {0};
vector <pair <int, pair <int, int> > > vt[MAXN];
unordered_map <int, int> ump[MAXN];
map <int, int> mp[MAXN];
void Dijkstra() {
priority_queue <pair <int, int>, vector <pair <int, int> >, greater <pair <int, int> > > pq;
pq.push(make_pair(0, 0));
while(pq.empty() == false) {
pair <int, int> u = pq.top();
pq.pop();
if(check[u.second] == true) {
continue;
} else {
check[u.second] = true;
}
val[u.second] = u.first;
for(int i = 0; i < (int)(vt[u.second].size()); i++) {
pair <int, pair <int, int> > x = vt[u.second][i];
if(mp[x.first].find(x.second.first) == mp[x.first].end()) {
mp[x.first][x.second.first] = u.first;
}
int temp = u.first;
map <int, int> :: iterator it = mp[u.second].find(x.second.first);
if(it != mp[u.second].end()) {
temp = it->second;
}
pq.push(make_pair(min(temp + ump[u.second][x.second.first] - x.second.second, u.first + x.second.second), x.first));
}
}
return;
}
void programme() {
// input:
cin >> n >> m;
for(int i = 0; i < m; i++) {
int a, b, c, d;
cin >> a >> b >> c >> d;
a--;
b--;
ump[a][c] += d;
ump[b][c] += d;
vt[a].push_back({b,{c,d}});
vt[b].push_back({a,{c,d}});
}
// solve:
Dijkstra();
// output:
if(check[n - 1] == false) {
printf("-1\n");
} else {
cout << val[n-1] << "\n";
}
return;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
// freopen("_mint.inp", "r", stdin);
// freopen("_mint.out", "w", stdout);
programme();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |