Submission #1099414

#TimeUsernameProblemLanguageResultExecution timeMemory
1099414andreiqwerCircle Passing (EGOI24_circlepassing)C++17
20 / 100
2100 ms844472 KiB
#include <iostream> #include <vector> #include <queue> #include <cstring> using namespace std; int n, m, q; vector<vector<int>> ad; vector<int> dist; void bfs(int k) { dist = vector<int>(2*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.tie(0); ios_base::sync_with_stdio(0); cin>>n>>m>>q; ad = vector<vector<int>>(2*n); 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...