Submission #992131

# Submission time Handle Problem Language Result Execution time Memory
992131 2024-06-04T01:43:00 Z 8pete8 Construction Project 2 (JOI24_ho_t2) C++17
100 / 100
181 ms 30212 KB
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<cassert>
#include<limits.h>
#include<cmath>
#include<set>
#include<numeric> //gcd(a,b)
#include<algorithm>
#include<bitset> 
#include<stack>
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define pppiiii pair<pii,pii>
#define ppii pair<int,pii>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#define int long long
const int mod=998244353,mxn=2e5+5,lg=30,inf=1e18,minf=-1e9,Mxn=100000,root=700;
void setIO(string name){		
	ios_base::sync_with_stdio(0); cin.tie(0);		
	freopen((name+".in").c_str(),"r",stdin);		
	freopen((name+".out").c_str(),"w",stdout);	
}
int n,m;
vector<pii>adj[mxn+10];
vector<pii> dijk(int st){
	vector<pii>dist(n,{inf,0});
	for(int i=1;i<n;i++)dist[i].s=i;
	priority_queue<pii,vector<pii>,greater<pii>>pq;
	dist[st].f=0;
	pq.push({0,st});
	while(!pq.empty()){
		int cost=pq.top().f,cur=pq.top().s;
		pq.pop();
		if(cost!=dist[cur].f)continue;
		for(auto i:adj[cur])if(dist[i.f].f>dist[cur].f+i.s){
			dist[i.f].f=dist[cur].f+i.s;
			pq.push({dist[i.f].f,i.f});
		}
	}
	return dist;
}
struct fen{
	int fwk[mxn+10];
	void update(int pos,int val){for(int i=pos+1;i<=n+1;i+=(i&-i))fwk[i]+=val;}
	int qry(int pos){
		int sum=0;
		for(int i=pos;i>0;i-=(i&-i))sum+=fwk[i];
		return sum;
	}
}t;
int32_t main(){
	fastio
	cin>>n>>m;
	int st,ed,l,k;cin>>st>>ed>>l>>k;
	st--;
	ed--;
	for(int i=0;i<m;i++){
		int a,b,c;cin>>a>>b>>c;
		--a;
		--b;
		adj[a].pb({b,c});
		adj[b].pb({a,c});
	}
	vector<pii>d1=dijk(st),d2=dijk(ed);
	if(d1[ed].f<=k){
		cout<<(n*(n-1))/2;
		return 0;
	}
	sort(rall(d1));
	for(int i=0;i<d1.size();i++)d2[d1[i].s].s=i;
	sort(all(d2));
	int cur=0;
	int ans=0;
	for(int i=0;i<d1.size();i++){
		int need=k-d1[i].f-l;
		while(cur<d2.size()&&d2[cur].f<=need){
			t.update(d2[cur].s,1);
			cur++;
		}
		ans+=t.qry(i);
	}
	cout<<ans;
}

Compilation message

Main.cpp: In function 'int32_t main()':
Main.cpp:86:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |  for(int i=0;i<d1.size();i++)d2[d1[i].s].s=i;
      |              ~^~~~~~~~~~
Main.cpp:90:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |  for(int i=0;i<d1.size();i++){
      |              ~^~~~~~~~~~
Main.cpp:92:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |   while(cur<d2.size()&&d2[cur].f<=need){
      |         ~~~^~~~~~~~~~
Main.cpp: In function 'void setIO(std::string)':
Main.cpp:36:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |  freopen((name+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:37:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |  freopen((name+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 3 ms 6492 KB Output is correct
3 Correct 2 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 2 ms 6744 KB Output is correct
7 Correct 74 ms 23504 KB Output is correct
8 Correct 88 ms 23500 KB Output is correct
9 Correct 77 ms 24136 KB Output is correct
10 Correct 2 ms 6488 KB Output is correct
11 Correct 2 ms 6492 KB Output is correct
12 Correct 2 ms 6492 KB Output is correct
13 Correct 3 ms 6744 KB Output is correct
14 Correct 41 ms 18012 KB Output is correct
15 Correct 147 ms 24180 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 3 ms 6748 KB Output is correct
18 Correct 91 ms 22148 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 2 ms 6508 KB Output is correct
21 Correct 2 ms 6580 KB Output is correct
22 Correct 3 ms 6744 KB Output is correct
23 Correct 39 ms 18012 KB Output is correct
24 Correct 136 ms 24048 KB Output is correct
25 Correct 2 ms 6488 KB Output is correct
26 Correct 2 ms 6748 KB Output is correct
27 Correct 73 ms 30212 KB Output is correct
28 Correct 54 ms 20888 KB Output is correct
29 Correct 57 ms 19060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 2 ms 6492 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Correct 2 ms 6492 KB Output is correct
10 Correct 2 ms 6488 KB Output is correct
11 Correct 2 ms 6324 KB Output is correct
12 Correct 3 ms 6488 KB Output is correct
13 Correct 2 ms 6492 KB Output is correct
14 Correct 2 ms 6488 KB Output is correct
15 Correct 2 ms 6488 KB Output is correct
16 Correct 1 ms 6488 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 2 ms 6548 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 2 ms 6492 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 2 ms 6492 KB Output is correct
28 Correct 2 ms 6492 KB Output is correct
29 Correct 2 ms 6492 KB Output is correct
30 Correct 2 ms 6492 KB Output is correct
31 Correct 2 ms 6320 KB Output is correct
32 Correct 2 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 2 ms 6492 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Correct 2 ms 6492 KB Output is correct
10 Correct 2 ms 6488 KB Output is correct
11 Correct 2 ms 6324 KB Output is correct
12 Correct 3 ms 6488 KB Output is correct
13 Correct 2 ms 6492 KB Output is correct
14 Correct 2 ms 6488 KB Output is correct
15 Correct 2 ms 6488 KB Output is correct
16 Correct 1 ms 6488 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 2 ms 6548 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 2 ms 6492 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 2 ms 6492 KB Output is correct
28 Correct 2 ms 6492 KB Output is correct
29 Correct 2 ms 6492 KB Output is correct
30 Correct 2 ms 6492 KB Output is correct
31 Correct 2 ms 6320 KB Output is correct
32 Correct 2 ms 6492 KB Output is correct
33 Correct 2 ms 6748 KB Output is correct
34 Correct 2 ms 6644 KB Output is correct
35 Correct 2 ms 6492 KB Output is correct
36 Correct 3 ms 6748 KB Output is correct
37 Correct 3 ms 6744 KB Output is correct
38 Correct 2 ms 6492 KB Output is correct
39 Correct 3 ms 6748 KB Output is correct
40 Correct 3 ms 6748 KB Output is correct
41 Correct 3 ms 6748 KB Output is correct
42 Correct 2 ms 6492 KB Output is correct
43 Correct 4 ms 6748 KB Output is correct
44 Correct 3 ms 6748 KB Output is correct
45 Correct 3 ms 6748 KB Output is correct
46 Correct 3 ms 6748 KB Output is correct
47 Correct 3 ms 6748 KB Output is correct
48 Correct 4 ms 6748 KB Output is correct
49 Correct 2 ms 6748 KB Output is correct
50 Correct 2 ms 6492 KB Output is correct
51 Correct 3 ms 6748 KB Output is correct
52 Correct 5 ms 6748 KB Output is correct
53 Correct 3 ms 6748 KB Output is correct
54 Correct 3 ms 6748 KB Output is correct
55 Correct 2 ms 6748 KB Output is correct
56 Correct 3 ms 6748 KB Output is correct
57 Correct 3 ms 6748 KB Output is correct
58 Correct 2 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 3 ms 6492 KB Output is correct
3 Correct 2 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 2 ms 6744 KB Output is correct
7 Correct 74 ms 23504 KB Output is correct
8 Correct 88 ms 23500 KB Output is correct
9 Correct 77 ms 24136 KB Output is correct
10 Correct 2 ms 6488 KB Output is correct
11 Correct 2 ms 6492 KB Output is correct
12 Correct 2 ms 6492 KB Output is correct
13 Correct 3 ms 6744 KB Output is correct
14 Correct 41 ms 18012 KB Output is correct
15 Correct 147 ms 24180 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 3 ms 6748 KB Output is correct
18 Correct 91 ms 22148 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 2 ms 6508 KB Output is correct
21 Correct 2 ms 6580 KB Output is correct
22 Correct 3 ms 6744 KB Output is correct
23 Correct 39 ms 18012 KB Output is correct
24 Correct 136 ms 24048 KB Output is correct
25 Correct 2 ms 6488 KB Output is correct
26 Correct 2 ms 6748 KB Output is correct
27 Correct 73 ms 30212 KB Output is correct
28 Correct 54 ms 20888 KB Output is correct
29 Correct 57 ms 19060 KB Output is correct
30 Correct 2 ms 6492 KB Output is correct
31 Correct 2 ms 6492 KB Output is correct
32 Correct 2 ms 6492 KB Output is correct
33 Correct 2 ms 6492 KB Output is correct
34 Correct 2 ms 6492 KB Output is correct
35 Correct 2 ms 6492 KB Output is correct
36 Correct 2 ms 6492 KB Output is correct
37 Correct 2 ms 6492 KB Output is correct
38 Correct 2 ms 6492 KB Output is correct
39 Correct 2 ms 6488 KB Output is correct
40 Correct 2 ms 6324 KB Output is correct
41 Correct 3 ms 6488 KB Output is correct
42 Correct 2 ms 6492 KB Output is correct
43 Correct 2 ms 6488 KB Output is correct
44 Correct 2 ms 6488 KB Output is correct
45 Correct 1 ms 6488 KB Output is correct
46 Correct 1 ms 6492 KB Output is correct
47 Correct 2 ms 6548 KB Output is correct
48 Correct 2 ms 6492 KB Output is correct
49 Correct 2 ms 6492 KB Output is correct
50 Correct 2 ms 6492 KB Output is correct
51 Correct 1 ms 6492 KB Output is correct
52 Correct 1 ms 6492 KB Output is correct
53 Correct 1 ms 6492 KB Output is correct
54 Correct 1 ms 6492 KB Output is correct
55 Correct 1 ms 6492 KB Output is correct
56 Correct 2 ms 6492 KB Output is correct
57 Correct 2 ms 6492 KB Output is correct
58 Correct 2 ms 6492 KB Output is correct
59 Correct 2 ms 6492 KB Output is correct
60 Correct 2 ms 6320 KB Output is correct
61 Correct 2 ms 6492 KB Output is correct
62 Correct 2 ms 6748 KB Output is correct
63 Correct 2 ms 6644 KB Output is correct
64 Correct 2 ms 6492 KB Output is correct
65 Correct 3 ms 6748 KB Output is correct
66 Correct 3 ms 6744 KB Output is correct
67 Correct 2 ms 6492 KB Output is correct
68 Correct 3 ms 6748 KB Output is correct
69 Correct 3 ms 6748 KB Output is correct
70 Correct 3 ms 6748 KB Output is correct
71 Correct 2 ms 6492 KB Output is correct
72 Correct 4 ms 6748 KB Output is correct
73 Correct 3 ms 6748 KB Output is correct
74 Correct 3 ms 6748 KB Output is correct
75 Correct 3 ms 6748 KB Output is correct
76 Correct 3 ms 6748 KB Output is correct
77 Correct 4 ms 6748 KB Output is correct
78 Correct 2 ms 6748 KB Output is correct
79 Correct 2 ms 6492 KB Output is correct
80 Correct 3 ms 6748 KB Output is correct
81 Correct 5 ms 6748 KB Output is correct
82 Correct 3 ms 6748 KB Output is correct
83 Correct 3 ms 6748 KB Output is correct
84 Correct 2 ms 6748 KB Output is correct
85 Correct 3 ms 6748 KB Output is correct
86 Correct 3 ms 6748 KB Output is correct
87 Correct 2 ms 6748 KB Output is correct
88 Correct 87 ms 23600 KB Output is correct
89 Correct 92 ms 23608 KB Output is correct
90 Correct 83 ms 23632 KB Output is correct
91 Correct 38 ms 16720 KB Output is correct
92 Correct 39 ms 16732 KB Output is correct
93 Correct 53 ms 18120 KB Output is correct
94 Correct 53 ms 18012 KB Output is correct
95 Correct 181 ms 24656 KB Output is correct
96 Correct 167 ms 24772 KB Output is correct
97 Correct 173 ms 23376 KB Output is correct
98 Correct 134 ms 23380 KB Output is correct
99 Correct 79 ms 22456 KB Output is correct
100 Correct 87 ms 22100 KB Output is correct
101 Correct 40 ms 16720 KB Output is correct
102 Correct 40 ms 16724 KB Output is correct
103 Correct 57 ms 18136 KB Output is correct
104 Correct 50 ms 18012 KB Output is correct
105 Correct 154 ms 24764 KB Output is correct
106 Correct 163 ms 24768 KB Output is correct
107 Correct 153 ms 29432 KB Output is correct
108 Correct 162 ms 29648 KB Output is correct
109 Correct 68 ms 20884 KB Output is correct
110 Correct 67 ms 21396 KB Output is correct
111 Correct 88 ms 19944 KB Output is correct
112 Correct 97 ms 20048 KB Output is correct