이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// And you curse yourself for things you never done
#include<bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 3e4 + 10;
vector<int> vec[maxn];
bitset<maxn> bs[maxn];
int dis[maxn];
bool done[maxn];
pii p[maxn];
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie();
int n, m;
cin >> n >> m;
for(int i = 0; i < m; i++){
cin >> p[i].F >> p[i].S;
vec[p[i].F].PB(p[i].S);
}
fill(dis, dis + maxn, -1);
deque< pair<pii, int> > q;
q.push_back({p[0], 0});
while(sz(q)){
int pos = q.front().F.F, p = q.front().F.S, d = q.front().S;
q.pop_front();
if(bs[pos][p])
continue;
bs[pos][p] = 1;
if(done[pos] == 0){
dis[pos] = d;
for(int x : vec[pos])
q.push_front({ {pos, x}, d });
}
done[pos] = 1;
if(pos >= p)
q.push_back({ {pos - p, p}, d + 1 });
if(pos + p < n)
q.push_back({ {pos + p, p}, d + 1 });
}
return cout << dis[p[1].F] << endl, 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |