이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define mp make_pair
const int INF=1e18;
struct edge{
int to,c,p;
edge(){}
edge(int a,int b,int c1){
to=a,c=b,p=c1;
}
};
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n,m;cin>>n>>m;
vector<vector<edge>> adj1(n);
vector<vector<pair<int,int>>> adj(n);
vector<map<int,int>> cnt(n);
for(int i=0;i<m;i++){
int a,b,c,d;cin>>a>>b>>c>>d;
a--;b--;
adj1[a].push_back(edge(b,c,d));
adj1[b].push_back(edge(a,c,d));
cnt[a][c]+=d;
cnt[b][c]+=d;
}
for(int i=0;i<n;i++){
for(edge &e:adj1[i]){
adj[i].push_back({e.to,min(e.p,cnt[i][e.c]-e.p)});
}
}
priority_queue<pii,vector<pii>,greater<pii>> pq;
vector<bool> vis(n);
vector<int> dis(n,INF);
pq.push({0,0});
while(pq.size()){
int a,b;
tie(a,b)=pq.top();
pq.pop();
if(vis[b]){
continue;
}
vis[b]=1;
for(pair<int,int> p:adj[b]){
if(dis[p.first]>a+p.second){
dis[p.first]=a+p.second;
pq.push({dis[p.first],p.first});
}
}
}
if(dis[n-1]==INF){
cout<<-1<<endl;
}
else{
cout<<dis[n-1]<<endl;
}
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... |