题解:AT_abc441_d [ABC441D] Paid Walk
NorthLatitude26 · · 题解
题目思路
看数据范围:
code:
#include<bits/stdc++.h>
#define N 200005
using namespace std;
struct node {int v , w , d ;};
int n , m , l , s , t ;
int u[N] , v[N] , c[N] , ans[N] ;
vector <node> e[N] ;
void bfs (){
queue <node> q;
q . push ( {1 , 0 , 0} ) ;
while (q . size ()) {
node p = q . front () ;
q . pop () ;
if(p . d > l) continue ; //强行跳过搜索
if (p . w >= s && p . d == l && p . w<= t) {ans [p . v] = 1 ; continue ;}
//注意顺序一定不能错不然的话程序答案会错误
for (node it : e[p . v]) q . push ( {it . v , it . w + p . w , p . d + 1} );
}
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m >> l >> s >> t ;
for (int i = 1 ; i <= m ; i++ ) cin >> u[i] >> v[i] >> c[i] , e [u[i]] . push_back ( {v[i] , c[i] , 0} );
bfs () ;
for (int i = 1 ; i <= n ; i++) if (ans[i]) cout << i << " " ;
return 0;
}
这里提一嘴,用vector做更好一点(个人喜欢数组)
错误示例:AC 33 WA 21 MLE 3