Submission #498729

# Submission time Handle Problem Language Result Execution time Memory
498729 2021-12-26T09:13:36 Z Kipras Cheap flights (LMIO18_pigus_skrydziai) C++14
37 / 100
351 ms 67436 KB
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;

const ll maxN = (1e5*5)+10;

ll n, m;
vector<pair<ll, ll>> adj[maxN];
vector<pair<ll, ll>> adjFast[maxN];

ll findVal(ll v, ll v1){
    ll l = 0, h = adjFast[v1].size()-1;
    while(l<h){
        ll mid = l+((h-l)/2);
        if(adjFast[v1][mid].first==v)return adjFast[v1][mid].second;
        else if(adjFast[v1][mid].first<v)l=mid+1;
        else h=mid-1;
    }
    return -1;
}

int main()
{

    ios_base::sync_with_stdio(0);cin.tie(nullptr);

    cin>>n>>m;
    for(ll i = 0; i < m; i++){
        ll a, b, c;
        cin>>a>>b>>c;
        adj[a].push_back({b, c});
        adj[b].push_back({a, c});
        adjFast[a].push_back({b, c});
        adjFast[b].push_back({a, c});
    }

    for(ll i = 1; i <= n; i++)sort(adjFast[i].begin(), adjFast[i].end());

    ll ans=0;

    for(ll i = 1; i <= n; i++){
        ll temp=0;
        for(auto x : adj[i]){
            temp+=x.second;
        }
        for(ll x = 0; x < (ll)(adj[i].size()); x++){
            ll val=-1;
            ll v1=adj[i][x].first, v2=adj[i][x+1].first;
            val = findVal(v2, v1);
            if(val==-1)continue;
            temp=max(temp, adj[i][x].second+adj[i][x+1].second+val);
        }

        ans=max(ans, temp);
    }

    cout<<ans;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23756 KB Output is correct
2 Correct 12 ms 23700 KB Output is correct
3 Correct 12 ms 23748 KB Output is correct
4 Correct 11 ms 23756 KB Output is correct
5 Correct 12 ms 23696 KB Output is correct
6 Correct 17 ms 25420 KB Output is correct
7 Correct 12 ms 23756 KB Output is correct
8 Correct 12 ms 23700 KB Output is correct
9 Correct 12 ms 23776 KB Output is correct
10 Correct 16 ms 23756 KB Output is correct
11 Correct 15 ms 23756 KB Output is correct
12 Correct 12 ms 23756 KB Output is correct
13 Correct 12 ms 23760 KB Output is correct
14 Correct 12 ms 23796 KB Output is correct
15 Correct 13 ms 23756 KB Output is correct
16 Correct 12 ms 23756 KB Output is correct
17 Correct 12 ms 23752 KB Output is correct
18 Correct 13 ms 23884 KB Output is correct
19 Correct 13 ms 23908 KB Output is correct
20 Correct 12 ms 23816 KB Output is correct
21 Correct 11 ms 23756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23756 KB Output is correct
2 Correct 12 ms 23700 KB Output is correct
3 Correct 12 ms 23748 KB Output is correct
4 Correct 11 ms 23756 KB Output is correct
5 Correct 12 ms 23696 KB Output is correct
6 Correct 17 ms 25420 KB Output is correct
7 Correct 12 ms 23756 KB Output is correct
8 Correct 12 ms 23700 KB Output is correct
9 Correct 12 ms 23776 KB Output is correct
10 Correct 16 ms 23756 KB Output is correct
11 Correct 15 ms 23756 KB Output is correct
12 Correct 12 ms 23756 KB Output is correct
13 Correct 12 ms 23760 KB Output is correct
14 Correct 12 ms 23796 KB Output is correct
15 Correct 13 ms 23756 KB Output is correct
16 Correct 12 ms 23756 KB Output is correct
17 Correct 12 ms 23752 KB Output is correct
18 Correct 13 ms 23884 KB Output is correct
19 Correct 13 ms 23908 KB Output is correct
20 Correct 12 ms 23816 KB Output is correct
21 Correct 11 ms 23756 KB Output is correct
22 Correct 351 ms 67436 KB Output is correct
23 Correct 204 ms 56432 KB Output is correct
24 Correct 23 ms 25888 KB Output is correct
25 Correct 16 ms 24404 KB Output is correct
26 Correct 15 ms 24396 KB Output is correct
27 Correct 14 ms 23984 KB Output is correct
28 Correct 104 ms 41280 KB Output is correct
29 Correct 56 ms 31120 KB Output is correct
30 Correct 79 ms 32528 KB Output is correct
31 Correct 15 ms 23884 KB Output is correct
32 Correct 12 ms 23796 KB Output is correct
33 Correct 201 ms 64292 KB Output is correct
34 Correct 155 ms 61840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 144 ms 42564 KB Output is correct
2 Incorrect 346 ms 54140 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 144 ms 42564 KB Output is correct
2 Incorrect 346 ms 54140 KB Output isn't correct
3 Halted 0 ms 0 KB -