#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
const int maxN=2e5+5;
const ll inf=2e18;
int n,m,s,t,l;
ll k;
struct duongdi
{
int u;
ll w;
bool operator < (const duongdi &o)const
{
return w>o.w;
}
};
ll d[2][maxN+1];
vector<duongdi> adj[maxN+1];
priority_queue<duongdi> pq;
void dijkstra(int s,int type)
{
for(int i=1;i<=n;i++)
{
d[type][i]=inf;
}
d[type][s]=0;
pq.push({s,0});
while(!pq.empty())
{
duongdi tmp=pq.top();
pq.pop();
int u=tmp.u;
ll w=tmp.w;
if(d[type][u]<w)
{
continue;
}
for(auto [v,nw]:adj[u])
{
if(d[type][v]>d[type][u]+nw)
{
d[type][v]=d[type][u]+nw;
pq.push({v,d[type][v]});
}
}
}
}
int main()
{
//freopen("","r",stdin);
//freopen("","w",stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m>>s>>t>>l>>k;
for(int i=1;i<=m;i++)
{
int u,v,w;
cin>>u>>v>>w;
adj[u].push_back({v,w});
adj[v].push_back({u,w});
}
dijkstra(s,0);
dijkstra(t,1);
if(d[0][t]<=k)
{
cout<<1LL*n*(n-1)/2;
return 0;
}
sort(d[0]+1,d[0]+n+1);
sort(d[1]+1,d[1]+n+1);
ll ans=0;
for(int i=1,j=n;i<=n;i++)
{
while(j>0&&d[0][i]+d[1][j]+l>k)
{
j--;
}
ans+=j;
}
cout<<ans;
}
Compilation message
Main.cpp: In function 'void dijkstra(int, int)':
Main.cpp:42:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
42 | for(auto [v,nw]:adj[u])
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4952 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
3 ms |
5196 KB |
Output is correct |
6 |
Correct |
3 ms |
5468 KB |
Output is correct |
7 |
Correct |
51 ms |
19572 KB |
Output is correct |
8 |
Correct |
59 ms |
19504 KB |
Output is correct |
9 |
Correct |
62 ms |
20664 KB |
Output is correct |
10 |
Correct |
2 ms |
4952 KB |
Output is correct |
11 |
Correct |
2 ms |
4952 KB |
Output is correct |
12 |
Correct |
3 ms |
5212 KB |
Output is correct |
13 |
Correct |
3 ms |
5432 KB |
Output is correct |
14 |
Correct |
40 ms |
14928 KB |
Output is correct |
15 |
Correct |
107 ms |
22224 KB |
Output is correct |
16 |
Correct |
2 ms |
4956 KB |
Output is correct |
17 |
Correct |
3 ms |
5320 KB |
Output is correct |
18 |
Correct |
72 ms |
20564 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
20 |
Correct |
2 ms |
4956 KB |
Output is correct |
21 |
Correct |
2 ms |
5212 KB |
Output is correct |
22 |
Correct |
3 ms |
5212 KB |
Output is correct |
23 |
Correct |
37 ms |
14980 KB |
Output is correct |
24 |
Correct |
128 ms |
22220 KB |
Output is correct |
25 |
Correct |
2 ms |
4956 KB |
Output is correct |
26 |
Correct |
4 ms |
5468 KB |
Output is correct |
27 |
Correct |
69 ms |
25296 KB |
Output is correct |
28 |
Correct |
52 ms |
19252 KB |
Output is correct |
29 |
Correct |
55 ms |
18312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4992 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
2 ms |
4956 KB |
Output is correct |
9 |
Correct |
2 ms |
4956 KB |
Output is correct |
10 |
Correct |
2 ms |
5176 KB |
Output is correct |
11 |
Correct |
3 ms |
4956 KB |
Output is correct |
12 |
Correct |
2 ms |
5080 KB |
Output is correct |
13 |
Correct |
2 ms |
4956 KB |
Output is correct |
14 |
Correct |
2 ms |
4956 KB |
Output is correct |
15 |
Correct |
2 ms |
5112 KB |
Output is correct |
16 |
Correct |
2 ms |
4956 KB |
Output is correct |
17 |
Correct |
2 ms |
4956 KB |
Output is correct |
18 |
Correct |
2 ms |
5160 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
20 |
Correct |
2 ms |
4956 KB |
Output is correct |
21 |
Correct |
2 ms |
4956 KB |
Output is correct |
22 |
Correct |
2 ms |
4956 KB |
Output is correct |
23 |
Correct |
2 ms |
4956 KB |
Output is correct |
24 |
Correct |
2 ms |
4956 KB |
Output is correct |
25 |
Correct |
2 ms |
5160 KB |
Output is correct |
26 |
Correct |
2 ms |
4956 KB |
Output is correct |
27 |
Correct |
2 ms |
4956 KB |
Output is correct |
28 |
Correct |
2 ms |
4956 KB |
Output is correct |
29 |
Correct |
2 ms |
4956 KB |
Output is correct |
30 |
Correct |
2 ms |
4956 KB |
Output is correct |
31 |
Correct |
2 ms |
4956 KB |
Output is correct |
32 |
Correct |
2 ms |
4956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4992 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
2 ms |
4956 KB |
Output is correct |
9 |
Correct |
2 ms |
4956 KB |
Output is correct |
10 |
Correct |
2 ms |
5176 KB |
Output is correct |
11 |
Correct |
3 ms |
4956 KB |
Output is correct |
12 |
Correct |
2 ms |
5080 KB |
Output is correct |
13 |
Correct |
2 ms |
4956 KB |
Output is correct |
14 |
Correct |
2 ms |
4956 KB |
Output is correct |
15 |
Correct |
2 ms |
5112 KB |
Output is correct |
16 |
Correct |
2 ms |
4956 KB |
Output is correct |
17 |
Correct |
2 ms |
4956 KB |
Output is correct |
18 |
Correct |
2 ms |
5160 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
20 |
Correct |
2 ms |
4956 KB |
Output is correct |
21 |
Correct |
2 ms |
4956 KB |
Output is correct |
22 |
Correct |
2 ms |
4956 KB |
Output is correct |
23 |
Correct |
2 ms |
4956 KB |
Output is correct |
24 |
Correct |
2 ms |
4956 KB |
Output is correct |
25 |
Correct |
2 ms |
5160 KB |
Output is correct |
26 |
Correct |
2 ms |
4956 KB |
Output is correct |
27 |
Correct |
2 ms |
4956 KB |
Output is correct |
28 |
Correct |
2 ms |
4956 KB |
Output is correct |
29 |
Correct |
2 ms |
4956 KB |
Output is correct |
30 |
Correct |
2 ms |
4956 KB |
Output is correct |
31 |
Correct |
2 ms |
4956 KB |
Output is correct |
32 |
Correct |
2 ms |
4956 KB |
Output is correct |
33 |
Correct |
3 ms |
5212 KB |
Output is correct |
34 |
Correct |
3 ms |
5468 KB |
Output is correct |
35 |
Correct |
2 ms |
5212 KB |
Output is correct |
36 |
Correct |
4 ms |
5208 KB |
Output is correct |
37 |
Correct |
3 ms |
5172 KB |
Output is correct |
38 |
Correct |
2 ms |
5212 KB |
Output is correct |
39 |
Correct |
3 ms |
5212 KB |
Output is correct |
40 |
Correct |
3 ms |
5468 KB |
Output is correct |
41 |
Correct |
3 ms |
5212 KB |
Output is correct |
42 |
Correct |
2 ms |
5212 KB |
Output is correct |
43 |
Correct |
3 ms |
5212 KB |
Output is correct |
44 |
Correct |
3 ms |
5464 KB |
Output is correct |
45 |
Correct |
3 ms |
5212 KB |
Output is correct |
46 |
Correct |
3 ms |
5212 KB |
Output is correct |
47 |
Correct |
3 ms |
5208 KB |
Output is correct |
48 |
Correct |
3 ms |
5212 KB |
Output is correct |
49 |
Correct |
3 ms |
5212 KB |
Output is correct |
50 |
Correct |
2 ms |
5212 KB |
Output is correct |
51 |
Correct |
4 ms |
5212 KB |
Output is correct |
52 |
Correct |
3 ms |
5212 KB |
Output is correct |
53 |
Correct |
4 ms |
5468 KB |
Output is correct |
54 |
Correct |
3 ms |
5464 KB |
Output is correct |
55 |
Correct |
3 ms |
5212 KB |
Output is correct |
56 |
Correct |
3 ms |
5212 KB |
Output is correct |
57 |
Correct |
3 ms |
5176 KB |
Output is correct |
58 |
Correct |
3 ms |
5212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4952 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
3 ms |
5196 KB |
Output is correct |
6 |
Correct |
3 ms |
5468 KB |
Output is correct |
7 |
Correct |
51 ms |
19572 KB |
Output is correct |
8 |
Correct |
59 ms |
19504 KB |
Output is correct |
9 |
Correct |
62 ms |
20664 KB |
Output is correct |
10 |
Correct |
2 ms |
4952 KB |
Output is correct |
11 |
Correct |
2 ms |
4952 KB |
Output is correct |
12 |
Correct |
3 ms |
5212 KB |
Output is correct |
13 |
Correct |
3 ms |
5432 KB |
Output is correct |
14 |
Correct |
40 ms |
14928 KB |
Output is correct |
15 |
Correct |
107 ms |
22224 KB |
Output is correct |
16 |
Correct |
2 ms |
4956 KB |
Output is correct |
17 |
Correct |
3 ms |
5320 KB |
Output is correct |
18 |
Correct |
72 ms |
20564 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
20 |
Correct |
2 ms |
4956 KB |
Output is correct |
21 |
Correct |
2 ms |
5212 KB |
Output is correct |
22 |
Correct |
3 ms |
5212 KB |
Output is correct |
23 |
Correct |
37 ms |
14980 KB |
Output is correct |
24 |
Correct |
128 ms |
22220 KB |
Output is correct |
25 |
Correct |
2 ms |
4956 KB |
Output is correct |
26 |
Correct |
4 ms |
5468 KB |
Output is correct |
27 |
Correct |
69 ms |
25296 KB |
Output is correct |
28 |
Correct |
52 ms |
19252 KB |
Output is correct |
29 |
Correct |
55 ms |
18312 KB |
Output is correct |
30 |
Correct |
2 ms |
4952 KB |
Output is correct |
31 |
Correct |
2 ms |
4956 KB |
Output is correct |
32 |
Correct |
2 ms |
4956 KB |
Output is correct |
33 |
Correct |
2 ms |
4956 KB |
Output is correct |
34 |
Correct |
2 ms |
4992 KB |
Output is correct |
35 |
Correct |
2 ms |
4956 KB |
Output is correct |
36 |
Correct |
2 ms |
4956 KB |
Output is correct |
37 |
Correct |
2 ms |
4956 KB |
Output is correct |
38 |
Correct |
2 ms |
4956 KB |
Output is correct |
39 |
Correct |
2 ms |
5176 KB |
Output is correct |
40 |
Correct |
3 ms |
4956 KB |
Output is correct |
41 |
Correct |
2 ms |
5080 KB |
Output is correct |
42 |
Correct |
2 ms |
4956 KB |
Output is correct |
43 |
Correct |
2 ms |
4956 KB |
Output is correct |
44 |
Correct |
2 ms |
5112 KB |
Output is correct |
45 |
Correct |
2 ms |
4956 KB |
Output is correct |
46 |
Correct |
2 ms |
4956 KB |
Output is correct |
47 |
Correct |
2 ms |
5160 KB |
Output is correct |
48 |
Correct |
2 ms |
4956 KB |
Output is correct |
49 |
Correct |
2 ms |
4956 KB |
Output is correct |
50 |
Correct |
2 ms |
4956 KB |
Output is correct |
51 |
Correct |
2 ms |
4956 KB |
Output is correct |
52 |
Correct |
2 ms |
4956 KB |
Output is correct |
53 |
Correct |
2 ms |
4956 KB |
Output is correct |
54 |
Correct |
2 ms |
5160 KB |
Output is correct |
55 |
Correct |
2 ms |
4956 KB |
Output is correct |
56 |
Correct |
2 ms |
4956 KB |
Output is correct |
57 |
Correct |
2 ms |
4956 KB |
Output is correct |
58 |
Correct |
2 ms |
4956 KB |
Output is correct |
59 |
Correct |
2 ms |
4956 KB |
Output is correct |
60 |
Correct |
2 ms |
4956 KB |
Output is correct |
61 |
Correct |
2 ms |
4956 KB |
Output is correct |
62 |
Correct |
3 ms |
5212 KB |
Output is correct |
63 |
Correct |
3 ms |
5468 KB |
Output is correct |
64 |
Correct |
2 ms |
5212 KB |
Output is correct |
65 |
Correct |
4 ms |
5208 KB |
Output is correct |
66 |
Correct |
3 ms |
5172 KB |
Output is correct |
67 |
Correct |
2 ms |
5212 KB |
Output is correct |
68 |
Correct |
3 ms |
5212 KB |
Output is correct |
69 |
Correct |
3 ms |
5468 KB |
Output is correct |
70 |
Correct |
3 ms |
5212 KB |
Output is correct |
71 |
Correct |
2 ms |
5212 KB |
Output is correct |
72 |
Correct |
3 ms |
5212 KB |
Output is correct |
73 |
Correct |
3 ms |
5464 KB |
Output is correct |
74 |
Correct |
3 ms |
5212 KB |
Output is correct |
75 |
Correct |
3 ms |
5212 KB |
Output is correct |
76 |
Correct |
3 ms |
5208 KB |
Output is correct |
77 |
Correct |
3 ms |
5212 KB |
Output is correct |
78 |
Correct |
3 ms |
5212 KB |
Output is correct |
79 |
Correct |
2 ms |
5212 KB |
Output is correct |
80 |
Correct |
4 ms |
5212 KB |
Output is correct |
81 |
Correct |
3 ms |
5212 KB |
Output is correct |
82 |
Correct |
4 ms |
5468 KB |
Output is correct |
83 |
Correct |
3 ms |
5464 KB |
Output is correct |
84 |
Correct |
3 ms |
5212 KB |
Output is correct |
85 |
Correct |
3 ms |
5212 KB |
Output is correct |
86 |
Correct |
3 ms |
5176 KB |
Output is correct |
87 |
Correct |
3 ms |
5212 KB |
Output is correct |
88 |
Correct |
88 ms |
23620 KB |
Output is correct |
89 |
Correct |
86 ms |
23508 KB |
Output is correct |
90 |
Correct |
88 ms |
23728 KB |
Output is correct |
91 |
Correct |
45 ms |
18768 KB |
Output is correct |
92 |
Correct |
44 ms |
18768 KB |
Output is correct |
93 |
Correct |
44 ms |
15700 KB |
Output is correct |
94 |
Correct |
43 ms |
15696 KB |
Output is correct |
95 |
Correct |
155 ms |
23792 KB |
Output is correct |
96 |
Correct |
124 ms |
23648 KB |
Output is correct |
97 |
Correct |
129 ms |
23028 KB |
Output is correct |
98 |
Correct |
127 ms |
23124 KB |
Output is correct |
99 |
Correct |
63 ms |
22076 KB |
Output is correct |
100 |
Correct |
74 ms |
22344 KB |
Output is correct |
101 |
Correct |
40 ms |
18780 KB |
Output is correct |
102 |
Correct |
41 ms |
18956 KB |
Output is correct |
103 |
Correct |
40 ms |
15700 KB |
Output is correct |
104 |
Correct |
43 ms |
15700 KB |
Output is correct |
105 |
Correct |
151 ms |
23752 KB |
Output is correct |
106 |
Correct |
144 ms |
23664 KB |
Output is correct |
107 |
Correct |
135 ms |
26548 KB |
Output is correct |
108 |
Correct |
142 ms |
26712 KB |
Output is correct |
109 |
Correct |
72 ms |
20384 KB |
Output is correct |
110 |
Correct |
71 ms |
20236 KB |
Output is correct |
111 |
Correct |
88 ms |
19152 KB |
Output is correct |
112 |
Correct |
91 ms |
19156 KB |
Output is correct |