QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#332168 | #6307. Chase Game 2 | automac# | WA | 0ms | 3828kb | C++20 | 2.2kb | 2024-02-19 11:15:43 | 2024-02-19 11:15:44 |
Judging History
answer
#include <bits/stdc++.h>
#define forn(i, n) for(int i = 0; i < (int)n; ++i)
#define for1(i, n) for(int i = 1; i <= (int)n; ++i)
#define fore(i, l, r) for(int i = (int)l; i <= (int)r; ++i)
#define all(x) x.begin(), x.end()
#define el '\n'
#define d(x) cerr << #x << ' ' << x << el
#define sz(a) (int) a.size()
#define pb push_back
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef array<int, 4> a4;
typedef pair<int,int> ii;
// const int nax = 2e5;
const int nax = 2e3;
vi g[nax];
ll dist[3][nax];
void solve(){
int n,m,k,d;
cin>>n>>m>>k>>d;
--k;
forn(i,m){
int u,v;
cin>>u>>v;
--u,--v;
g[u].pb(v), g[v].pb(u);
}
queue<int> q;
q.push(k);
dist[0][k] = 0;
vi visited(n);
visited[k] = 1;
while(!q.empty()){
int siz = sz(q);
while(siz--){
int u = q.front();
q.pop();
ll curDist = dist[0][u];
for(int v : g[u]){
if(!visited[v])
{
visited[v] = 1;
q.push(v);
dist[0][v] = curDist + 1;
}
}
}
}
queue<ii> qq;
qq.push({0,1});
vector<vi> vis(2, vi(n));
vector<vector<ll>> curDist(2, vector<ll>(n));
vis[1][0] = 1;
curDist[1][0] = 0;
while(!qq.empty()){
int siz = sz(qq);
while(siz--){
auto [u, same] = qq.front();
qq.pop();
ll distU = curDist[same][u];
for(int v : g[u]){
bool newSame = (dist[0][v] < d) && same;
int cost = d;
if(newSame) cost = d - dist[0][v];
if(!vis[newSame][v]){
vis[newSame][v] = 1;
curDist[newSame][v] = distU + cost;
qq.push({v, newSame});
}
}
}
}
ll ans = min(curDist[0][n-1], curDist[1][n-1]);
cout<<ans<<el;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tt = 1;
// cin>>tt;
while(tt--){
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3828kb
input:
4 2 1 2 4 1 2 2 3 3 4 4 1 2 2 3 2 4 5 1 2 2 3 3 4 3 5
output:
0
result:
wrong answer 1st numbers differ - expected: '-1', found: '0'