101282024-03-27 19:45:52111Vázsony vonatjegyet vásárolcpp17Wrong answer 0/1001.6s131816 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;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1956 KiB
2Wrong answer273ms24496 KiB
subtask20/20
3Time limit exceeded1.562s10636 KiB
4Time limit exceeded1.55s41188 KiB
5Time limit exceeded1.578s43432 KiB
6Accepted1.121s61132 KiB
7Time limit exceeded1.549s54732 KiB
8Time limit exceeded1.575s55676 KiB
9Time limit exceeded1.549s85188 KiB
subtask30/15
10Time limit exceeded1.564s72076 KiB
11Accepted8ms58836 KiB
12Time limit exceeded1.6s57520 KiB
13Time limit exceeded1.577s61384 KiB
14Time limit exceeded1.562s68800 KiB
subtask40/20
15Time limit exceeded1.554s68560 KiB
16Time limit exceeded1.552s77796 KiB
17Time limit exceeded1.582s69592 KiB
18Time limit exceeded1.6s73368 KiB
19Time limit exceeded1.565s68920 KiB
20Time limit exceeded1.575s73456 KiB
subtask50/45
21Time limit exceeded1.562s67308 KiB
22Time limit exceeded1.57s129076 KiB
23Time limit exceeded1.578s88564 KiB
24Time limit exceeded1.531s104752 KiB
25Time limit exceeded1.564s106884 KiB
26Time limit exceeded1.544s120864 KiB
27Accepted216ms131628 KiB
28Time limit exceeded1.562s131744 KiB
29Time limit exceeded1.562s108116 KiB
30Time limit exceeded1.575s131812 KiB
31Time limit exceeded1.57s119204 KiB
32Time limit exceeded1.557s109948 KiB
33Time limit exceeded1.55s131064 KiB
34Time limit exceeded1.557s131740 KiB
35Time limit exceeded1.578s131748 KiB
36Time limit exceeded1.562s131744 KiB
37Time limit exceeded1.552s131816 KiB