#include <bits/stdc++.h>
#define ll long long
#define str string
#define ins insert
#define ld long double
#define pb push_back
#define pf push_front
#define pof pop_front()
#define pob pop_back()
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define sz size()
#define vll vector<ll>
#define bc back()
#define arr array
#define pll vector<pair<ll,ll>>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>
template<class S,class T>
bool chmin(S &a,const T &b) {
return a>b?(a=b)==b:false;
}
template<class S,class T>
bool chmax(S &a,const T &b) {
return a<b?(a=b)==b:false;
}
//void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
void start(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
const ll inf=1e18;
const ll mod=1e18+7;
const ll mod2=1e9+11;
const ll N=2e5+7;
const ld eps=1e-9;
vector<pll> g(N);
ll d[N];
void dijkstra(ll s){
set<pair<ll,ll>> st;
memset(d,0x3f,sizeof(d));
d[s]=0;
st.ins({d[s],s});
while(st.sz){
ll x=st.begin()->sc;
st.erase(st.begin());
for(auto i : g[x]){
ll to=i.fr,len=i.sc;
if(d[to]>d[x]+len){
d[to]=d[x]+len;
st.ins({d[to],to});
}
}
}
}
void solve(){
ll i,j;
ll n,m;
ll s,t,l,k;
cin>>n>>m;
cin>>s>>t>>l>>k;
for(i=0;i<m;i++){
ll a,b,c;
cin>>a>>b>>c;
g[a].pb({b,c});
g[b].pb({a,c});
}
dijkstra(s);
pll vs;
for(i=1;i<=n;i++)vs.pb({d[i],i});
dijkstra(t);
ll ans=0;
vll vt;
for(i=1;i<=n;i++)vt.pb(d[i]);
sort(all(vt));
if(d[s]<=k){
cout<<n*(n-1)/2<<endl;
return;
}
for(i=0;i<n;i++){
ans+=lb(all(vt),k-l-vs[i].fr+1)-vt.begin();
}
cout<<ans<<endl;
}
signed main(){
start();
ll t=1;
//cin>>t;
while(t--) solve();
return 0;
}
/*
a<b<c<d
a a
b b
a a
a a
*/
Compilation message
Main.cpp: In function 'void solve()':
Main.cpp:66:10: warning: unused variable 'j' [-Wunused-variable]
66 | ll i,j;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
6492 KB |
Output is correct |
2 |
Correct |
3 ms |
6492 KB |
Output is correct |
3 |
Correct |
5 ms |
6704 KB |
Output is correct |
4 |
Correct |
4 ms |
6492 KB |
Output is correct |
5 |
Correct |
4 ms |
7004 KB |
Output is correct |
6 |
Correct |
4 ms |
7004 KB |
Output is correct |
7 |
Correct |
69 ms |
24496 KB |
Output is correct |
8 |
Correct |
91 ms |
24696 KB |
Output is correct |
9 |
Correct |
99 ms |
27232 KB |
Output is correct |
10 |
Correct |
3 ms |
6492 KB |
Output is correct |
11 |
Correct |
3 ms |
6492 KB |
Output is correct |
12 |
Correct |
3 ms |
6748 KB |
Output is correct |
13 |
Correct |
4 ms |
7000 KB |
Output is correct |
14 |
Correct |
41 ms |
20188 KB |
Output is correct |
15 |
Correct |
174 ms |
27464 KB |
Output is correct |
16 |
Correct |
3 ms |
6488 KB |
Output is correct |
17 |
Correct |
4 ms |
7004 KB |
Output is correct |
18 |
Correct |
73 ms |
25552 KB |
Output is correct |
19 |
Correct |
3 ms |
6488 KB |
Output is correct |
20 |
Correct |
3 ms |
6708 KB |
Output is correct |
21 |
Correct |
4 ms |
6748 KB |
Output is correct |
22 |
Correct |
5 ms |
7004 KB |
Output is correct |
23 |
Correct |
42 ms |
20104 KB |
Output is correct |
24 |
Correct |
172 ms |
27460 KB |
Output is correct |
25 |
Correct |
3 ms |
6492 KB |
Output is correct |
26 |
Correct |
4 ms |
7004 KB |
Output is correct |
27 |
Correct |
124 ms |
35580 KB |
Output is correct |
28 |
Correct |
75 ms |
25168 KB |
Output is correct |
29 |
Correct |
62 ms |
22800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
6492 KB |
Output is correct |
2 |
Correct |
3 ms |
6492 KB |
Output is correct |
3 |
Correct |
3 ms |
6492 KB |
Output is correct |
4 |
Correct |
3 ms |
6492 KB |
Output is correct |
5 |
Correct |
3 ms |
6492 KB |
Output is correct |
6 |
Correct |
3 ms |
6492 KB |
Output is correct |
7 |
Correct |
3 ms |
6488 KB |
Output is correct |
8 |
Correct |
4 ms |
6492 KB |
Output is correct |
9 |
Correct |
3 ms |
6708 KB |
Output is correct |
10 |
Correct |
3 ms |
6492 KB |
Output is correct |
11 |
Correct |
3 ms |
6492 KB |
Output is correct |
12 |
Correct |
3 ms |
6492 KB |
Output is correct |
13 |
Correct |
3 ms |
6492 KB |
Output is correct |
14 |
Correct |
3 ms |
6492 KB |
Output is correct |
15 |
Correct |
4 ms |
6492 KB |
Output is correct |
16 |
Correct |
3 ms |
6492 KB |
Output is correct |
17 |
Correct |
4 ms |
6492 KB |
Output is correct |
18 |
Correct |
3 ms |
6492 KB |
Output is correct |
19 |
Correct |
3 ms |
6492 KB |
Output is correct |
20 |
Correct |
3 ms |
6712 KB |
Output is correct |
21 |
Correct |
3 ms |
6492 KB |
Output is correct |
22 |
Correct |
3 ms |
6492 KB |
Output is correct |
23 |
Correct |
3 ms |
6492 KB |
Output is correct |
24 |
Correct |
3 ms |
6492 KB |
Output is correct |
25 |
Correct |
3 ms |
6492 KB |
Output is correct |
26 |
Correct |
3 ms |
6492 KB |
Output is correct |
27 |
Correct |
4 ms |
6492 KB |
Output is correct |
28 |
Correct |
4 ms |
6704 KB |
Output is correct |
29 |
Correct |
3 ms |
6492 KB |
Output is correct |
30 |
Correct |
3 ms |
6492 KB |
Output is correct |
31 |
Correct |
3 ms |
6488 KB |
Output is correct |
32 |
Correct |
3 ms |
6492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
6492 KB |
Output is correct |
2 |
Correct |
3 ms |
6492 KB |
Output is correct |
3 |
Correct |
3 ms |
6492 KB |
Output is correct |
4 |
Correct |
3 ms |
6492 KB |
Output is correct |
5 |
Correct |
3 ms |
6492 KB |
Output is correct |
6 |
Correct |
3 ms |
6492 KB |
Output is correct |
7 |
Correct |
3 ms |
6488 KB |
Output is correct |
8 |
Correct |
4 ms |
6492 KB |
Output is correct |
9 |
Correct |
3 ms |
6708 KB |
Output is correct |
10 |
Correct |
3 ms |
6492 KB |
Output is correct |
11 |
Correct |
3 ms |
6492 KB |
Output is correct |
12 |
Correct |
3 ms |
6492 KB |
Output is correct |
13 |
Correct |
3 ms |
6492 KB |
Output is correct |
14 |
Correct |
3 ms |
6492 KB |
Output is correct |
15 |
Correct |
4 ms |
6492 KB |
Output is correct |
16 |
Correct |
3 ms |
6492 KB |
Output is correct |
17 |
Correct |
4 ms |
6492 KB |
Output is correct |
18 |
Correct |
3 ms |
6492 KB |
Output is correct |
19 |
Correct |
3 ms |
6492 KB |
Output is correct |
20 |
Correct |
3 ms |
6712 KB |
Output is correct |
21 |
Correct |
3 ms |
6492 KB |
Output is correct |
22 |
Correct |
3 ms |
6492 KB |
Output is correct |
23 |
Correct |
3 ms |
6492 KB |
Output is correct |
24 |
Correct |
3 ms |
6492 KB |
Output is correct |
25 |
Correct |
3 ms |
6492 KB |
Output is correct |
26 |
Correct |
3 ms |
6492 KB |
Output is correct |
27 |
Correct |
4 ms |
6492 KB |
Output is correct |
28 |
Correct |
4 ms |
6704 KB |
Output is correct |
29 |
Correct |
3 ms |
6492 KB |
Output is correct |
30 |
Correct |
3 ms |
6492 KB |
Output is correct |
31 |
Correct |
3 ms |
6488 KB |
Output is correct |
32 |
Correct |
3 ms |
6492 KB |
Output is correct |
33 |
Correct |
4 ms |
7000 KB |
Output is correct |
34 |
Correct |
4 ms |
7004 KB |
Output is correct |
35 |
Correct |
4 ms |
6776 KB |
Output is correct |
36 |
Correct |
4 ms |
7004 KB |
Output is correct |
37 |
Correct |
4 ms |
7004 KB |
Output is correct |
38 |
Correct |
3 ms |
6748 KB |
Output is correct |
39 |
Correct |
5 ms |
7000 KB |
Output is correct |
40 |
Correct |
4 ms |
7028 KB |
Output is correct |
41 |
Correct |
4 ms |
6744 KB |
Output is correct |
42 |
Correct |
3 ms |
6748 KB |
Output is correct |
43 |
Correct |
5 ms |
7004 KB |
Output is correct |
44 |
Correct |
5 ms |
7000 KB |
Output is correct |
45 |
Correct |
4 ms |
7060 KB |
Output is correct |
46 |
Correct |
4 ms |
6952 KB |
Output is correct |
47 |
Correct |
4 ms |
6976 KB |
Output is correct |
48 |
Correct |
4 ms |
7004 KB |
Output is correct |
49 |
Correct |
5 ms |
6744 KB |
Output is correct |
50 |
Correct |
4 ms |
6748 KB |
Output is correct |
51 |
Correct |
4 ms |
7004 KB |
Output is correct |
52 |
Correct |
5 ms |
7000 KB |
Output is correct |
53 |
Correct |
4 ms |
7004 KB |
Output is correct |
54 |
Correct |
4 ms |
7004 KB |
Output is correct |
55 |
Correct |
5 ms |
7004 KB |
Output is correct |
56 |
Correct |
5 ms |
7004 KB |
Output is correct |
57 |
Correct |
4 ms |
6744 KB |
Output is correct |
58 |
Correct |
4 ms |
6748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
6492 KB |
Output is correct |
2 |
Correct |
3 ms |
6492 KB |
Output is correct |
3 |
Correct |
5 ms |
6704 KB |
Output is correct |
4 |
Correct |
4 ms |
6492 KB |
Output is correct |
5 |
Correct |
4 ms |
7004 KB |
Output is correct |
6 |
Correct |
4 ms |
7004 KB |
Output is correct |
7 |
Correct |
69 ms |
24496 KB |
Output is correct |
8 |
Correct |
91 ms |
24696 KB |
Output is correct |
9 |
Correct |
99 ms |
27232 KB |
Output is correct |
10 |
Correct |
3 ms |
6492 KB |
Output is correct |
11 |
Correct |
3 ms |
6492 KB |
Output is correct |
12 |
Correct |
3 ms |
6748 KB |
Output is correct |
13 |
Correct |
4 ms |
7000 KB |
Output is correct |
14 |
Correct |
41 ms |
20188 KB |
Output is correct |
15 |
Correct |
174 ms |
27464 KB |
Output is correct |
16 |
Correct |
3 ms |
6488 KB |
Output is correct |
17 |
Correct |
4 ms |
7004 KB |
Output is correct |
18 |
Correct |
73 ms |
25552 KB |
Output is correct |
19 |
Correct |
3 ms |
6488 KB |
Output is correct |
20 |
Correct |
3 ms |
6708 KB |
Output is correct |
21 |
Correct |
4 ms |
6748 KB |
Output is correct |
22 |
Correct |
5 ms |
7004 KB |
Output is correct |
23 |
Correct |
42 ms |
20104 KB |
Output is correct |
24 |
Correct |
172 ms |
27460 KB |
Output is correct |
25 |
Correct |
3 ms |
6492 KB |
Output is correct |
26 |
Correct |
4 ms |
7004 KB |
Output is correct |
27 |
Correct |
124 ms |
35580 KB |
Output is correct |
28 |
Correct |
75 ms |
25168 KB |
Output is correct |
29 |
Correct |
62 ms |
22800 KB |
Output is correct |
30 |
Correct |
3 ms |
6492 KB |
Output is correct |
31 |
Correct |
3 ms |
6492 KB |
Output is correct |
32 |
Correct |
3 ms |
6492 KB |
Output is correct |
33 |
Correct |
3 ms |
6492 KB |
Output is correct |
34 |
Correct |
3 ms |
6492 KB |
Output is correct |
35 |
Correct |
3 ms |
6492 KB |
Output is correct |
36 |
Correct |
3 ms |
6488 KB |
Output is correct |
37 |
Correct |
4 ms |
6492 KB |
Output is correct |
38 |
Correct |
3 ms |
6708 KB |
Output is correct |
39 |
Correct |
3 ms |
6492 KB |
Output is correct |
40 |
Correct |
3 ms |
6492 KB |
Output is correct |
41 |
Correct |
3 ms |
6492 KB |
Output is correct |
42 |
Correct |
3 ms |
6492 KB |
Output is correct |
43 |
Correct |
3 ms |
6492 KB |
Output is correct |
44 |
Correct |
4 ms |
6492 KB |
Output is correct |
45 |
Correct |
3 ms |
6492 KB |
Output is correct |
46 |
Correct |
4 ms |
6492 KB |
Output is correct |
47 |
Correct |
3 ms |
6492 KB |
Output is correct |
48 |
Correct |
3 ms |
6492 KB |
Output is correct |
49 |
Correct |
3 ms |
6712 KB |
Output is correct |
50 |
Correct |
3 ms |
6492 KB |
Output is correct |
51 |
Correct |
3 ms |
6492 KB |
Output is correct |
52 |
Correct |
3 ms |
6492 KB |
Output is correct |
53 |
Correct |
3 ms |
6492 KB |
Output is correct |
54 |
Correct |
3 ms |
6492 KB |
Output is correct |
55 |
Correct |
3 ms |
6492 KB |
Output is correct |
56 |
Correct |
4 ms |
6492 KB |
Output is correct |
57 |
Correct |
4 ms |
6704 KB |
Output is correct |
58 |
Correct |
3 ms |
6492 KB |
Output is correct |
59 |
Correct |
3 ms |
6492 KB |
Output is correct |
60 |
Correct |
3 ms |
6488 KB |
Output is correct |
61 |
Correct |
3 ms |
6492 KB |
Output is correct |
62 |
Correct |
4 ms |
7000 KB |
Output is correct |
63 |
Correct |
4 ms |
7004 KB |
Output is correct |
64 |
Correct |
4 ms |
6776 KB |
Output is correct |
65 |
Correct |
4 ms |
7004 KB |
Output is correct |
66 |
Correct |
4 ms |
7004 KB |
Output is correct |
67 |
Correct |
3 ms |
6748 KB |
Output is correct |
68 |
Correct |
5 ms |
7000 KB |
Output is correct |
69 |
Correct |
4 ms |
7028 KB |
Output is correct |
70 |
Correct |
4 ms |
6744 KB |
Output is correct |
71 |
Correct |
3 ms |
6748 KB |
Output is correct |
72 |
Correct |
5 ms |
7004 KB |
Output is correct |
73 |
Correct |
5 ms |
7000 KB |
Output is correct |
74 |
Correct |
4 ms |
7060 KB |
Output is correct |
75 |
Correct |
4 ms |
6952 KB |
Output is correct |
76 |
Correct |
4 ms |
6976 KB |
Output is correct |
77 |
Correct |
4 ms |
7004 KB |
Output is correct |
78 |
Correct |
5 ms |
6744 KB |
Output is correct |
79 |
Correct |
4 ms |
6748 KB |
Output is correct |
80 |
Correct |
4 ms |
7004 KB |
Output is correct |
81 |
Correct |
5 ms |
7000 KB |
Output is correct |
82 |
Correct |
4 ms |
7004 KB |
Output is correct |
83 |
Correct |
4 ms |
7004 KB |
Output is correct |
84 |
Correct |
5 ms |
7004 KB |
Output is correct |
85 |
Correct |
5 ms |
7004 KB |
Output is correct |
86 |
Correct |
4 ms |
6744 KB |
Output is correct |
87 |
Correct |
4 ms |
6748 KB |
Output is correct |
88 |
Correct |
104 ms |
28736 KB |
Output is correct |
89 |
Correct |
105 ms |
28740 KB |
Output is correct |
90 |
Correct |
104 ms |
28808 KB |
Output is correct |
91 |
Correct |
48 ms |
20404 KB |
Output is correct |
92 |
Correct |
49 ms |
20308 KB |
Output is correct |
93 |
Correct |
47 ms |
20988 KB |
Output is correct |
94 |
Correct |
48 ms |
20820 KB |
Output is correct |
95 |
Correct |
223 ms |
29768 KB |
Output is correct |
96 |
Correct |
200 ms |
29176 KB |
Output is correct |
97 |
Correct |
164 ms |
28092 KB |
Output is correct |
98 |
Correct |
167 ms |
28328 KB |
Output is correct |
99 |
Correct |
71 ms |
27300 KB |
Output is correct |
100 |
Correct |
76 ms |
27076 KB |
Output is correct |
101 |
Correct |
44 ms |
20308 KB |
Output is correct |
102 |
Correct |
50 ms |
20368 KB |
Output is correct |
103 |
Correct |
46 ms |
20924 KB |
Output is correct |
104 |
Correct |
45 ms |
20924 KB |
Output is correct |
105 |
Correct |
203 ms |
30024 KB |
Output is correct |
106 |
Correct |
209 ms |
29160 KB |
Output is correct |
107 |
Correct |
233 ms |
37052 KB |
Output is correct |
108 |
Correct |
221 ms |
37052 KB |
Output is correct |
109 |
Execution timed out |
2062 ms |
24372 KB |
Time limit exceeded |
110 |
Halted |
0 ms |
0 KB |
- |