Submission #1099394

#TimeUsernameProblemLanguageResultExecution timeMemory
1099394mihaihvhCircle Passing (EGOI24_circlepassing)C++14
20 / 100
2099 ms1048576 KiB
#include <iostream> #include <set> #include <queue> #include <vector> using namespace std; vector<set<int>> v; int n, m, q; int M; void bf(int l, int k) { //int viz[20001]{0}; vector<int> viz(2*n); queue<int> q; viz[k] = 1; q.push(k); bool E = 1; while (!q.empty() && E) { for (auto m : v[q.front()]) { if (!viz[m]) { q.push(m); viz[m] = viz[q.front()] + 1; if (m == l) { cout << viz[l] - 1 << '\n'; return; } } } q.pop(); } cout << viz[l] - 1 << '\n'; } int main() { cin >> n >> m >> q; vector<set<int>> V(2*n); v = V; for (int i = 0; i < m; ++i) { cin >> M; v[M].insert(M+n); v[M+n].insert(M); } for (int i = 0; i < 2*n; ++i) { if (i == 0) v[i].insert(2*n-1); if (i == 2*n-1) v[i].insert(0); if (i < 2*n-1) v[i].insert(i+1); if (i > 0) v[i].insert(i-1); } for (int i = 0; i < q; ++i) { int a, b; cin >> a >> b; bf(a, b); } return 0; }
#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...