Submission #1170918

#TimeUsernameProblemLanguageResultExecution timeMemory
1170918uranhishigCircle Passing (EGOI24_circlepassing)C++20
0 / 100
1 ms580 KiB
#include <bits/stdc++.h> using namespace std; #define endl "\n" #define int long long #define ff first #define ss second #define all(a) (a).begin(),(a).end() #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) const int mx = 2e5 + 9; signed main() { int n, m, t; cin >> n >> m >> t; if (n <= 1000 and m <= 1000 and t <= 1000) { vector<vector<int>> v(1005); vector<bool> vis(1005, false); vector<int> p(1005); for (int i = 0; i < m; i++) { cin >> p[i]; v[p[i]].push_back(n + p[i]); v[n + p[i]].push_back(p[i]); } v[2 * n - 1].push_back(0); v[0].push_back(2 * n - 1); for (int i = 0; i < 2 * n - 1; i++) { v[i].push_back(i + 1); v[i + 1].push_back(i); } while (t--) { fill(vis.begin(), vis.end(), false); queue<pair<int , int>>q; int start, end; cin >> start >> end; q.push({start,0}); vis[start]=1; bool k = true; while(!q.empty()){ int x = q.front().first; int w = q.front().second; q.pop(); if (x==end) { cout<<w<<endl; k = false; break; } for (auto y:v[x]) { if (!vis[y]) { vis[y]=1; q.push({y,w+1}); } } } if (k) cout<<'0'<< endl; } return 0; } 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...