Submission #256143

# Submission time Handle Problem Language Result Execution time Memory
256143 2020-08-02T10:18:47 Z aloo123 Cheap flights (LMIO18_pigus_skrydziai) C++14
100 / 100
1653 ms 97400 KB
		#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <climits>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define in insert
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define f first
#define s second
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define int ll
#define sz(x) (ll)x.size()
#define all(x) (x.begin(),x.end())
using namespace std;

 
const ll INF = 1e12;
const ll N =(3e5+5); // TODO : change value as per problem
const ll MOD = 1e9+7;
vector<pair<int,int>> adj2[N];
map<pll,ll> cost;
void solve(){
	int n,m;
	cin >> n >> m;
	for(int i =1;i<=m;i++){
		int u,v;
		int ch;
		cin >> u >> v >> ch;
		adj2[u].pb({ch,v});
		adj2[v].pb({ch,u});
		cost[{u,v}] = ch;
		cost[{v,u}] = ch;
	}
	for(int i =1;i<=n;i++){
		sort(adj2[i].begin(),adj2[i].end());
	}	
	int ans = 0;
	for(int i =1 ;i<=n;i++){
		int cur = 0;
		if((int)adj2[i].size() < 2) continue;
		// it--;
		// auto it2 = it-1;
		pll p = adj2[i].back();
		int u = p.s;
		cur += p.f;

		// it++;
		pll p2 = adj2[i][adj2[i].size()-2];
		int v = p2.s;
		cur += p2.f;
		cur += cost[{u,v}];
		ans = max(ans,cur);
	}	
	for(int i =1;i<=n;i++){
		int cur = 0;
		for(auto p:adj2[i]){
			cur += p.f;
		}
		ans = max(ans,cur);
	}
	cout << ans << endl;
	


}
signed main(){
 
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
     // freopen(".in","r",stdin);freopen(".out","w",stdout);
    
     ll tt=1;   
     // cin >> tt;
    while(tt--){    
        solve();
    }    
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7424 KB Output is correct
2 Correct 4 ms 7424 KB Output is correct
3 Correct 4 ms 7424 KB Output is correct
4 Correct 5 ms 7424 KB Output is correct
5 Correct 5 ms 7424 KB Output is correct
6 Correct 21 ms 10752 KB Output is correct
7 Correct 4 ms 7424 KB Output is correct
8 Correct 5 ms 7424 KB Output is correct
9 Correct 5 ms 7424 KB Output is correct
10 Correct 5 ms 7424 KB Output is correct
11 Correct 6 ms 7424 KB Output is correct
12 Correct 6 ms 7424 KB Output is correct
13 Correct 5 ms 7424 KB Output is correct
14 Correct 5 ms 7424 KB Output is correct
15 Correct 6 ms 7424 KB Output is correct
16 Correct 5 ms 7424 KB Output is correct
17 Correct 5 ms 7424 KB Output is correct
18 Correct 6 ms 7552 KB Output is correct
19 Correct 7 ms 7680 KB Output is correct
20 Correct 7 ms 7424 KB Output is correct
21 Correct 5 ms 7424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7424 KB Output is correct
2 Correct 4 ms 7424 KB Output is correct
3 Correct 4 ms 7424 KB Output is correct
4 Correct 5 ms 7424 KB Output is correct
5 Correct 5 ms 7424 KB Output is correct
6 Correct 21 ms 10752 KB Output is correct
7 Correct 4 ms 7424 KB Output is correct
8 Correct 5 ms 7424 KB Output is correct
9 Correct 5 ms 7424 KB Output is correct
10 Correct 5 ms 7424 KB Output is correct
11 Correct 6 ms 7424 KB Output is correct
12 Correct 6 ms 7424 KB Output is correct
13 Correct 5 ms 7424 KB Output is correct
14 Correct 5 ms 7424 KB Output is correct
15 Correct 6 ms 7424 KB Output is correct
16 Correct 5 ms 7424 KB Output is correct
17 Correct 5 ms 7424 KB Output is correct
18 Correct 6 ms 7552 KB Output is correct
19 Correct 7 ms 7680 KB Output is correct
20 Correct 7 ms 7424 KB Output is correct
21 Correct 5 ms 7424 KB Output is correct
22 Correct 1653 ms 90820 KB Output is correct
23 Correct 596 ms 94860 KB Output is correct
24 Correct 29 ms 11260 KB Output is correct
25 Correct 11 ms 8576 KB Output is correct
26 Correct 13 ms 8576 KB Output is correct
27 Correct 9 ms 7936 KB Output is correct
28 Correct 514 ms 44068 KB Output is correct
29 Correct 214 ms 21752 KB Output is correct
30 Correct 274 ms 29176 KB Output is correct
31 Correct 6 ms 7552 KB Output is correct
32 Correct 5 ms 7552 KB Output is correct
33 Correct 640 ms 97400 KB Output is correct
34 Correct 518 ms 88184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 302 ms 35664 KB Output is correct
2 Correct 808 ms 79064 KB Output is correct
3 Correct 218 ms 31480 KB Output is correct
4 Correct 451 ms 53240 KB Output is correct
5 Correct 1448 ms 70768 KB Output is correct
6 Correct 115 ms 27128 KB Output is correct
7 Correct 300 ms 62200 KB Output is correct
8 Correct 301 ms 59000 KB Output is correct
9 Correct 8 ms 7552 KB Output is correct
10 Correct 131 ms 27128 KB Output is correct
11 Correct 327 ms 61444 KB Output is correct
12 Correct 264 ms 46888 KB Output is correct
13 Correct 5 ms 7424 KB Output is correct
14 Correct 224 ms 24184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 302 ms 35664 KB Output is correct
2 Correct 808 ms 79064 KB Output is correct
3 Correct 218 ms 31480 KB Output is correct
4 Correct 451 ms 53240 KB Output is correct
5 Correct 1448 ms 70768 KB Output is correct
6 Correct 115 ms 27128 KB Output is correct
7 Correct 300 ms 62200 KB Output is correct
8 Correct 301 ms 59000 KB Output is correct
9 Correct 8 ms 7552 KB Output is correct
10 Correct 131 ms 27128 KB Output is correct
11 Correct 327 ms 61444 KB Output is correct
12 Correct 264 ms 46888 KB Output is correct
13 Correct 5 ms 7424 KB Output is correct
14 Correct 224 ms 24184 KB Output is correct
15 Correct 551 ms 43468 KB Output is correct
16 Correct 511 ms 40404 KB Output is correct
17 Correct 744 ms 44412 KB Output is correct
18 Correct 989 ms 53956 KB Output is correct
19 Correct 208 ms 24552 KB Output is correct
20 Correct 840 ms 59384 KB Output is correct
21 Correct 794 ms 79224 KB Output is correct
22 Correct 519 ms 55160 KB Output is correct
23 Correct 583 ms 53596 KB Output is correct
24 Correct 351 ms 34132 KB Output is correct
25 Correct 953 ms 61560 KB Output is correct
26 Correct 785 ms 57396 KB Output is correct
27 Correct 1107 ms 55248 KB Output is correct
28 Correct 5 ms 7424 KB Output is correct
29 Correct 4 ms 7424 KB Output is correct
30 Correct 4 ms 7424 KB Output is correct
31 Correct 5 ms 7424 KB Output is correct
32 Correct 5 ms 7424 KB Output is correct
33 Correct 21 ms 10752 KB Output is correct
34 Correct 4 ms 7424 KB Output is correct
35 Correct 5 ms 7424 KB Output is correct
36 Correct 5 ms 7424 KB Output is correct
37 Correct 5 ms 7424 KB Output is correct
38 Correct 6 ms 7424 KB Output is correct
39 Correct 6 ms 7424 KB Output is correct
40 Correct 5 ms 7424 KB Output is correct
41 Correct 5 ms 7424 KB Output is correct
42 Correct 6 ms 7424 KB Output is correct
43 Correct 5 ms 7424 KB Output is correct
44 Correct 5 ms 7424 KB Output is correct
45 Correct 6 ms 7552 KB Output is correct
46 Correct 7 ms 7680 KB Output is correct
47 Correct 7 ms 7424 KB Output is correct
48 Correct 5 ms 7424 KB Output is correct
49 Correct 1653 ms 90820 KB Output is correct
50 Correct 596 ms 94860 KB Output is correct
51 Correct 29 ms 11260 KB Output is correct
52 Correct 11 ms 8576 KB Output is correct
53 Correct 13 ms 8576 KB Output is correct
54 Correct 9 ms 7936 KB Output is correct
55 Correct 514 ms 44068 KB Output is correct
56 Correct 214 ms 21752 KB Output is correct
57 Correct 274 ms 29176 KB Output is correct
58 Correct 6 ms 7552 KB Output is correct
59 Correct 5 ms 7552 KB Output is correct
60 Correct 640 ms 97400 KB Output is correct
61 Correct 518 ms 88184 KB Output is correct