Submission #445604

#TimeUsernameProblemLanguageResultExecution timeMemory
445604jamezzzRobot (JOI21_ho_t4)C++17
58 / 100
3070 ms53516 KiB
#include <bits/stdc++.h>
using namespace std;

#define DEBUG

#ifdef DEBUG
#define debug(...) printf(__VA_ARGS__);
#else
#define debug(...)
#endif
#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++;
	}
	AL[mp[{a,c}]].push_back({b,c,d});
	tot[mp[{a,c}]]+=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;
	for(int i=0;i<cnt;++i){
		for(iii t:AL[i]){
			int v,c,w;tie(v,c,w)=t;
		}
	}
	dist[0]=0;
	pq.push({dist[0],0});
	while(!pq.empty()){
		ll d;int u;tie(d,u)=pq.top();pq.pop();
		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]);
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:54:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |  sf("%d%d",&n,&m);
      |    ^
Main.cpp:57:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |   sf("%d%d%d%d",&a,&b,&c,&d);
      |     ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...