이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long int lld;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define trav(a,v) for(auto a:v)
lld inp[1000000][4];
const lld INF=1e18;
void solve(){
int n,m;
cin>>n>>m;
map<pair<int,int>,lld> M;
rep(i,0,m){
rep(j,0,4)cin>>inp[i][j];
inp[i][0]--;
inp[i][1]--;
M[{inp[i][0],inp[i][2]}]+=inp[i][3];
M[{inp[i][1],inp[i][2]}]+=inp[i][3];
}
vector<vector<pair<int,lld> > >nei(n);
rep(i,0,m){
nei[inp[i][0]].push_back({inp[i][1],min(inp[i][3],M[{inp[i][0],inp[i][2]}]-inp[i][3])});
nei[inp[i][1]].push_back({inp[i][0],min(inp[i][3],M[{inp[i][1],inp[i][2]}]-inp[i][3])});
}
vector<lld> dist(n,INF);
dist[0]=0;
priority_queue<pair<lld,int> >pq;
pq.push({0,0});
while(!pq.empty()){
lld d=-pq.top().first;
int v=pq.top().second;
pq.pop();
if(d>dist[v])continue;
trav(u,nei[v]){
if(dist[u.first]>u.second+d){
dist[u.first]=u.second+d;
pq.push({-dist[u.first],u.first});
}
}
}
if(dist[n-1]<INF)cout<<dist[n-1]<<"\n";
else cout<<"-1\n";
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int tt=1;
//cin>>tt;
while(tt--){
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |