Submission #248984

#TimeUsernameProblemLanguageResultExecution timeMemory
248984tleontest1Olympic Bus (JOI20_ho_t4)C++17
0 / 100
1084 ms262148 KiB
#include <bits/stdc++.h> using namespace std; typedef long long lo; typedef pair< lo,lo > PII; typedef pair< lo,PII > PIII; typedef pair< lo,PIII > PIIII; typedef pair< lo,PIIII > PIIIII; typedef pair< lo,PIIIII > PIIIIII; #define fi first #define se second #define mp make_pair #define endl "\n" #define pb push_back #define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define FOR for(int i=1;i<=n;i++) #define mid ((start+end)/2) #define ort ((bas+son)/2) #define int long long const lo inf = 1000000000000000000; const lo KOK = 100000; const lo LOG = 30; const lo li = 203; const lo mod = 1000000007; int n,m,b[li],a[li],k,flag,t,val[li],vis[li][4][4],mn,ans=inf,d[50005],visit[50005],visit1[50005],vis1[205][50005]; string s; vector<PIIII> v[li]; //~ inline void sp2(){ //~ priority_queue<PIIIII> pq; //~ pq.push({0,{n,{0,{0,0}}}}); //~ FOR vis[i][0]=0; //~ FOR vis[i][1]=0; //~ mn=inf; //~ while(pq.size()){ //~ int co=-pq.top().fi; //~ int node=pq.top().se.fi; //~ int hak=pq.top().se.se.fi; //~ int xx=pq.top().se.se.se.fi; //~ int yy=pq.top().se.se.se.se; //~ pq.pop(); //~ if(vis[node][hak])continue; //~ vis[node][hak]=1; //~ if(node==1)mn=min(mn,co); //~ for(int i=0;i<(int)v[node].size();i++){ //~ int go=v[node][i].fi; //~ if(node==xx && go==yy)continue; //~ if(v[node][i].se.se==0)pq.push({-co-v[node][i].se.fi,{go,{hak,{xx,yy}}}}); //~ else{ //~ if(hak)continue; //~ pq.push({-co-v[node][i].se.fi,{go,{1,{go,node}}}}); //~ } //~ } //~ } //~ } //~ inline void sp3(int xxx,int yyy){ //~ priority_queue<PIIIII> pq; //~ pq.push({0,{n,{1,{xxx,yyy}}}}); //~ FOR vis[i][0]=0; //~ FOR vis[i][1]=0; //~ mn=inf; //~ while(pq.size()){ //~ int co=-pq.top().fi; //~ int node=pq.top().se.fi; //~ int hak=pq.top().se.se.fi; //~ int xx=pq.top().se.se.se.fi; //~ int yy=pq.top().se.se.se.se; //~ pq.pop(); //~ if(vis[node][hak])continue; //~ vis[node][hak]=1; //~ if(node==1)mn=min(mn,co); //~ cout<<xx<<" : : "<<yy<<endl; //~ for(int i=0;i<(int)v[node].size();i++){ //~ int go=v[node][i].fi; //~ if(node==xx && go==yy)continue; //~ if(v[node][i].se.se==0)pq.push({-co-v[node][i].se.fi,{go,{hak,{xx,yy}}}}); //~ else{ //~ if(hak)continue; //~ pq.push({-co-v[node][i].se.fi,{go,{1,{go,node}}}}); //~ } //~ } //~ } //~ } inline void sp(){ priority_queue<PIIIII> pq; pq.push({0,{1,{0,{0,0}}}}); //~ int val1=-1,val2=-1; //~ int stx=0,sty=0; ans=inf; while(pq.size()){ int co=-pq.top().fi; int node=pq.top().se.fi; int hak=pq.top().se.se.fi; int xx=pq.top().se.se.se.fi; //~ int yy=pq.top().se.se.se.se.fi; int gel=pq.top().se.se.se.se; pq.pop(); //~ cout<<node<<" : : "<<gel<<" : : "<<xx<<" : : "<<hak<<" : : "<<co<<endl; if(vis[node][hak][gel])continue; if(node==n && visit[xx]==0)continue; if(gel==1 && node==1)ans=min(ans,co); vis[node][hak][gel]=1; for(int i=0;i<(int)v[node].size();i++){ int go=v[node][i].fi; if(v[node][i].se.se.se==xx && v[node][i].se.se.fi==0)continue; if(v[node][i].se.se.se==xx && v[node][i].se.se.fi==1){ pq.push({-co-v[node][i].se.fi+d[v[node][i].se.se.se],{go,{hak,{xx,(node==n?1:gel)}}}}); continue; } //~ if(node==yy && go==xx){ //~ pq.push({-co-v[node][i].se.fi,{go,{hak,{xx,{yy,(node==n?1:gel)}}}}}); //~ continue; //~ } if(v[node][i].se.se.fi==0)pq.push({-co-v[node][i].se.fi,{go,{hak,{xx,(node==n?1:gel)}}}}); else{ if(hak)continue; if(gel==1 || node==n)continue; pq.push({-co-v[node][i].se.fi,{go,{1,{v[node][i].se.se.se,(node==n?1:gel)}}}}); } } } //~ cout<<ans<<endl; //~ if(ans>=inf)ans=-1; //~ printf("%lld\n",ans); } inline void sp1(){ priority_queue<PIIIII> pq; pq.push({0,{n,{0,{0,0}}}}); //~ int val1=-1,val2=-1; //~ int stx=0,sty=0; //~ ans=inf; memset(vis,0,sizeof(vis)); while(pq.size()){ int co=-pq.top().fi; int node=pq.top().se.fi; int hak=pq.top().se.se.fi; int xx=pq.top().se.se.se.fi; //~ int yy=pq.top().se.se.se.se.fi; int gel=pq.top().se.se.se.se; pq.pop(); //~ cout<<node<<" : : "<<gel<<" : : "<<xx<<" : : "<<hak<<" : : "<<co<<endl; if(vis[node][hak][gel])continue; if(node==1 && visit1[xx]==0)continue; if(gel==1 && node==n)ans=min(ans,co); vis[node][hak][gel]=1; for(int i=0;i<(int)v[node].size();i++){ int go=v[node][i].fi; if(v[node][i].se.se.se==xx && v[node][i].se.se.fi==0)continue; if(v[node][i].se.se.se==xx && v[node][i].se.se.fi==1){ pq.push({-co-v[node][i].se.fi+d[v[node][i].se.se.se],{go,{hak,{xx,(node==1?1:gel)}}}}); continue; } //~ if(node==yy && go==xx){ //~ pq.push({-co-v[node][i].se.fi,{go,{hak,{xx,{yy,(node==n?1:gel)}}}}}); //~ continue; //~ } if(v[node][i].se.se.fi==0)pq.push({-co-v[node][i].se.fi,{go,{hak,{xx,(node==1?1:gel)}}}}); else{ if(hak)continue; if(gel==1 || node==1)continue; pq.push({-co-v[node][i].se.fi,{go,{1,{v[node][i].se.se.se,(node==1?1:gel)}}}}); } } } if(ans>=inf)ans=-1; printf("%lld\n",ans); } inline void sp2(){ priority_queue<PIIIII> pq; pq.push({0,{n,{0,{0,0}}}}); //~ int val1=-1,val2=-1; //~ int stx=0,sty=0; //~ ans=inf; //~ memset(vis,0,sizeof(vis)); while(pq.size()){ int co=-pq.top().fi; int node=pq.top().se.fi; int hak=pq.top().se.se.fi; int xx=pq.top().se.se.se.fi; //~ int yy=pq.top().se.se.se.se.fi; int gel=pq.top().se.se.se.se; pq.pop(); //~ cout<<node<<" : : "<<gel<<" : : "<<xx<<" : : "<<hak<<" : : "<<co<<endl; if(vis1[node][xx])continue; if(node==1){visit[xx]=1;continue;} vis1[node][xx]=1; for(int i=0;i<(int)v[node].size();i++){ int go=v[node][i].fi; if(v[node][i].se.se.se==xx && v[node][i].se.se.fi==0)continue; if(v[node][i].se.se.se==xx && v[node][i].se.se.fi==1){ pq.push({-co-v[node][i].se.fi+d[v[node][i].se.se.se],{go,{hak,{xx,(node==1?1:gel)}}}}); continue; } //~ if(node==yy && go==xx){ //~ pq.push({-co-v[node][i].se.fi,{go,{hak,{xx,{yy,(node==n?1:gel)}}}}}); //~ continue; //~ } if(v[node][i].se.se.fi==0)pq.push({-co-v[node][i].se.fi,{go,{hak,{xx,(node==1?1:gel)}}}}); else{ if(hak)continue; if(gel==1 || node==1)continue; pq.push({-co-v[node][i].se.fi,{go,{1,{v[node][i].se.se.se,(node==1?1:gel)}}}}); } } } //~ if(ans>=inf)ans=-1; //~ printf("%lld\n",ans); } inline void sp3(){ priority_queue<PIIIII> pq; pq.push({0,{n,{0,{0,0}}}}); //~ int val1=-1,val2=-1; //~ int stx=0,sty=0; //~ ans=inf; memset(vis1,0,sizeof(vis1)); while(pq.size()){ int co=-pq.top().fi; int node=pq.top().se.fi; int hak=pq.top().se.se.fi; int xx=pq.top().se.se.se.fi; //~ int yy=pq.top().se.se.se.se.fi; int gel=pq.top().se.se.se.se; pq.pop(); //~ cout<<node<<" : : "<<gel<<" : : "<<xx<<" : : "<<hak<<" : : "<<co<<endl; if(vis1[node][xx])continue; if(node==1){visit1[xx]=1;continue;} vis1[node][xx]=1; for(int i=0;i<(int)v[node].size();i++){ int go=v[node][i].fi; if(v[node][i].se.se.se==xx && v[node][i].se.se.fi==0)continue; if(v[node][i].se.se.se==xx && v[node][i].se.se.fi==1){ pq.push({-co-v[node][i].se.fi+d[v[node][i].se.se.se],{go,{hak,{xx,(node==1?1:gel)}}}}); continue; } //~ if(node==yy && go==xx){ //~ pq.push({-co-v[node][i].se.fi,{go,{hak,{xx,{yy,(node==n?1:gel)}}}}}); //~ continue; //~ } if(v[node][i].se.se.fi==0)pq.push({-co-v[node][i].se.fi,{go,{hak,{xx,(node==1?1:gel)}}}}); else{ if(hak)continue; if(gel==1 || node==1)continue; pq.push({-co-v[node][i].se.fi,{go,{1,{v[node][i].se.se.se,(node==1?1:gel)}}}}); } } } //~ if(ans>=inf)ans=-1; //~ printf("%lld\n",ans); } main(void){ scanf("%lld %lld",&n,&m); for(int i=1;i<=m;i++){ int x,y,z; scanf("%lld %lld %lld %lld",&x,&y,&z,&d[i]); v[x].pb({y,{z,{0,i}}}); v[y].pb({x,{z+d[i],{1,i}}}); } sp2(); sp3(); sp(); sp1(); return 0; }

Compilation message (stderr)

ho_t4.cpp:263:10: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(void){
          ^
ho_t4.cpp: In function 'int main()':
ho_t4.cpp:264:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld %lld",&n,&m);
  ~~~~~^~~~~~~~~~~~~~~~~~~
ho_t4.cpp:267:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld %lld %lld",&x,&y,&z,&d[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...