Sponsors

Codeforces Round #420 (Div. 2), problem: (D) Okabe and City Solution In C/C++

#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<cmath>
using namespace std;
const int maxn=1e4+5;
const int inf=0x7f7f7f7f;
int x[maxn],y[maxn],dis[maxn];
bool vis[maxn];
int k,n,m;
int bfs()
{
queue<int>q;
q.push(1);
//memset
//for(int i=1;i<=n;i++)dis[i]=inf;
memset(dis,0x7f,sizeof dis);
dis[1]=0;
vis[1]=true;
while(!q.empty())
{
int u;
u=q.front();q.pop();
for(int i=1;i<=k;i++)
{
if(u==i)continue;
int w=inf;
int l1=abs(x[i]-x[u]);
int l2=abs(y[i]-y[u]);
if(l1+l2<=1)w=0;
else if(l1<=2||l2<=2)w=1;
if(dis[i]>dis[u]+w)
{
dis[i]=dis[u]+w;
if(!vis[i])
{
vis[i]=true;q.push(i);
}
q.push(i);
}
}
vis[u]=0;

}
return dis[k]==inf?-1:dis[k];

}
int main()
{
scanf(“%d %d %d”,&n,&m,&k);
bool flag=false;
for(int i=1;i<=k;i++)
{
scanf(“%d %d”,&x[i],&y[i]);
flag|=(x[i]==n&&y[i]==m);
}
if(!flag)
{
x[++k]=n+1;y[k]=m+1;
}
printf(“%d\n”,bfs());
}

Squid Game: The Challenge’s...

Contestant 100 Reveals The Truth Behind Her 'Traumatizing Exit'...

Discussion on Covid Vaccination...

Why the Covid Vaccine Discussion Needs to Shed its...

ISC Declares Quarterly Dividend

Information Services Corporation Declares $0.23 Quarterly Dividend In a significant...

Electrolux 10kg Front Load...

Massive Deal Alert: Electrolux 10kg Front Loader EWF1042R9WC Slashed...

RFK Jr.’s top drug...

Top FDA Regulator Resigns Amid Scandal Involving 'Revenge Campaign' The...

National Guard, DC Police...

National Guard Deployed as Chaos Grips DC Navy Yard...

Squid Game: The Challenge’s Contestant 100 Talks About That ‘Really Traumatizing Exit’

Contestant 100 Reveals The Truth Behind Her 'Traumatizing Exit' from Squid Game: The Challenge Netflix’s reality competition hit, Squid Game: The Challenge, put its contestants...

Discussion on Covid Vaccination Should Be Non-Controversial

Why the Covid Vaccine Discussion Needs to Shed its Controversy In an age dominated by instantaneous news cycles and the constant pursuit of viral content,...

ISC Declares Quarterly Dividend

Information Services Corporation Declares $0.23 Quarterly Dividend In a significant announcement for its shareholders, Information Services Corporation (TSX:ISC), often referred to simply as "ISC," revealed...

Electrolux 10kg Front Load Washing Machine EWF1042R9WC $725 + Delivery ($0 to Selected Cities Only) @ Appliance Central

Massive Deal Alert: Electrolux 10kg Front Loader EWF1042R9WC Slashed to $725 Home appliance shoppers, prepare to upgrade your laundry room without emptying your wallet. A...

RFK Jr.’s top drug regulator resigns after ‘revenge campaign’ against ex-colleague: report

Top FDA Regulator Resigns Amid Scandal Involving 'Revenge Campaign' The political and regulatory landscape was shaken this week following the abrupt resignation of a senior...

National Guard, DC Police Respond As Dozens Descend On Navy Yard, Several Arrests Made

National Guard Deployed as Chaos Grips DC Navy Yard on Halloween Night Halloween night traditionally brings costumed fun, but in Washington D.C.’s Navy Yard neighborhood,...

She’s a pop star, he’s a former PM – why Katy Perry and Justin Trudeau just might work

The Unlikely Parallel: Why Katy Perry and Justin Trudeau Share a Volatile Path In the often-unpredictable world of celebrity and politics, finding common ground between...

Government issuing license for real estate business

Government Formalizes Real Estate Sector, Begins Issuing Operating Licenses in Kathmandu Announcing a significant regulatory shift, the Department of Land Management and Archives has confirmed...

Yokogawa to Deliver Integrated Control Systems for Urban Infrastructure in Green Riyadh Project

Yokogawa Powers Green Riyadh: Integrated Control Systems to Drive Massive Afforestation Project The Kingdom of Saudi Arabia is aggressively pursuing massive urban transformation initiatives, and...