Submission #205894

# Submission time Handle Problem Language Result Execution time Memory
205894 2020-03-01T09:57:42 Z mraron Cheap flights (LMIO18_pigus_skrydziai) C++14
100 / 100
2260 ms 29304 KB
#include<bits/stdc++.h>
using namespace std;
int n,m;
typedef long long ll;

vector<pair<int, ll>> adj[300001];
ll cost(int a, int b) {
	if(adj[a].size()>adj[b].size()) swap(a,b);
	auto it=lower_bound(adj[a].begin(),adj[a].end(), make_pair(b,0LL));
	if(it==adj[a].end() || it->first!=b) return 0;
	return it->second;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	for(int i=0;i<m;++i) {
		int a,b,c;
		cin>>a>>b>>c;
		adj[a].push_back({b,c});
		adj[b].push_back({a,c});
	}
	ll ans=0;
	for(int i=1;i<=n;++i) {
		ll cans=0;
		for(auto j:adj[i]) {
			cans+=j.second;
		}
		ans=max(ans, cans);
		sort(adj[i].begin(),adj[i].end());
	}
	
	const int lim=128;
	for(int i=1;i<=n;++i) {
		if(adj[i].size()<=lim) {
			for(int j=0;j<adj[i].size();++j) {
				for(int k=j+1;k<adj[i].size();++k) {
					ans=max(ans, adj[i][j].second+adj[i][k].second+cost(adj[i][j].first, adj[i][k].first));
				}
			}
		}else {
			vector<int> kell(n+1);
			for(auto j:adj[i]) {
				kell[j.first]=j.second;
			}
			for(auto j:adj[i]) {
				for(auto k:adj[j.first]) {
					if(kell[k.first]) ans=max(ans, k.second+j.second+kell[k.first]);
				}
			}
		}
	}
	cout<<ans<<"\n";
	return 0;
}

Compilation message

pigus_skrydziai.cpp: In function 'int main()':
pigus_skrydziai.cpp:37:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int j=0;j<adj[i].size();++j) {
                ~^~~~~~~~~~~~~~
pigus_skrydziai.cpp:38:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int k=j+1;k<adj[i].size();++k) {
                   ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7416 KB Output is correct
2 Correct 9 ms 7416 KB Output is correct
3 Correct 9 ms 7416 KB Output is correct
4 Correct 10 ms 7416 KB Output is correct
5 Correct 9 ms 7416 KB Output is correct
6 Correct 28 ms 8184 KB Output is correct
7 Correct 9 ms 7416 KB Output is correct
8 Correct 9 ms 7416 KB Output is correct
9 Correct 9 ms 7416 KB Output is correct
10 Correct 9 ms 7416 KB Output is correct
11 Correct 10 ms 7416 KB Output is correct
12 Correct 9 ms 7416 KB Output is correct
13 Correct 9 ms 7416 KB Output is correct
14 Correct 10 ms 7416 KB Output is correct
15 Correct 9 ms 7416 KB Output is correct
16 Correct 9 ms 7416 KB Output is correct
17 Correct 9 ms 7416 KB Output is correct
18 Correct 10 ms 7416 KB Output is correct
19 Correct 11 ms 7416 KB Output is correct
20 Correct 9 ms 7416 KB Output is correct
21 Correct 9 ms 7416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7416 KB Output is correct
2 Correct 9 ms 7416 KB Output is correct
3 Correct 9 ms 7416 KB Output is correct
4 Correct 10 ms 7416 KB Output is correct
5 Correct 9 ms 7416 KB Output is correct
6 Correct 28 ms 8184 KB Output is correct
7 Correct 9 ms 7416 KB Output is correct
8 Correct 9 ms 7416 KB Output is correct
9 Correct 9 ms 7416 KB Output is correct
10 Correct 9 ms 7416 KB Output is correct
11 Correct 10 ms 7416 KB Output is correct
12 Correct 9 ms 7416 KB Output is correct
13 Correct 9 ms 7416 KB Output is correct
14 Correct 10 ms 7416 KB Output is correct
15 Correct 9 ms 7416 KB Output is correct
16 Correct 9 ms 7416 KB Output is correct
17 Correct 9 ms 7416 KB Output is correct
18 Correct 10 ms 7416 KB Output is correct
19 Correct 11 ms 7416 KB Output is correct
20 Correct 9 ms 7416 KB Output is correct
21 Correct 9 ms 7416 KB Output is correct
22 Correct 855 ms 29304 KB Output is correct
23 Correct 2260 ms 23672 KB Output is correct
24 Correct 48 ms 8568 KB Output is correct
25 Correct 14 ms 7672 KB Output is correct
26 Correct 14 ms 7672 KB Output is correct
27 Correct 10 ms 7544 KB Output is correct
28 Correct 256 ms 16120 KB Output is correct
29 Correct 138 ms 11128 KB Output is correct
30 Correct 256 ms 11768 KB Output is correct
31 Correct 10 ms 7416 KB Output is correct
32 Correct 9 ms 7416 KB Output is correct
33 Correct 783 ms 27584 KB Output is correct
34 Correct 700 ms 26360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 122 ms 16888 KB Output is correct
2 Correct 280 ms 23032 KB Output is correct
3 Correct 72 ms 12664 KB Output is correct
4 Correct 171 ms 17660 KB Output is correct
5 Correct 354 ms 22968 KB Output is correct
6 Correct 238 ms 11512 KB Output is correct
7 Correct 129 ms 19544 KB Output is correct
8 Correct 149 ms 21424 KB Output is correct
9 Correct 12 ms 7416 KB Output is correct
10 Correct 229 ms 11512 KB Output is correct
11 Correct 136 ms 21612 KB Output is correct
12 Correct 331 ms 15588 KB Output is correct
13 Correct 9 ms 7416 KB Output is correct
14 Correct 488 ms 11840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 122 ms 16888 KB Output is correct
2 Correct 280 ms 23032 KB Output is correct
3 Correct 72 ms 12664 KB Output is correct
4 Correct 171 ms 17660 KB Output is correct
5 Correct 354 ms 22968 KB Output is correct
6 Correct 238 ms 11512 KB Output is correct
7 Correct 129 ms 19544 KB Output is correct
8 Correct 149 ms 21424 KB Output is correct
9 Correct 12 ms 7416 KB Output is correct
10 Correct 229 ms 11512 KB Output is correct
11 Correct 136 ms 21612 KB Output is correct
12 Correct 331 ms 15588 KB Output is correct
13 Correct 9 ms 7416 KB Output is correct
14 Correct 488 ms 11840 KB Output is correct
15 Correct 136 ms 17240 KB Output is correct
16 Correct 227 ms 15580 KB Output is correct
17 Correct 367 ms 16484 KB Output is correct
18 Correct 375 ms 17608 KB Output is correct
19 Correct 74 ms 12648 KB Output is correct
20 Correct 689 ms 23800 KB Output is correct
21 Correct 323 ms 23228 KB Output is correct
22 Correct 192 ms 17784 KB Output is correct
23 Correct 189 ms 20060 KB Output is correct
24 Correct 103 ms 14280 KB Output is correct
25 Correct 360 ms 21752 KB Output is correct
26 Correct 238 ms 20524 KB Output is correct
27 Correct 403 ms 19192 KB Output is correct
28 Correct 9 ms 7416 KB Output is correct
29 Correct 9 ms 7416 KB Output is correct
30 Correct 9 ms 7416 KB Output is correct
31 Correct 10 ms 7416 KB Output is correct
32 Correct 9 ms 7416 KB Output is correct
33 Correct 28 ms 8184 KB Output is correct
34 Correct 9 ms 7416 KB Output is correct
35 Correct 9 ms 7416 KB Output is correct
36 Correct 9 ms 7416 KB Output is correct
37 Correct 9 ms 7416 KB Output is correct
38 Correct 10 ms 7416 KB Output is correct
39 Correct 9 ms 7416 KB Output is correct
40 Correct 9 ms 7416 KB Output is correct
41 Correct 10 ms 7416 KB Output is correct
42 Correct 9 ms 7416 KB Output is correct
43 Correct 9 ms 7416 KB Output is correct
44 Correct 9 ms 7416 KB Output is correct
45 Correct 10 ms 7416 KB Output is correct
46 Correct 11 ms 7416 KB Output is correct
47 Correct 9 ms 7416 KB Output is correct
48 Correct 9 ms 7416 KB Output is correct
49 Correct 855 ms 29304 KB Output is correct
50 Correct 2260 ms 23672 KB Output is correct
51 Correct 48 ms 8568 KB Output is correct
52 Correct 14 ms 7672 KB Output is correct
53 Correct 14 ms 7672 KB Output is correct
54 Correct 10 ms 7544 KB Output is correct
55 Correct 256 ms 16120 KB Output is correct
56 Correct 138 ms 11128 KB Output is correct
57 Correct 256 ms 11768 KB Output is correct
58 Correct 10 ms 7416 KB Output is correct
59 Correct 9 ms 7416 KB Output is correct
60 Correct 783 ms 27584 KB Output is correct
61 Correct 700 ms 26360 KB Output is correct