Submission #972140

#TimeUsernameProblemLanguageResultExecution timeMemory
972140boyliguanhanRobot (JOI21_ho_t4)C++17
100 / 100
1424 ms141160 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define PB push_back #define djik(a,b,w) if(dis[a][b]>w)pq.push({dis[a][b]=w,a,b}) #define M 7<<14 vector<int> N[M],E[M],P[M],C[M],dis[M]; map<int,int>mp[M]; map<int,set<pair<int,int>>>mp2[M]; signed main(){ cin.tie(0)->sync_with_stdio(0); int n,m; cin>>n>>m; for(int i=1;i<=n;i++) N[i].PB(0),E[i].PB(0),C[i].PB(0),P[i].PB(0),dis[i].PB(1e18); dis[1][0]=0; while(m--){ int a,b,c,d; cin>>a>>b>>c>>d; mp[a][c]+=d; mp[b][c]+=d; dis[a].PB(1e18); dis[b].PB(1e18); E[a].PB(size(P[b])); E[b].PB(size(P[a])); P[a].PB(d),P[b].PB(d); N[a].PB(b),N[b].PB(a); mp2[b][c].insert({d,size(C[b])}); mp2[a][c].insert({d,size(C[a])}); C[a].PB(c),C[b].PB(c); } priority_queue<tuple<int,int,int>,vector<tuple<int,int,int>>,greater<>>pq; pq.push({0,1,0}); while(pq.size()){ auto[w,x,e]=pq.top(); pq.pop(); if(dis[x][e]<w) continue; djik(x,0,w); if(e){ if(mp[x][C[x][e]]==P[x][e]) continue; int y=(--mp2[x][C[x][e]].end())->second; if(y==e) y=prev(--mp2[x][C[x][e]].end())->second; djik(N[x][y],0,w+mp[x][C[x][e]]-P[x][e]-P[x][y]); } else { for(int i=1;i<P[x].size();i++) { djik(N[x][i],E[x][i],w+P[x][i]); djik(N[x][i],0,w+mp[x][C[x][i]]-P[x][i]); } } } cout<<(dis[n][0]<1e18?dis[n][0]:-1); }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:48:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |             for(int i=1;i<P[x].size();i++) {
      |                         ~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...