제출 #1036075

#제출 시각아이디문제언어결과실행 시간메모리
1036075HNa_seawjingRobot (JOI21_ho_t4)C++14
0 / 100
54 ms41404 KiB
#include <bits/stdc++.h> //code #define fl(i,x,y,z) for(int i=x;i<=y;i=i+z) #define fn(i,x,y,z) for(int i=x;i>=y;i=i-z) #define rep(i,x,y) for(int i=x;i<y;i=i+1) #define all(v) v.begin(),v.end() #define pb push_back #define tle cout<<"tle"<<endl #define edl cout<<"\n" #define el "\n" #define getbit(x,i) ((x>>i)&1) #define bitcnt __builtin_popcount //ham #define pii pair<long long,long long> #define fi first #define se second #define ll long long #define ld long double #define inf 0x3f3f3f3f #define int long long using namespace std; const ll mod=1e9+7; int n,m; struct kb { int v,c,p; }; vector <pair<int,pii>> e[100005]; vector <pii> a[100005]; int vis[1000005],t[1000005]; ll d[1000005]; priority_queue <pii,vector <pii>, greater <pii>> q; void inp() { cin>>n>>m; fl(i,1,m,1) { int u,v,c,p; cin>>u>>v>>c>>p; e[u].pb({v,{c,p}}); e[v].pb({u,{c,p}}); a[u].pb({v,p}); a[v].pb({u,p}); } } void dij() { fl(i,1,n,1) d[i]=1e18; d[1]=0; q.push({d[1],1}); while (!q.empty()) { int u=q.top().se; int c=q.top().fi; q.pop(); if (c<d[u]) continue; for (auto it: a[u]) { int v=it.fi,w=it.se; if (d[v]>d[u]+w) { d[v]=d[u]+w; q.push({d[v],v}); } } } if (d[n]==1e18) cout<<-1; else cout<< d[n]; } void sol() { int cur = n; fl(i,1,n,1) { sort(e[i].begin(), e[i].end()); for (auto it : e[i]) t[it.fi] += it.se.se; for (auto it : e[i]) { if (!vis[it.fi]) { ++cur; a[i].push_back({cur,0}); } vis[it.fi]=1; a[cur].push_back({it.se.fi, t[it.fi]-it.se.se}); a[it.se.fi].push_back({cur, 0}); } for (auto it : e[i]) { t[it.fi] = 0; vis[it.fi] = 0; } } dij(); } signed main() { // freopen("task.inp","r",stdin); // freopen("task.out","w",stdout); ios_base::sync_with_stdio(false); cin.tie(NULL); inp(); sol(); return 0; } /* /\_/\ ( ._. ) / >V< \ */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...