10128 | 2024-03-27 19:45:52 | 111 | Vázsony vonatjegyet vásárol | cpp17 | Wrong answer 0/100 | 1.6s | 131816 KiB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF (int)1e18
template<typename T>
using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N,M,A,B;
cin>>N>>M>>A>>B;
vector<vector<pair<int,int>>>g(N+1);
for(int i=0;i<M;i++){
int a,b,w;
cin>>a>>b>>w;
g[a].emplace_back(b,w);
g[b].emplace_back(a,w);
}
vector<int>c(N+1,INF);
min_priority_queue<pair<int,int>>pq;
c[B]=0;
pq.emplace(0,B);
while(!pq.empty()){
auto[d,i]=pq.top();
pq.pop();
if(d>c[i]){
continue;
}
for(auto[j,w]:g[i]){
if(c[i]+w<c[j]){
c[j]=c[i]+w;
pq.emplace(c[j],j);
}
}
}
vector<int>ans,a;
vector<int>v(N+1);
auto bt=[&](auto self,int i)->void{
if(v[i]){
return;
}
v[i]=1;
a.push_back(i);
if(i==B){
if(a.size()>ans.size()){
ans=a;
}
}
else{
for(auto[j,_]:g[i]){
if(c[j]<=c[i]){
self(self,j);
}
}
}
a.pop_back();
v[i]=0;
};
bt(bt,A);
cout<<ans.size()<<'\n';
for(int i:ans){
cout<<i<<' ';
}
cout<<'\n';
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1956 KiB | ||||
2 | Wrong answer | 273ms | 24496 KiB | ||||
subtask2 | 0/20 | ||||||
3 | Time limit exceeded | 1.562s | 10636 KiB | ||||
4 | Time limit exceeded | 1.55s | 41188 KiB | ||||
5 | Time limit exceeded | 1.578s | 43432 KiB | ||||
6 | Accepted | 1.121s | 61132 KiB | ||||
7 | Time limit exceeded | 1.549s | 54732 KiB | ||||
8 | Time limit exceeded | 1.575s | 55676 KiB | ||||
9 | Time limit exceeded | 1.549s | 85188 KiB | ||||
subtask3 | 0/15 | ||||||
10 | Time limit exceeded | 1.564s | 72076 KiB | ||||
11 | Accepted | 8ms | 58836 KiB | ||||
12 | Time limit exceeded | 1.6s | 57520 KiB | ||||
13 | Time limit exceeded | 1.577s | 61384 KiB | ||||
14 | Time limit exceeded | 1.562s | 68800 KiB | ||||
subtask4 | 0/20 | ||||||
15 | Time limit exceeded | 1.554s | 68560 KiB | ||||
16 | Time limit exceeded | 1.552s | 77796 KiB | ||||
17 | Time limit exceeded | 1.582s | 69592 KiB | ||||
18 | Time limit exceeded | 1.6s | 73368 KiB | ||||
19 | Time limit exceeded | 1.565s | 68920 KiB | ||||
20 | Time limit exceeded | 1.575s | 73456 KiB | ||||
subtask5 | 0/45 | ||||||
21 | Time limit exceeded | 1.562s | 67308 KiB | ||||
22 | Time limit exceeded | 1.57s | 129076 KiB | ||||
23 | Time limit exceeded | 1.578s | 88564 KiB | ||||
24 | Time limit exceeded | 1.531s | 104752 KiB | ||||
25 | Time limit exceeded | 1.564s | 106884 KiB | ||||
26 | Time limit exceeded | 1.544s | 120864 KiB | ||||
27 | Accepted | 216ms | 131628 KiB | ||||
28 | Time limit exceeded | 1.562s | 131744 KiB | ||||
29 | Time limit exceeded | 1.562s | 108116 KiB | ||||
30 | Time limit exceeded | 1.575s | 131812 KiB | ||||
31 | Time limit exceeded | 1.57s | 119204 KiB | ||||
32 | Time limit exceeded | 1.557s | 109948 KiB | ||||
33 | Time limit exceeded | 1.55s | 131064 KiB | ||||
34 | Time limit exceeded | 1.557s | 131740 KiB | ||||
35 | Time limit exceeded | 1.578s | 131748 KiB | ||||
36 | Time limit exceeded | 1.562s | 131744 KiB | ||||
37 | Time limit exceeded | 1.552s | 131816 KiB |