Submission #498279

# Submission time Handle Problem Language Result Execution time Memory
498279 2021-12-24T19:03:35 Z Kipras Cheap flights (LMIO18_pigus_skrydziai) C++14
53 / 100
645 ms 57996 KB
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;

const int maxN = 1e5*3+1;

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

int findVal(int v, int v1){
    int l = 0, h = adjFast[v1].size();
    while(l<h){
        int 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(int 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(int i = 1; i <= n; i++)sort(adjFast[i].begin(), adjFast[i].end());

    ll ans=0;

    for(int i = 1; i <= n; i++){
        ll temp=0;
        for(auto x : adj[i]){
            temp+=x.second;
        }
        ans=max(ans, temp);
    }

    for(int i = 1; i <= n; i++){
        for(int x = 0; x < (int)(adj[i].size())-1; x++){
            ll temp=0;
            ll val=-1;
            ll v1=adj[i][x].first, v2=adj[i][x+1].first;
            val = findVal(v2, v1);
            if(val==-1)continue;
            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 14284 KB Output is correct
2 Correct 10 ms 14296 KB Output is correct
3 Correct 9 ms 14284 KB Output is correct
4 Correct 8 ms 14284 KB Output is correct
5 Correct 8 ms 14308 KB Output is correct
6 Correct 21 ms 16012 KB Output is correct
7 Correct 9 ms 14284 KB Output is correct
8 Correct 8 ms 14372 KB Output is correct
9 Correct 8 ms 14404 KB Output is correct
10 Correct 8 ms 14284 KB Output is correct
11 Correct 9 ms 14412 KB Output is correct
12 Correct 10 ms 14412 KB Output is correct
13 Correct 8 ms 14284 KB Output is correct
14 Correct 7 ms 14284 KB Output is correct
15 Correct 8 ms 14284 KB Output is correct
16 Correct 7 ms 14340 KB Output is correct
17 Correct 8 ms 14284 KB Output is correct
18 Correct 8 ms 14412 KB Output is correct
19 Correct 9 ms 14540 KB Output is correct
20 Correct 8 ms 14284 KB Output is correct
21 Correct 8 ms 14376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 14284 KB Output is correct
2 Correct 10 ms 14296 KB Output is correct
3 Correct 9 ms 14284 KB Output is correct
4 Correct 8 ms 14284 KB Output is correct
5 Correct 8 ms 14308 KB Output is correct
6 Correct 21 ms 16012 KB Output is correct
7 Correct 9 ms 14284 KB Output is correct
8 Correct 8 ms 14372 KB Output is correct
9 Correct 8 ms 14404 KB Output is correct
10 Correct 8 ms 14284 KB Output is correct
11 Correct 9 ms 14412 KB Output is correct
12 Correct 10 ms 14412 KB Output is correct
13 Correct 8 ms 14284 KB Output is correct
14 Correct 7 ms 14284 KB Output is correct
15 Correct 8 ms 14284 KB Output is correct
16 Correct 7 ms 14340 KB Output is correct
17 Correct 8 ms 14284 KB Output is correct
18 Correct 8 ms 14412 KB Output is correct
19 Correct 9 ms 14540 KB Output is correct
20 Correct 8 ms 14284 KB Output is correct
21 Correct 8 ms 14376 KB Output is correct
22 Correct 645 ms 57996 KB Output is correct
23 Correct 457 ms 46756 KB Output is correct
24 Correct 26 ms 16460 KB Output is correct
25 Correct 13 ms 14888 KB Output is correct
26 Correct 14 ms 14980 KB Output is correct
27 Correct 10 ms 14636 KB Output is correct
28 Correct 199 ms 31820 KB Output is correct
29 Correct 83 ms 21696 KB Output is correct
30 Correct 139 ms 23036 KB Output is correct
31 Correct 8 ms 14412 KB Output is correct
32 Correct 8 ms 14412 KB Output is correct
33 Correct 455 ms 54936 KB Output is correct
34 Correct 319 ms 52416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 202 ms 33084 KB Output is correct
2 Correct 475 ms 44572 KB Output is correct
3 Correct 127 ms 24464 KB Output is correct
4 Correct 292 ms 34740 KB Output is correct
5 Correct 578 ms 45408 KB Output is correct
6 Correct 91 ms 22508 KB Output is correct
7 Correct 233 ms 38424 KB Output is correct
8 Correct 283 ms 42548 KB Output is correct
9 Correct 10 ms 14412 KB Output is correct
10 Correct 94 ms 22532 KB Output is correct
11 Correct 236 ms 42000 KB Output is correct
12 Correct 218 ms 32956 KB Output is correct
13 Correct 8 ms 14288 KB Output is correct
14 Correct 98 ms 24360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 202 ms 33084 KB Output is correct
2 Correct 475 ms 44572 KB Output is correct
3 Correct 127 ms 24464 KB Output is correct
4 Correct 292 ms 34740 KB Output is correct
5 Correct 578 ms 45408 KB Output is correct
6 Correct 91 ms 22508 KB Output is correct
7 Correct 233 ms 38424 KB Output is correct
8 Correct 283 ms 42548 KB Output is correct
9 Correct 10 ms 14412 KB Output is correct
10 Correct 94 ms 22532 KB Output is correct
11 Correct 236 ms 42000 KB Output is correct
12 Correct 218 ms 32956 KB Output is correct
13 Correct 8 ms 14288 KB Output is correct
14 Correct 98 ms 24360 KB Output is correct
15 Correct 12 ms 14284 KB Output is correct
16 Correct 10 ms 14296 KB Output is correct
17 Correct 9 ms 14284 KB Output is correct
18 Correct 8 ms 14284 KB Output is correct
19 Correct 8 ms 14308 KB Output is correct
20 Correct 21 ms 16012 KB Output is correct
21 Correct 9 ms 14284 KB Output is correct
22 Correct 8 ms 14372 KB Output is correct
23 Correct 8 ms 14404 KB Output is correct
24 Correct 8 ms 14284 KB Output is correct
25 Correct 9 ms 14412 KB Output is correct
26 Correct 10 ms 14412 KB Output is correct
27 Correct 8 ms 14284 KB Output is correct
28 Correct 7 ms 14284 KB Output is correct
29 Correct 8 ms 14284 KB Output is correct
30 Correct 7 ms 14340 KB Output is correct
31 Correct 8 ms 14284 KB Output is correct
32 Correct 8 ms 14412 KB Output is correct
33 Correct 9 ms 14540 KB Output is correct
34 Correct 8 ms 14284 KB Output is correct
35 Correct 8 ms 14376 KB Output is correct
36 Correct 645 ms 57996 KB Output is correct
37 Correct 457 ms 46756 KB Output is correct
38 Correct 26 ms 16460 KB Output is correct
39 Correct 13 ms 14888 KB Output is correct
40 Correct 14 ms 14980 KB Output is correct
41 Correct 10 ms 14636 KB Output is correct
42 Correct 199 ms 31820 KB Output is correct
43 Correct 83 ms 21696 KB Output is correct
44 Correct 139 ms 23036 KB Output is correct
45 Correct 8 ms 14412 KB Output is correct
46 Correct 8 ms 14412 KB Output is correct
47 Correct 455 ms 54936 KB Output is correct
48 Correct 319 ms 52416 KB Output is correct
49 Correct 238 ms 35100 KB Output is correct
50 Correct 214 ms 34224 KB Output is correct
51 Correct 275 ms 35956 KB Output is correct
52 Correct 340 ms 39028 KB Output is correct
53 Correct 133 ms 25620 KB Output is correct
54 Correct 305 ms 52276 KB Output is correct
55 Correct 542 ms 51728 KB Output is correct
56 Correct 346 ms 38988 KB Output is correct
57 Correct 379 ms 42016 KB Output is correct
58 Correct 156 ms 28884 KB Output is correct
59 Correct 414 ms 47796 KB Output is correct
60 Correct 371 ms 43396 KB Output is correct
61 Incorrect 259 ms 41748 KB Output isn't correct