Submission #595547

#TimeUsernameProblemLanguageResultExecution timeMemory
595547ThegeekKnight16Event Hopping (BOI22_events)C++14
10 / 100
1584 ms32716 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; int Inicio[MAXN], Fim[MAXN]; vector<int> Indices; vector<int> grafo[MAXN]; int Marc[MAXN], Dist[MAXN]; void bfs(int v, int N) { for (int i = 1; i <= N; i++) {Marc[i] = 0; Dist[i] = 1e9 + 10;} queue<int> q; Marc[v] = 1; Dist[v] = 0; q.push(v); while (!q.empty()) { int cur = q.front(); q.pop(); for (auto viz : grafo[cur]) { if (Marc[viz]) continue; Dist[viz] = Dist[cur] + 1; Marc[viz] = 1; q.push(viz); } } } bool cmp(int a, int b) { if (Fim[a] == Fim[b]) return Inicio[a] < Inicio[b]; return Fim[a] > Fim[b]; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int N, Q; cin >> N >> Q; for (int i = 1; i <= N; i++) { cin >> Inicio[i] >> Fim[i]; Indices.push_back(i); } sort(Indices.begin(), Indices.end(), cmp); for (int i = 0; i < Indices.size(); i++) { int id = Indices[i]; for (int j = 0; j < Indices.size(); j++) { int jd = Indices[j]; if (Inicio[jd] <= Fim[id] && Fim[id] <= Fim[jd]) {grafo[id].push_back(jd);} } } for (int q = 1; q <= Q; q++) { int X, Y; cin >> X >> Y; bfs(X, N); if (Dist[Y] == 1e9 + 10) cout << "impossible" << '\n'; else cout << Dist[Y] << '\n'; } }

Compilation message (stderr)

events.cpp: In function 'int main()':
events.cpp:49:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |     for (int i = 0; i < Indices.size(); i++)
      |                     ~~^~~~~~~~~~~~~~~~
events.cpp:52:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |         for (int j = 0; j < Indices.size(); j++)
      |                         ~~^~~~~~~~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...