Submission #1111262

# Submission time Handle Problem Language Result Execution time Memory
1111262 2024-11-11T22:53:32 Z StefanSebez Construction Project 2 (JOI24_ho_t2) C++14
100 / 100
297 ms 35108 KB
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ld long double
const int N=2e5+50,M=5e5+50;
const ll inf=1e18;
vector<pair<ll,ll>>E[N];
ll dist[N][2];bool was[N];
priority_queue<pair<ll,ll>>kju;
ll bit[M+50];
void Update(int i,int x){for(i++;i<=M;i+=i&-i)bit[i]+=x;}
ll Get(int i){ll x=0;for(i++;i>=1;i-=i&-i)x+=bit[i];return x;}
int main(){
    ll n,m;scanf("%lld%lld",&n,&m);
    int S,T;ll L,K;scanf("%i%i%lld%lld",&S,&T,&L,&K);
    for(int i=1;i<=m;i++){
		int u,v;ll w;scanf("%i%i%lld",&u,&v,&w);
		E[u].pb({v,w}),E[v].pb({u,w});
    }
    for(int i=1;i<=n;i++) dist[i][0]=dist[i][1]=inf;
    dist[S][0]=0;
    kju.push({0,S});
    while(kju.size()){
		int u=kju.top().se;kju.pop();
		if(was[u]) continue;
		was[u]=true;
		for(auto i:E[u]){
			if(!was[i.fi]&&dist[i.fi][0]>dist[u][0]+i.se){
				dist[i.fi][0]=dist[u][0]+i.se;
				kju.push({-dist[i.fi][0],i.fi});
			}
		}
    }
    for(int i=1;i<=n;i++) was[i]=false;
    dist[T][1]=0;
    kju.push({0,T});
	while(kju.size()){
		int u=kju.top().se;kju.pop();
		if(was[u]) continue;
		was[u]=true;
		for(auto i:E[u]){
			if(!was[i.fi]&&dist[i.fi][1]>dist[u][1]+i.se){
				dist[i.fi][1]=dist[u][1]+i.se;
				kju.push({-dist[i.fi][1],i.fi});
			}
		}
    }
    ll res=0;
    if(dist[T][0]<=K){
		res=(n*(n-1))/2;
		printf("%lld\n",res);
		return 0;
    }
    //for(int i=1;i<=n;i++) printf("%i: %lld %lld\n",i,dist[i][0],dist[i][1]);
    vector<int>ind;for(int i=1;i<=n;i++) ind.pb(i);
    sort(ind.begin(),ind.end(),[&](int i,int j){return dist[i][1]<dist[j][1];});
    vector<ll>Vals;
    for(int i=1;i<=n;i++){
		Vals.pb(dist[i][1]+L);
		Vals.pb(K-dist[i][0]);
    }
    sort(Vals.begin(),Vals.end());
    int mm=unique(Vals.begin(),Vals.end())-Vals.begin();
    Vals.resize(mm);
    //for(auto i:Vals) printf("%lld ",i);printf("\n");
    for(auto i:ind){
		//printf("%i\n",i);
		/*ll l=1,r=n,lb=0;
		while(l<=r){
			ll mid=l+r>>1;
			if(B[mid]<=x){lb=mid;l=mid+1;}
			else r=mid-1;
		}*/
		res+=Get(upper_bound(Vals.begin(),Vals.end(),K-dist[i][0])-Vals.begin());
		Update(upper_bound(Vals.begin(),Vals.end(),dist[i][1]+L)-Vals.begin(),1);
		//for(int j=1;j<=7;j++) printf("%i ",bit[j]);printf("\n");
		//if(dist[i][1]<=x) res--;
    }
    printf("%lld\n",res);
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:17:17: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     ll n,m;scanf("%lld%lld",&n,&m);
      |            ~~~~~^~~~~~~~~~~~~~~~~~
Main.cpp:18:25: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     int S,T;ll L,K;scanf("%i%i%lld%lld",&S,&T,&L,&K);
      |                    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:20:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |   int u,v;ll w;scanf("%i%i%lld",&u,&v,&w);
      |                ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5200 KB Output is correct
2 Correct 4 ms 4932 KB Output is correct
3 Correct 4 ms 5368 KB Output is correct
4 Correct 4 ms 5200 KB Output is correct
5 Correct 5 ms 5456 KB Output is correct
6 Correct 4 ms 5200 KB Output is correct
7 Correct 81 ms 23984 KB Output is correct
8 Correct 117 ms 23972 KB Output is correct
9 Correct 77 ms 19884 KB Output is correct
10 Correct 4 ms 5368 KB Output is correct
11 Correct 4 ms 5200 KB Output is correct
12 Correct 5 ms 5456 KB Output is correct
13 Correct 6 ms 5456 KB Output is correct
14 Correct 65 ms 20024 KB Output is correct
15 Correct 169 ms 27328 KB Output is correct
16 Correct 4 ms 5200 KB Output is correct
17 Correct 5 ms 5456 KB Output is correct
18 Correct 115 ms 25656 KB Output is correct
19 Correct 4 ms 5084 KB Output is correct
20 Correct 4 ms 5156 KB Output is correct
21 Correct 5 ms 5456 KB Output is correct
22 Correct 6 ms 5416 KB Output is correct
23 Correct 61 ms 20044 KB Output is correct
24 Correct 221 ms 27320 KB Output is correct
25 Correct 4 ms 4944 KB Output is correct
26 Correct 5 ms 5456 KB Output is correct
27 Correct 104 ms 26780 KB Output is correct
28 Correct 83 ms 22696 KB Output is correct
29 Correct 95 ms 23100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4944 KB Output is correct
2 Correct 3 ms 5068 KB Output is correct
3 Correct 3 ms 5020 KB Output is correct
4 Correct 4 ms 5368 KB Output is correct
5 Correct 4 ms 5200 KB Output is correct
6 Correct 4 ms 5200 KB Output is correct
7 Correct 4 ms 5152 KB Output is correct
8 Correct 4 ms 5200 KB Output is correct
9 Correct 4 ms 5200 KB Output is correct
10 Correct 4 ms 5200 KB Output is correct
11 Correct 4 ms 5200 KB Output is correct
12 Correct 6 ms 4944 KB Output is correct
13 Correct 4 ms 5200 KB Output is correct
14 Correct 4 ms 5200 KB Output is correct
15 Correct 4 ms 4944 KB Output is correct
16 Correct 4 ms 5140 KB Output is correct
17 Correct 4 ms 5200 KB Output is correct
18 Correct 4 ms 5200 KB Output is correct
19 Correct 4 ms 5200 KB Output is correct
20 Correct 4 ms 5200 KB Output is correct
21 Correct 3 ms 5200 KB Output is correct
22 Correct 4 ms 5200 KB Output is correct
23 Correct 4 ms 5200 KB Output is correct
24 Correct 4 ms 5200 KB Output is correct
25 Correct 4 ms 5200 KB Output is correct
26 Correct 4 ms 5200 KB Output is correct
27 Correct 4 ms 5160 KB Output is correct
28 Correct 5 ms 5200 KB Output is correct
29 Correct 4 ms 5200 KB Output is correct
30 Correct 3 ms 5200 KB Output is correct
31 Correct 3 ms 4944 KB Output is correct
32 Correct 3 ms 4944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4944 KB Output is correct
2 Correct 3 ms 5068 KB Output is correct
3 Correct 3 ms 5020 KB Output is correct
4 Correct 4 ms 5368 KB Output is correct
5 Correct 4 ms 5200 KB Output is correct
6 Correct 4 ms 5200 KB Output is correct
7 Correct 4 ms 5152 KB Output is correct
8 Correct 4 ms 5200 KB Output is correct
9 Correct 4 ms 5200 KB Output is correct
10 Correct 4 ms 5200 KB Output is correct
11 Correct 4 ms 5200 KB Output is correct
12 Correct 6 ms 4944 KB Output is correct
13 Correct 4 ms 5200 KB Output is correct
14 Correct 4 ms 5200 KB Output is correct
15 Correct 4 ms 4944 KB Output is correct
16 Correct 4 ms 5140 KB Output is correct
17 Correct 4 ms 5200 KB Output is correct
18 Correct 4 ms 5200 KB Output is correct
19 Correct 4 ms 5200 KB Output is correct
20 Correct 4 ms 5200 KB Output is correct
21 Correct 3 ms 5200 KB Output is correct
22 Correct 4 ms 5200 KB Output is correct
23 Correct 4 ms 5200 KB Output is correct
24 Correct 4 ms 5200 KB Output is correct
25 Correct 4 ms 5200 KB Output is correct
26 Correct 4 ms 5200 KB Output is correct
27 Correct 4 ms 5160 KB Output is correct
28 Correct 5 ms 5200 KB Output is correct
29 Correct 4 ms 5200 KB Output is correct
30 Correct 3 ms 5200 KB Output is correct
31 Correct 3 ms 4944 KB Output is correct
32 Correct 3 ms 4944 KB Output is correct
33 Correct 6 ms 5456 KB Output is correct
34 Correct 5 ms 5200 KB Output is correct
35 Correct 5 ms 5200 KB Output is correct
36 Correct 5 ms 5456 KB Output is correct
37 Correct 6 ms 5456 KB Output is correct
38 Correct 5 ms 5456 KB Output is correct
39 Correct 5 ms 5456 KB Output is correct
40 Correct 5 ms 5324 KB Output is correct
41 Correct 4 ms 5200 KB Output is correct
42 Correct 6 ms 5452 KB Output is correct
43 Correct 6 ms 5456 KB Output is correct
44 Correct 5 ms 5456 KB Output is correct
45 Correct 6 ms 5456 KB Output is correct
46 Correct 5 ms 5456 KB Output is correct
47 Correct 5 ms 5456 KB Output is correct
48 Correct 5 ms 5456 KB Output is correct
49 Correct 4 ms 5200 KB Output is correct
50 Correct 5 ms 5200 KB Output is correct
51 Correct 6 ms 5456 KB Output is correct
52 Correct 5 ms 5456 KB Output is correct
53 Correct 6 ms 5456 KB Output is correct
54 Correct 6 ms 5624 KB Output is correct
55 Correct 5 ms 5456 KB Output is correct
56 Correct 5 ms 5332 KB Output is correct
57 Correct 5 ms 5200 KB Output is correct
58 Correct 5 ms 5200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5200 KB Output is correct
2 Correct 4 ms 4932 KB Output is correct
3 Correct 4 ms 5368 KB Output is correct
4 Correct 4 ms 5200 KB Output is correct
5 Correct 5 ms 5456 KB Output is correct
6 Correct 4 ms 5200 KB Output is correct
7 Correct 81 ms 23984 KB Output is correct
8 Correct 117 ms 23972 KB Output is correct
9 Correct 77 ms 19884 KB Output is correct
10 Correct 4 ms 5368 KB Output is correct
11 Correct 4 ms 5200 KB Output is correct
12 Correct 5 ms 5456 KB Output is correct
13 Correct 6 ms 5456 KB Output is correct
14 Correct 65 ms 20024 KB Output is correct
15 Correct 169 ms 27328 KB Output is correct
16 Correct 4 ms 5200 KB Output is correct
17 Correct 5 ms 5456 KB Output is correct
18 Correct 115 ms 25656 KB Output is correct
19 Correct 4 ms 5084 KB Output is correct
20 Correct 4 ms 5156 KB Output is correct
21 Correct 5 ms 5456 KB Output is correct
22 Correct 6 ms 5416 KB Output is correct
23 Correct 61 ms 20044 KB Output is correct
24 Correct 221 ms 27320 KB Output is correct
25 Correct 4 ms 4944 KB Output is correct
26 Correct 5 ms 5456 KB Output is correct
27 Correct 104 ms 26780 KB Output is correct
28 Correct 83 ms 22696 KB Output is correct
29 Correct 95 ms 23100 KB Output is correct
30 Correct 4 ms 4944 KB Output is correct
31 Correct 3 ms 5068 KB Output is correct
32 Correct 3 ms 5020 KB Output is correct
33 Correct 4 ms 5368 KB Output is correct
34 Correct 4 ms 5200 KB Output is correct
35 Correct 4 ms 5200 KB Output is correct
36 Correct 4 ms 5152 KB Output is correct
37 Correct 4 ms 5200 KB Output is correct
38 Correct 4 ms 5200 KB Output is correct
39 Correct 4 ms 5200 KB Output is correct
40 Correct 4 ms 5200 KB Output is correct
41 Correct 6 ms 4944 KB Output is correct
42 Correct 4 ms 5200 KB Output is correct
43 Correct 4 ms 5200 KB Output is correct
44 Correct 4 ms 4944 KB Output is correct
45 Correct 4 ms 5140 KB Output is correct
46 Correct 4 ms 5200 KB Output is correct
47 Correct 4 ms 5200 KB Output is correct
48 Correct 4 ms 5200 KB Output is correct
49 Correct 4 ms 5200 KB Output is correct
50 Correct 3 ms 5200 KB Output is correct
51 Correct 4 ms 5200 KB Output is correct
52 Correct 4 ms 5200 KB Output is correct
53 Correct 4 ms 5200 KB Output is correct
54 Correct 4 ms 5200 KB Output is correct
55 Correct 4 ms 5200 KB Output is correct
56 Correct 4 ms 5160 KB Output is correct
57 Correct 5 ms 5200 KB Output is correct
58 Correct 4 ms 5200 KB Output is correct
59 Correct 3 ms 5200 KB Output is correct
60 Correct 3 ms 4944 KB Output is correct
61 Correct 3 ms 4944 KB Output is correct
62 Correct 6 ms 5456 KB Output is correct
63 Correct 5 ms 5200 KB Output is correct
64 Correct 5 ms 5200 KB Output is correct
65 Correct 5 ms 5456 KB Output is correct
66 Correct 6 ms 5456 KB Output is correct
67 Correct 5 ms 5456 KB Output is correct
68 Correct 5 ms 5456 KB Output is correct
69 Correct 5 ms 5324 KB Output is correct
70 Correct 4 ms 5200 KB Output is correct
71 Correct 6 ms 5452 KB Output is correct
72 Correct 6 ms 5456 KB Output is correct
73 Correct 5 ms 5456 KB Output is correct
74 Correct 6 ms 5456 KB Output is correct
75 Correct 5 ms 5456 KB Output is correct
76 Correct 5 ms 5456 KB Output is correct
77 Correct 5 ms 5456 KB Output is correct
78 Correct 4 ms 5200 KB Output is correct
79 Correct 5 ms 5200 KB Output is correct
80 Correct 6 ms 5456 KB Output is correct
81 Correct 5 ms 5456 KB Output is correct
82 Correct 6 ms 5456 KB Output is correct
83 Correct 6 ms 5624 KB Output is correct
84 Correct 5 ms 5456 KB Output is correct
85 Correct 5 ms 5332 KB Output is correct
86 Correct 5 ms 5200 KB Output is correct
87 Correct 5 ms 5200 KB Output is correct
88 Correct 96 ms 23780 KB Output is correct
89 Correct 101 ms 23748 KB Output is correct
90 Correct 133 ms 28616 KB Output is correct
91 Correct 51 ms 18960 KB Output is correct
92 Correct 52 ms 18760 KB Output is correct
93 Correct 62 ms 21052 KB Output is correct
94 Correct 63 ms 21048 KB Output is correct
95 Correct 297 ms 29104 KB Output is correct
96 Correct 172 ms 24512 KB Output is correct
97 Correct 290 ms 30260 KB Output is correct
98 Correct 201 ms 30516 KB Output is correct
99 Correct 116 ms 28724 KB Output is correct
100 Correct 115 ms 27956 KB Output is correct
101 Correct 51 ms 19016 KB Output is correct
102 Correct 50 ms 18944 KB Output is correct
103 Correct 64 ms 21052 KB Output is correct
104 Correct 63 ms 20932 KB Output is correct
105 Correct 227 ms 29128 KB Output is correct
106 Correct 228 ms 29092 KB Output is correct
107 Correct 208 ms 34860 KB Output is correct
108 Correct 235 ms 35108 KB Output is correct
109 Correct 104 ms 24492 KB Output is correct
110 Correct 100 ms 24484 KB Output is correct
111 Correct 124 ms 23744 KB Output is correct
112 Correct 127 ms 23824 KB Output is correct