結果
| 問題 |
No.1190 Points
|
| コンテスト | |
| ユーザー |
Ricky_pon
|
| 提出日時 | 2020-08-22 17:50:24 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,842 bytes |
| コンパイル時間 | 2,491 ms |
| コンパイル使用メモリ | 206,520 KB |
| 最終ジャッジ日時 | 2025-01-13 11:08:39 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 WA * 4 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:120:18: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-Wformat=]
120 | printf("%d\n", ans.size());
| ~^ ~~~~~~~~~~
| | |
| int std::vector<int>::size_type {aka long unsigned int}
| %ld
main.cpp:85:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
85 | scanf("%d%d%d", &n, &m, &p);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
main.cpp:87:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
87 | scanf("%d%d", &s, &t);
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:93:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
93 | scanf("%d%d", &a, &b);
| ~~~~~^~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
#define For(i, a, b) for (int(i) = (int)(a); (i) < (int)(b); ++(i))
#define rFor(i, a, b) for (int(i) = (int)(a)-1; (i) >= (int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template <class T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T>
bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T>
T div_floor(T a, T b) {
if (b < 0) a *= -1, b *= -1;
return a >= 0 ? a / b : (a + 1) / b - 1;
}
template <class T>
T div_ceil(T a, T b) {
if (b < 0) a *= -1, b *= -1;
return a > 0 ? (a - 1) / b + 1 : a / b;
}
constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;
template <typename T>
struct edge {
int from, to;
T cost;
edge(int f, int t, T c) : from(f), to(t), cost(c) {}
};
template <typename T>
struct Graph {
vector<vector<edge<T>>> G;
int n;
Graph(int n_) : n(n_) { G.resize(n); }
void add_edge(int f, int t, T c) { G[f].emplace_back(f, t, c); }
};
template <typename T>
vector<T> dijkstra(Graph<T> &gr, int s) {
using state = pair<T, int>;
priority_queue<state, vector<state>, greater<state>> que;
vector<T> d(gr.n, INF);
d[s] = 0;
que.emplace(0, s);
while (!que.empty()) {
state p = que.top();
que.pop();
int v = p.second;
if (d[v] < p.first) continue;
for (edge<T> &e : gr.G[v]) {
if (d[e.to] > d[v] + e.cost) {
d[e.to] = d[v] + e.cost;
que.emplace(d[e.to], e.to);
}
}
}
return d;
}
int main() {
int n, m, p;
scanf("%d%d%d", &n, &m, &p);
int s, t;
scanf("%d%d", &s, &t);
--s;
--t;
Graph<lint> gr(2 * n);
rep(i, m) {
int a, b;
scanf("%d%d", &a, &b);
--a;
--b;
gr.add_edge(a, b + n, 1);
gr.add_edge(a + n, b, 1);
gr.add_edge(b, a + n, 1);
gr.add_edge(b + n, a, 1);
}
auto ds = dijkstra(gr, s);
auto dt = dijkstra(gr, t);
if (ds[t + n * (p % 2)] == INF) {
puts("-1");
return 0;
}
vector<int> ans;
rep(i, n) {
lint tmp = INF;
if (p % 2 == 0)
tmp = min(ds[i] + dt[i], ds[i + n] + ds[i + n]);
else
tmp = min(ds[i + n] + dt[i], ds[i] + dt[i + n]);
if (tmp <= p) ans.push_back(i);
}
if (ans.empty())
puts("-1");
else {
printf("%d\n", ans.size());
for (auto v : ans) printf("%d\n", v + 1);
}
}
Ricky_pon