#include #include #include #include #include using namespace std; const int MAXN=222; const long long INF=100100100100LL; struct cell { int x,y; cell() {} cell(int _x,int _y) { x=_x; y=_y; } }; struct inQ { cell x; long long y; bool operator < (const inQ &el)const { return el.y v[MAXN][MAXN]; priority_queue Queue; cell current,ncell; int a,b; void read() { freopen("party.in","r",stdin); freopen("party.out","w",stdout); int i,j; int w,x,y,z; scanf("%d%d%d",&n,&p,&k); for(i=1;i<=n;i++) for(j=1;j<=n;j++) scanf("%d",&h[i][j]); scanf("%d%d",&a,&b); for(i=1;i<=p;i++) { scanf("%d%d%d%d",&w,&x,&y,&z); v[w][x].push_back(party(y,z)); } for(i=1;i<=k;i++) { scanf("%d%d",&x,&y); sh[x][y]=1; } } bool cmp(party el1,party el2) { return el1.sn)return 0; if(el.y<1||el.y>n)return 0; return 1; } void dj(int cakes) { int i,j; long long cost; inQ el,el1; for(i=1;i<=n;i++) for(j=1;j<=n;j++) dist[i][j]=INF; dist[a][b]=0; el.x=cell(a,b); el.y=0; Queue.push(el); while(!Queue.empty()) { el=Queue.top(); current=el.x; Queue.pop(); if(el.y!=dist[current.x][current.y])continue; ncell=current; ncell.x++; cost=(delta(current,ncell)+cakes)*(delta(current,ncell)+cakes)+1; if(ok(ncell)&& el.y+cost %d %d %lld\n",current.x,current.y,el.y,ncell.x,ncell.y,el1.y); Queue.push(el1); } ncell=current; ncell.x--; cost=(delta(current,ncell)+cakes)*(delta(current,ncell)+cakes)+1; if(ok(ncell)&& el.y+cost %d %d %lld\n",current.x,current.y,el.y,ncell.x,ncell.y,el1.y); Queue.push(el1); } ncell=current; ncell.y++; cost=(delta(current,ncell)+cakes)*(delta(current,ncell)+cakes)+1; if(ok(ncell)&& el.y+cost %d %d %lld\n",current.x,current.y,el.y,ncell.x,ncell.y,el1.y); Queue.push(el1); } ncell=current; ncell.y--; cost=(delta(current,ncell)+cakes)*(delta(current,ncell)+cakes)+1; if(ok(ncell)&& el.y+cost %d %d %lld\n",current.x,current.y,el.y,ncell.x,ncell.y,el1.y); Queue.push(el1); } } } party upcoming(int x,int y,long long mom) { int l,r,mid; party ans; ans.d=0; l=0; r=v[x][y].size()-1; while(l<=r) { mid=(l+r)/2; if(v[x][y][mid].s+v[x][y][mid].d>mom) { ans=v[x][y][mid]; r=mid-1; } else l=mid+1; } return ans; } void travel(int x,int y,int cakes) { long long cost; //printf("@%d %d\n",x,y); if(x==a&&y==b)return; current=cell(x,y); ncell=cell(x+1,y); cost=(delta(current,ncell)+cakes)*(delta(current,ncell)+cakes)+1; if(ok(ncell)&&dist[ncell.x][ncell.y]+cost==dist[x][y]) { travel(ncell.x,ncell.y,cakes); printf("U"); return; } ncell=cell(x-1,y); cost=(delta(current,ncell)+cakes)*(delta(current,ncell)+cakes)+1; if(ok(ncell)&&dist[ncell.x][ncell.y]+cost==dist[x][y]) { travel(ncell.x,ncell.y,cakes); printf("D"); return; } ncell=cell(x,y+1); cost=(delta(current,ncell)+cakes)*(delta(current,ncell)+cakes)+1; if(ok(ncell)&&dist[ncell.x][ncell.y]+cost==dist[x][y]) { travel(ncell.x,ncell.y,cakes); printf("L"); return; } current=cell(x,y); ncell=cell(x,y-1); cost=(delta(current,ncell)+cakes)*(delta(current,ncell)+cakes)+1; if(ok(ncell)&&dist[ncell.x][ncell.y]+cost==dist[x][y]) { travel(ncell.x,ncell.y,cakes); printf("R"); return; } } void solve() { int i,j; int cakes=0; long long itr=0LL; long long score=0; party pr,opt; cell dest; long long curtime=0; for(i=1;i<=n;i++) for(j=1;j<=n;j++) sort(v[i][j].begin(),v[i][j].end(),cmp); while(1) { dj(cakes); //for(i=1;i<=n;i++) // for(j=1;j<=n;j++) // printf("%d %d %d %d %lld\n",a,b,i,j,dist[i][j]); opt.s=curtime; opt.d=0; for(i=1;i<=n;i++) for(j=1;j<=n;j++) { //printf("!%d %d %lld\n",i,j,dist[i][j]); pr=upcoming(i,j,curtime+dist[i][j]); if(pr.d==0)continue; if(opt.d==0||pr.s+pr.d100100100)break; //break; } printf("\n"); } int main() { read(); solve(); }