101332024-03-27 20:24:06111Vázsony vonatjegyet vásárolcpp17Wrong answer 0/1001.572s121584 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<tuple<int,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,i);
		g[b].emplace_back(a,w,i);
	}
	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;
	int ansc=0,ac=0;
	vector<int>v(N+1),w(M);
	int st=clock();
	auto bt=[&](auto self,int i)->void{
		if(clock()-st>CLOCKS_PER_SEC)return;
		if(v[i]==0){
			ac++;
		}
		v[i]++;
		a.push_back(i);
		if(i==B){
			if(ac>ansc){
				ansc=ac;
				ans=a;
			}
		}
		else{
			for(auto[j,_,k]:g[i]){
				if(w[k]>=2){
					continue;
				}
				w[k]++;
				if(c[j]<=c[i]){
					self(self,j);
				}
				w[k]--;
			}
		}
		a.pop_back();
		v[i]--;
		if(v[i]==0){
			ac--;
		}
	};
	bt(bt,A);
	sort(ans.begin(),ans.end());
	ans.erase(unique(ans.begin(),ans.end()),ans.end());
	cout<<ans.size()<<'\n';
	for(int i:ans){
		cout<<i<<' ';
	}
	cout<<'\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1828 KiB
2Wrong answer1.108s32568 KiB
subtask20/20
3Wrong answer1.047s16824 KiB
4Wrong answer1.31s83788 KiB
5Wrong answer1.258s66356 KiB
6Wrong answer1.203s52488 KiB
7Wrong answer1.238s67240 KiB
8Wrong answer1.21s52016 KiB
9Wrong answer1.435s109108 KiB
subtask30/15
10Wrong answer1.312s64192 KiB
11Accepted9ms9344 KiB
12Wrong answer1.018s10260 KiB
13Wrong answer1.054s20256 KiB
14Wrong answer1.065s36208 KiB
subtask40/20
15Wrong answer1.052s30876 KiB
16Wrong answer1.159s47208 KiB
17Wrong answer1.029s22928 KiB
18Wrong answer1.054s29872 KiB
19Wrong answer1.031s16488 KiB
20Wrong answer1.06s26048 KiB
subtask50/45
21Wrong answer1.003s7392 KiB
22Time limit exceeded1.572s78712 KiB
23Wrong answer1.037s20368 KiB
24Wrong answer1.174s56064 KiB
25Wrong answer1.159s48856 KiB
26Wrong answer1.276s71352 KiB
27Accepted1.024s48268 KiB
28Wrong answer1.486s121584 KiB
29Wrong answer1.106s36032 KiB
30Wrong answer1.424s102612 KiB
31Wrong answer1.192s49212 KiB
32Wrong answer1.039s23300 KiB
33Wrong answer1.276s67080 KiB
34Wrong answer1.274s60628 KiB
35Wrong answer1.277s60668 KiB
36Wrong answer1.279s60768 KiB
37Wrong answer1.276s60920 KiB