이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <array>
#include <queue>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
const ll inf = 1e17;
int edges[50000][4];
vector<pair<int, ll>> v[200];
ll dis[50000];
bool bl[50000];
void vclear(){ for(int i = 0; i < 200; i++) v[i].clear(); }
void clear(){
for(int i = 0; i < 50000; i++) dis[i] = inf, bl[i] = 0;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m; cin >> n >> m;
for(int i = 0; i < m; i++){
cin >> edges[i][0] >> edges[i][1] >> edges[i][2] >> edges[i][3];
edges[i][0]--, edges[i][1]--;
}
ll ans = inf;
for(int tt = 0; tt <= m; tt++){
vclear();
ll cur = 0;
for(int i = 0; i < m; i++){
if(tt == i){
v[edges[i][1]].pb({edges[i][0], edges[i][2]});
cur+=edges[i][3];
}
else{
v[edges[i][0]].pb({edges[i][1], edges[i][2]});
}
}
priority_queue<pair<ll, int>> pq;
clear();
dis[0] = 0;
pq.push({0, 0});
while(!pq.empty()){
int nd = pq.top().sc; pq.pop();
if(bl[nd]) continue;
bl[nd] = 1;
for(auto [x, w]: v[nd]) if(dis[nd]+w < dis[x]){
dis[x] = dis[nd]+w;
pq.push({-dis[x], x});
}
}
cur+=dis[n-1];
cur = min(cur, inf);
clear();
dis[n-1] = 0;
pq.push({0, n-1});
while(!pq.empty()){
int nd = pq.top().sc; pq.pop();
if(bl[nd]) continue;
bl[nd] = 1;
for(auto [x, w]: v[nd]) if(dis[nd]+w < dis[x]){
dis[x] = dis[nd]+w;
pq.push({-dis[x], x});
}
}
cur+=dis[0];
ans = min(ans, cur);
}
if(ans >= inf) ans = -1;
cout << ans << "\n";
}
# | 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... |