QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | 提交记录ID | 题目 | Hacker | Owner | 结果 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|
#873 | #580609 | #9374. Escape | stavage | wdw | Failed. | 2024-09-21 22:45:39 | 2024-09-21 22:45:40 |
詳細信息
Extra Test:
Invalid Input
input:
1 10 21 0 9 7 9 5 1 2 10 3 3 9 4 1 7 3 1 7 3 8 5 3 5 6 8 7 10 5 4 10 1 9 3 6 4 5 1 3 7 4 2 4 8 4 1 5
output:
result:
FAIL Integer parameter [name=~d~] equals to 0, violates the range [1, 9] (test case 1, stdin, line 2)
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#580609 | #9374. Escape | wdw | AC ✓ | 594ms | 76784kb | C++20 | 2.7kb | 2024-09-21 22:42:01 | 2024-09-21 22:42:02 |
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define db double
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const db eps = 1e-10;
void solve() {
int n, m, d;
cin >> n >> m >> d;
vector<vector<int>> q(n + 5);
vector<vector<int>> dis(n + 5, vector<int>(2, 1e9)), vis(n + 5, vector<int>(2)), vis2(n + 5, vector<int>(2)), dis2(
n + 5, vector<int>(2, 1e9));
vector<vector<int>>pre(n+5,vector<int>(2,0));
for (int i = 1, l, r; i <= m; i++) {
cin >> l >> r;
q[l].push_back(r);
q[r].push_back(l);
}
int k;
cin >> k;
queue<pair<int, int>> q1;
for (int i = 1, x; i <= k; i++) {
cin >> x;
q1.push({x, 0});
dis[x][0] = 0;
}
while (!q1.empty()) {
auto y = q1.front();
q1.pop();
if (vis[y.first][y.second % 2] || y.second == d)continue;
vis[y.first][y.second % 2] = 1;
for (auto j: q[y.first]) {
if( dis[j][(y.second+1) % 2]>y.second+1){
dis[j][(y.second+1) % 2]=y.second+1;
q1.push({j, y.second + 1});
}
}
}
q1.push({1, 0});
dis2[1][0] = 0;
vector<int> ans;
int f = 0;
int fx=0;
while (!q1.empty()) {
auto y = q1.front();
q1.pop();
// cout<<'\n';
// cout<<y.first<<" "<<y.second<<'\n';
if (y.first == n) {
f = 1;
fx=y.second%2;
break;
}
if (vis2[y.first][y.second % 2])continue;
vis2[y.first][y.second % 2] = 1;
for (auto j: q[y.first]) {
if (vis2[j][(y.second + 1)%2])continue;
if(dis[j][(y.second + 1)%2]>y.second+1){
if(y.second+1<dis2[j][(y.second + 1)%2]){
dis2[j][(y.second + 1)%2]=min( dis2[j][(y.second + 1)%2],y.second+1);
pre[j][(y.second + 1)%2]=y.first;
q1.push({j, y.second + 1});
}
}
}
}
// cout<<n<<" "<<fx<<'\n';
// cout<<dis2[n][fx]<<'\n';
if (f) {
int q=n;
ans.push_back(n);
while(1){
q=pre[q][fx];
fx^=1;
ans.push_back(q);
if(q==1&&fx==0)break;
}
int w1=ans.size();
cout<<w1-1<<'\n';
std::reverse(ans.begin(), ans.end());
for(int i=0;i<ans.size();i++){
cout<<ans[i]<<" ";
}cout<<'\n';
}else{
cout<<-1<<'\n';
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
//cout<<fixed<<setprecision(10);
int T = 1;
cin >> T;
while (T--)solve();
return 0;
}