#include #include using namespace std; using namespace atcoder; using ll=long long; ll inf=1000000000000000001; struct warp{ ll x1,x2,y1,y2; warp(){} warp(ll x1,ll y1,ll x2,ll y2):x1(x1),y1(y1),x2(x2),y2(y2){}; }; struct edge{ int from,to; ll w; edge(){} edge(int f,int t,ll w):from(f),to(t),w(w){} }; int main() { ll h,w; int n; cin>>h>>w>>n; vector warps(n); for(int i=0;i>a>>b>>c>>d; warps[i]=warp(a,b,c,d); } vector> graph(2*n+2); auto f=[](ll x1,ll y1,ll x2,ll y2)->ll{ return abs(x2-x1)+abs(y2-y1); }; graph[0].push_back(edge(0,2*n+1,h+w-2)); for(int i=0;i distance(2*n+2,inf); using pli=pair; priority_queue,greater> pq; pq.push(make_pair(0,0)); while(!pq.empty()){ auto [c,p]=pq.top(); pq.pop(); if(distance[p]