제출 #1237122

#제출 시각아이디문제언어결과실행 시간메모리
1237122PlayVoltzRobot (JOI21_ho_t4)C++20
100 / 100
173 ms28176 KiB
#include <cstdio>
#include <stdio.h>
#include <stdbool.h>
#include <iostream>
#include <map>
#include <vector>
#include <climits>
#include <stack>
#include <string>
#include <queue>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <cctype>
#include <bitset>
#include <iomanip>
#include <cstring>
#include <numeric>
#include <cassert>
#include <random>
#include <chrono>
#include <fstream>
using namespace std;

#define int long long
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second

struct trio{
	int to, t, c;
};

int32_t main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, m, a, b, c, d;
	cin>>n>>m;
	vector<vector<trio> > graph(n+1);
	for (int i=0; i<m; ++i){
		cin>>a>>b>>c>>d;
		graph[a].pb({b, c, d});
		graph[b].pb({a, c, d});
	}
	vector<int> dj(n+1, LLONG_MAX/2), sum(m+1), mn(m+1);
	priority_queue<pii, vector<pii>, greater<pii> > pq;
	pq.push(mp(0, 1));
	while (pq.size()){
		int d=pq.top().fi, node=pq.top().se;
		pq.pop();
		if (d>=dj[node])continue;
		dj[node]=d;
		map<int, int> m;
		for (auto num:graph[node])sum[num.t]=0, mn[num.t]=LLONG_MAX/2;
		for (auto num:graph[node])sum[num.t]+=num.c, mn[num.t]=min(mn[num.t], dj[num.to]);
		for (auto num:graph[node])pq.push(mp(min({d+num.c, d+sum[num.t]-num.c, mn[num.t]+sum[num.t]-num.c}), num.to));
	}
	cout<<(dj[n]==LLONG_MAX/2?-1:dj[n]);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...