Submission #248605

#TimeUsernameProblemLanguageResultExecution timeMemory
248605tleontest1Olympic Bus (JOI20_ho_t4)C++17
0 / 100
44 ms896 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],yasak,mn,ans1,ans2,cev,d[li]; 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(int ii){ priority_queue<PII> pq; pq.push({0,ii}); FOR vis[i]=0; ans1=-1; ans2=-1; while(pq.size()){ int co=-pq.top().fi; int node=pq.top().se; pq.pop(); if(vis[node])continue; vis[node]=1; if(node==1)ans1=co; if(node==n)ans2=co; for(int i=0;i<(int)v[node].size();i++){ if(v[node][i].se.se.se==yasak && v[node][i].se.se.fi==0)continue; if(v[node][i].se.se.se!=yasak && v[node][i].se.se.fi==1)continue; pq.push({-co-v[node][i].se.fi,v[node][i].fi}); } } } 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,{1,i}}}); } int ans=inf; for(int i=1;i<=n;i++){ yasak=i; sp(1); if(ans2==-1)continue; cev=ans2; sp(n); if(ans1==-1)continue; cev+=ans1; cev+=d[i]; ans=min(ans,cev); } yasak=0; sp(1); if(ans2!=-1){ cev=ans2; sp(n); if(ans1!=-1){ cev+=ans1; ans=min(ans,cev); } } if(ans==inf)ans=-1; printf("%lld\n",ans); return 0; }

Compilation message (stderr)

ho_t4.cpp:112: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:113: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:116: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...