제출 #1228388

#제출 시각아이디문제언어결과실행 시간메모리
1228388JerRailway Trip 2 (JOI22_ho_t4)C++20
0 / 100
2094 ms106056 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 2005; vector<int> con[MAXN]; int n, k, m, q; int query(int s, int t) { set<int> vis; queue<int> q; q.push(s); int l = 0; while (!q.empty()) { int len = q.size(); for (int z = 0; z < len; z++) { int curr = q.front(); q.pop(); if (vis.find(curr) != vis.end()) continue; vis.insert(curr); if (curr == t) return l; for (auto i : con[curr]) q.push(i); } l++; } return -1; } int main() { scanf("%d%d%d", &n, &k, &m); int a, b; for (int i = 0; i < m; i++) { scanf("%d%d", &a, &b); a--, b--; if (a < b) { for (int s = a; s <= min(a + k - 1, b - 1); s++) for (int j = s + 1; j <= b; j++) con[s].push_back(j); } else { for (int s = a; s >= max(a - k + 1, b + 1); s--) for (int j = s - 1; j >= b; j--) con[s].push_back(j); } } scanf("%d", &q); while (q--) { int s, t; scanf("%d%d", &s, &t); s--, t--; printf("%d\n", query(s, t)); } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'int main()':
Main.cpp:43:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |     scanf("%d%d%d", &n, &k, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |         scanf("%d%d", &a, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~
Main.cpp:64:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |     scanf("%d", &q);
      |     ~~~~~^~~~~~~~~~
Main.cpp:69:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |         scanf("%d%d", &s, &t);
      |         ~~~~~^~~~~~~~~~~~~~~~
#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...