#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include #include using namespace std; using namespace atcoder; using ll=long long; using P=pair; void IO(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); } int main(){ IO(); ll h,w,n; cin>>h>>w>>n; vector a(n),b(n),c(n),d(n); for(ll i=0;i>a[i]>>b[i]>>c[i]>>d[i]; } vector> G(n+2,vector(n+2,-1)); for(ll i=0;i,greater

> que; que.push(P(0,0)); vector dist(n+2,1e18); dist[0]=0; while(que.size()){ P q=que.top(); que.pop(); ll x=q.first; ll y=q.second; for(ll i=0;i<=n+1;i++){ if(G[y][i]==-1){ continue; } if(dist[i]<=x+G[y][i]){ continue; } dist[i]=x+G[y][i]; que.push(P(x+G[y][i],i)); } } cout<