Submission #205880

# Submission time Handle Problem Language Result Execution time Memory
205880 2020-03-01T09:43:39 Z mraron Cheap flights (LMIO18_pigus_skrydziai) C++14
28 / 100
3000 ms 37088 KB
#include<bits/stdc++.h>
using namespace std;
int n,m;
typedef long long ll;
struct el {
	int a,b;
	ll c;
	bool operator<(const el& masik) const {
		if(a==masik.a) return b<masik.b;
		return a<masik.a;
	}
};
vector<el> lst;
vector<pair<int, ll>> adj[300001];
ll cost(int a, int b) {
	if(a>b) swap(a,b);
	auto it=lower_bound(lst.begin(),lst.end(), el{a,b,0});
	if(it==lst.end() || it->a!=a || it->b!=b) return 0;
	return it->c;
}
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;
		lst.push_back({min(a,b),max(a,b),c});
		adj[a].push_back({b,c});
		adj[b].push_back({a,c});
	}
	sort(lst.begin(),lst.end());
	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);
	}
	
	const int lim=200;
	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 i:adj[i]) {
				kell[i.first]=i.second;
			}
			for(auto i:lst) {
				if(kell[i.a] && kell[i.b]) ans=max(ans, kell[i.a]+kell[i.b]+i.c);
			}
		}
	}
	cout<<ans<<"\n";
	return 0;
}

Compilation message

pigus_skrydziai.cpp: In function 'int main()':
pigus_skrydziai.cpp:46:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int j=0;j<adj[i].size();++j) {
                ~^~~~~~~~~~~~~~
pigus_skrydziai.cpp:47: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 9 ms 7416 KB Output is correct
5 Correct 9 ms 7416 KB Output is correct
6 Correct 262 ms 8688 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 11 ms 7416 KB Output is correct
19 Correct 13 ms 7544 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 9 ms 7416 KB Output is correct
5 Correct 9 ms 7416 KB Output is correct
6 Correct 262 ms 8688 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 11 ms 7416 KB Output is correct
19 Correct 13 ms 7544 KB Output is correct
20 Correct 9 ms 7416 KB Output is correct
21 Correct 9 ms 7416 KB Output is correct
22 Execution timed out 3085 ms 37088 KB Time limit exceeded
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 120 ms 19688 KB Output is correct
2 Correct 334 ms 29876 KB Output is correct
3 Correct 92 ms 14180 KB Output is correct
4 Correct 196 ms 20704 KB Output is correct
5 Correct 523 ms 29404 KB Output is correct
6 Correct 167 ms 13412 KB Output is correct
7 Correct 152 ms 27356 KB Output is correct
8 Correct 183 ms 31964 KB Output is correct
9 Correct 12 ms 7416 KB Output is correct
10 Correct 159 ms 14840 KB Output is correct
11 Correct 149 ms 29888 KB Output is correct
12 Correct 354 ms 21856 KB Output is correct
13 Correct 9 ms 7416 KB Output is correct
14 Correct 1320 ms 14564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 120 ms 19688 KB Output is correct
2 Correct 334 ms 29876 KB Output is correct
3 Correct 92 ms 14180 KB Output is correct
4 Correct 196 ms 20704 KB Output is correct
5 Correct 523 ms 29404 KB Output is correct
6 Correct 167 ms 13412 KB Output is correct
7 Correct 152 ms 27356 KB Output is correct
8 Correct 183 ms 31964 KB Output is correct
9 Correct 12 ms 7416 KB Output is correct
10 Correct 159 ms 14840 KB Output is correct
11 Correct 149 ms 29888 KB Output is correct
12 Correct 354 ms 21856 KB Output is correct
13 Correct 9 ms 7416 KB Output is correct
14 Correct 1320 ms 14564 KB Output is correct
15 Correct 149 ms 24004 KB Output is correct
16 Correct 563 ms 22752 KB Output is correct
17 Correct 344 ms 24284 KB Output is correct
18 Correct 402 ms 31452 KB Output is correct
19 Correct 75 ms 16084 KB Output is correct
20 Correct 545 ms 33888 KB Output is correct
21 Correct 389 ms 36188 KB Output is correct
22 Correct 242 ms 25440 KB Output is correct
23 Correct 199 ms 28228 KB Output is correct
24 Correct 101 ms 19172 KB Output is correct
25 Correct 774 ms 33372 KB Output is correct
26 Correct 284 ms 31068 KB Output is correct
27 Correct 992 ms 30688 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 9 ms 7416 KB Output is correct
32 Correct 9 ms 7416 KB Output is correct
33 Correct 262 ms 8688 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 11 ms 7416 KB Output is correct
46 Correct 13 ms 7544 KB Output is correct
47 Correct 9 ms 7416 KB Output is correct
48 Correct 9 ms 7416 KB Output is correct
49 Execution timed out 3085 ms 37088 KB Time limit exceeded
50 Halted 0 ms 0 KB -