Submission #498282

# Submission time Handle Problem Language Result Execution time Memory
498282 2021-12-24T19:04:51 Z Kipras Cheap flights (LMIO18_pigus_skrydziai) C++14
53 / 100
386 ms 58336 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()-1;
    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 8 ms 14404 KB Output is correct
2 Correct 8 ms 14404 KB Output is correct
3 Correct 7 ms 14404 KB Output is correct
4 Correct 8 ms 14284 KB Output is correct
5 Correct 7 ms 14404 KB Output is correct
6 Correct 14 ms 16076 KB Output is correct
7 Correct 7 ms 14412 KB Output is correct
8 Correct 8 ms 14284 KB Output is correct
9 Correct 7 ms 14412 KB Output is correct
10 Correct 8 ms 14504 KB Output is correct
11 Correct 8 ms 14412 KB Output is correct
12 Correct 9 ms 14412 KB Output is correct
13 Correct 8 ms 14340 KB Output is correct
14 Correct 7 ms 14324 KB Output is correct
15 Correct 8 ms 14348 KB Output is correct
16 Correct 8 ms 14412 KB Output is correct
17 Correct 8 ms 14324 KB Output is correct
18 Correct 8 ms 14412 KB Output is correct
19 Correct 9 ms 14560 KB Output is correct
20 Correct 8 ms 14412 KB Output is correct
21 Correct 7 ms 14404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14404 KB Output is correct
2 Correct 8 ms 14404 KB Output is correct
3 Correct 7 ms 14404 KB Output is correct
4 Correct 8 ms 14284 KB Output is correct
5 Correct 7 ms 14404 KB Output is correct
6 Correct 14 ms 16076 KB Output is correct
7 Correct 7 ms 14412 KB Output is correct
8 Correct 8 ms 14284 KB Output is correct
9 Correct 7 ms 14412 KB Output is correct
10 Correct 8 ms 14504 KB Output is correct
11 Correct 8 ms 14412 KB Output is correct
12 Correct 9 ms 14412 KB Output is correct
13 Correct 8 ms 14340 KB Output is correct
14 Correct 7 ms 14324 KB Output is correct
15 Correct 8 ms 14348 KB Output is correct
16 Correct 8 ms 14412 KB Output is correct
17 Correct 8 ms 14324 KB Output is correct
18 Correct 8 ms 14412 KB Output is correct
19 Correct 9 ms 14560 KB Output is correct
20 Correct 8 ms 14412 KB Output is correct
21 Correct 7 ms 14404 KB Output is correct
22 Correct 364 ms 58336 KB Output is correct
23 Correct 201 ms 46956 KB Output is correct
24 Correct 18 ms 16468 KB Output is correct
25 Correct 12 ms 14996 KB Output is correct
26 Correct 10 ms 14924 KB Output is correct
27 Correct 9 ms 14648 KB Output is correct
28 Correct 100 ms 31932 KB Output is correct
29 Correct 49 ms 21776 KB Output is correct
30 Correct 77 ms 23172 KB Output is correct
31 Correct 8 ms 14408 KB Output is correct
32 Correct 8 ms 14412 KB Output is correct
33 Correct 192 ms 55012 KB Output is correct
34 Correct 148 ms 52548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 125 ms 33284 KB Output is correct
2 Correct 321 ms 44680 KB Output is correct
3 Correct 89 ms 24644 KB Output is correct
4 Correct 205 ms 34672 KB Output is correct
5 Correct 386 ms 45416 KB Output is correct
6 Correct 46 ms 22592 KB Output is correct
7 Correct 110 ms 38504 KB Output is correct
8 Correct 123 ms 42560 KB Output is correct
9 Correct 10 ms 14412 KB Output is correct
10 Correct 45 ms 22540 KB Output is correct
11 Correct 110 ms 42052 KB Output is correct
12 Correct 82 ms 30660 KB Output is correct
13 Correct 8 ms 14284 KB Output is correct
14 Correct 57 ms 23324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 125 ms 33284 KB Output is correct
2 Correct 321 ms 44680 KB Output is correct
3 Correct 89 ms 24644 KB Output is correct
4 Correct 205 ms 34672 KB Output is correct
5 Correct 386 ms 45416 KB Output is correct
6 Correct 46 ms 22592 KB Output is correct
7 Correct 110 ms 38504 KB Output is correct
8 Correct 123 ms 42560 KB Output is correct
9 Correct 10 ms 14412 KB Output is correct
10 Correct 45 ms 22540 KB Output is correct
11 Correct 110 ms 42052 KB Output is correct
12 Correct 82 ms 30660 KB Output is correct
13 Correct 8 ms 14284 KB Output is correct
14 Correct 57 ms 23324 KB Output is correct
15 Correct 8 ms 14404 KB Output is correct
16 Correct 8 ms 14404 KB Output is correct
17 Correct 7 ms 14404 KB Output is correct
18 Correct 8 ms 14284 KB Output is correct
19 Correct 7 ms 14404 KB Output is correct
20 Correct 14 ms 16076 KB Output is correct
21 Correct 7 ms 14412 KB Output is correct
22 Correct 8 ms 14284 KB Output is correct
23 Correct 7 ms 14412 KB Output is correct
24 Correct 8 ms 14504 KB Output is correct
25 Correct 8 ms 14412 KB Output is correct
26 Correct 9 ms 14412 KB Output is correct
27 Correct 8 ms 14340 KB Output is correct
28 Correct 7 ms 14324 KB Output is correct
29 Correct 8 ms 14348 KB Output is correct
30 Correct 8 ms 14412 KB Output is correct
31 Correct 8 ms 14324 KB Output is correct
32 Correct 8 ms 14412 KB Output is correct
33 Correct 9 ms 14560 KB Output is correct
34 Correct 8 ms 14412 KB Output is correct
35 Correct 7 ms 14404 KB Output is correct
36 Correct 364 ms 58336 KB Output is correct
37 Correct 201 ms 46956 KB Output is correct
38 Correct 18 ms 16468 KB Output is correct
39 Correct 12 ms 14996 KB Output is correct
40 Correct 10 ms 14924 KB Output is correct
41 Correct 9 ms 14648 KB Output is correct
42 Correct 100 ms 31932 KB Output is correct
43 Correct 49 ms 21776 KB Output is correct
44 Correct 77 ms 23172 KB Output is correct
45 Correct 8 ms 14408 KB Output is correct
46 Correct 8 ms 14412 KB Output is correct
47 Correct 192 ms 55012 KB Output is correct
48 Correct 148 ms 52548 KB Output is correct
49 Correct 153 ms 32712 KB Output is correct
50 Correct 109 ms 30504 KB Output is correct
51 Correct 156 ms 31832 KB Output is correct
52 Correct 182 ms 34252 KB Output is correct
53 Correct 70 ms 23708 KB Output is correct
54 Correct 161 ms 47264 KB Output is correct
55 Correct 341 ms 44612 KB Output is correct
56 Correct 212 ms 34624 KB Output is correct
57 Correct 207 ms 37900 KB Output is correct
58 Correct 98 ms 27576 KB Output is correct
59 Correct 236 ms 42908 KB Output is correct
60 Correct 177 ms 40148 KB Output is correct
61 Incorrect 158 ms 38420 KB Output isn't correct