이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
bitset<30001> bs,bs2[30001];
vector<int> v[30001];
int n,m;
int main(){
ios_base::sync_with_stdio(false);
cout.tie(NULL);
cin.tie(NULL);
cin >> n >> m;
for(int i = 0 ; i < m ; i += 1){
int a,b;
cin >> a >> b;
v[a].push_back(b);
}
queue<pair<int,int>> q;
for(auto i : v[0]){
q.push({0,i});
bs2[0][i] = 1;
}
bs[0] = 1;
int dist = 0;
while(q.size()){
queue<pair<int,int>> q2;
while(q.size()){
pair<int,int> a = q.front();
q.pop();
cout << a.first << " " << a.second << " " << dist << endl;
if(!bs[a.first]){
bs[a.first] = 1;
for(auto i : v[a.first]){
q.push({a.first,i}) , bs2[a.first][i] = 1;
}
}
if(a.first+a.second < n && !bs2[a.first+a.second][a.second]){
q2.push({a.first+a.second,a.second}) , bs2[a.first+a.second][a.second] = 1;
}
if(a.first-a.second >= 0 && !bs2[a.first-a.second][a.second]){
q2.push({a.first-a.second,a.second}) , bs2[a.first-a.second][a.second] = 1;
}
}
q = q2;
if(bs[1]){
cout << dist << '\n';
return 0;
}
dist += 1;
}
cout << -1 << endl;
}
# | 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... |