Submission #1099410

#TimeUsernameProblemLanguageResultExecution timeMemory
1099410andreiqwerCircle Passing (EGOI24_circlepassing)C++17
20 / 100
2081 ms1035344 KiB
#include <iostream> #include <vector> #include <queue> #include <cstring> using namespace std; int n, m, q; vector<int> ad[10000001]; int dist[10000001]; void bfs(int k) { memset(dist, 0, 8*n); dist[k]=1; queue<int> q; q.push(k); while(!q.empty()) { int node=q.front(); q.pop(); for(auto& x : ad[node]) { if(!dist[x]) { dist[x]=dist[node]+1; q.push(x); } } } } int main() { cin>>n>>m>>q; for(int i=0; i<2*n-1; i++) { ad[i].push_back(i+1); ad[i+1].push_back(i); } ad[2*n-1].push_back(0); ad[0].push_back(2*n-1); for(int i=0; i<m; i++) { int k; cin>>k; ad[k].push_back(k+n); ad[k+n].push_back(k); } for(int i=1; i<=q; i++) { int x, y; cin>>x>>y; bfs(x); cout<<dist[y]-1<<'\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...