이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb emplace_back
#define sz(x) (int)x.size()
#define mnto(x,y) x=min(x,(__typeof__(x))y)
#define mxto(x,y) x=max(x,(__typeof__(x))y)
#define INF 1023456789
#define LINF 1023456789123456789
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef vector<int> vi;
typedef vector<ii> vii;
mt19937 rng(time(0));
int n,m,a,b,c,d,cnt;
ll tot[500005],dist[500005];
map<ii,int> mp;
vector<iii> AL[500005];
priority_queue<li,vector<li>,greater<li>> pq;
void add(int a,int b,int c,int d){
if(!mp.count({a,c})){
AL[a].push_back({cnt,0,0});
mp[{a,c}]=cnt++;
}
int z=mp[{a,c}];
AL[z].push_back({b,c,d});
tot[z]+=d;
}
void up(int v,ll d){
if(dist[v]<=d)return;
dist[v]=d;
pq.push({dist[v],v});
}
int main(){
sf("%d%d",&n,&m);
cnt=n;
for(int i=0;i<m;++i){
sf("%d%d%d%d",&a,&b,&c,&d);
--a;--b;
add(a,b,c,d);
add(b,a,c,d);
}
for(int i=0;i<cnt;++i)dist[i]=LINF;
dist[0]=0;
pq.push({dist[0],0});
while(!pq.empty()){
ll d;int u;tie(d,u)=pq.top();pq.pop();
if(d>dist[u])continue;
if(u<n){
for(iii t:AL[u]){
int v,c,w;tie(v,c,w)=t;
for(iii t2:AL[v]){
int v2,c2,w2;tie(v2,c2,w2)=t2;
up(v2,d+min((ll)w2,tot[v]-w2));
up(mp[{v2,c2}],d);
}
}
}
else{
for(iii t:AL[u]){
int v,c,w;tie(v,c,w)=t;
up(v,d+tot[u]-w);
}
}
}
if(dist[n-1]==LINF)dist[n-1]=-1;
pf("%lld\n",dist[n-1]);
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int main()':
Main.cpp:48:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
48 | sf("%d%d",&n,&m);
| ^
Main.cpp:51:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
51 | sf("%d%d%d%d",&a,&b,&c,&d);
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |