답안 #791867

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
791867 2023-07-24T11:55:09 Z Cookie Cheap flights (LMIO18_pigus_skrydziai) C++14
100 / 100
343 ms 66612 KB
#include<bits/stdc++.h>
#include<fstream>
#pragma GCC optimize("Ofast,O3,unroll-loops")
#pragma GCC target("avx2")
using namespace std;
//ifstream fin("FEEDING.INP");
//ofstream fout("FEEDING.OUT");
#define sz(a) (int)a.size()
#define int long long
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const ll mxn = 3e5 + 5, base = 972663749;
const ll mod = 911382323, inf = 1e9;
int n, m;
vt<pll>g[mxn + 1], adj[mxn + 1];
ll cost[mxn + 1];
signed main()
{
     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    cin >> n >> m;
    forr(i, 0, m){
        ll u, v, w; cin >> u >> v >> w;
        adj[u].pb({v, w}); adj[v].pb({u, w}); cost[u] += w; cost[v] += w;
        g[u].pb({w, v}); g[v].pb({w, u});
    }
    for(int u = 1; u <= n; u++){
        sort(adj[u].begin(), adj[u].end());
        sort(g[u].rbegin(), g[u].rend());
    }
    ll ans = 0;
    for(int i = 1; i <= n; i++){
        ans = max(ans, cost[i]);
        if(sz(g[i]) < 2)continue;
        int u = g[i][0].se, v = g[i][1].se;
        int id = lower_bound(adj[u].begin(), adj[u].end(), make_pair(v, (ll)-1)) - adj[u].begin();
        if(id != sz(adj[u]) && adj[u][id].fi == v){
            ans = max(ans, g[i][0].fi + g[i][1].fi + adj[u][id].se);
        }
    }
    cout << ans;
    return(0);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14420 KB Output is correct
2 Correct 9 ms 14412 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 7 ms 14404 KB Output is correct
5 Correct 8 ms 14412 KB Output is correct
6 Correct 15 ms 16220 KB Output is correct
7 Correct 7 ms 14420 KB Output is correct
8 Correct 7 ms 14420 KB Output is correct
9 Correct 7 ms 14352 KB Output is correct
10 Correct 8 ms 14308 KB Output is correct
11 Correct 11 ms 14420 KB Output is correct
12 Correct 7 ms 14412 KB Output is correct
13 Correct 7 ms 14416 KB Output is correct
14 Correct 7 ms 14360 KB Output is correct
15 Correct 6 ms 14320 KB Output is correct
16 Correct 6 ms 14412 KB Output is correct
17 Correct 7 ms 14420 KB Output is correct
18 Correct 9 ms 14548 KB Output is correct
19 Correct 8 ms 14556 KB Output is correct
20 Correct 7 ms 14420 KB Output is correct
21 Correct 7 ms 14420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14420 KB Output is correct
2 Correct 9 ms 14412 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 7 ms 14404 KB Output is correct
5 Correct 8 ms 14412 KB Output is correct
6 Correct 15 ms 16220 KB Output is correct
7 Correct 7 ms 14420 KB Output is correct
8 Correct 7 ms 14420 KB Output is correct
9 Correct 7 ms 14352 KB Output is correct
10 Correct 8 ms 14308 KB Output is correct
11 Correct 11 ms 14420 KB Output is correct
12 Correct 7 ms 14412 KB Output is correct
13 Correct 7 ms 14416 KB Output is correct
14 Correct 7 ms 14360 KB Output is correct
15 Correct 6 ms 14320 KB Output is correct
16 Correct 6 ms 14412 KB Output is correct
17 Correct 7 ms 14420 KB Output is correct
18 Correct 9 ms 14548 KB Output is correct
19 Correct 8 ms 14556 KB Output is correct
20 Correct 7 ms 14420 KB Output is correct
21 Correct 7 ms 14420 KB Output is correct
22 Correct 214 ms 66612 KB Output is correct
23 Correct 167 ms 55484 KB Output is correct
24 Correct 17 ms 16780 KB Output is correct
25 Correct 9 ms 15060 KB Output is correct
26 Correct 8 ms 15072 KB Output is correct
27 Correct 8 ms 14676 KB Output is correct
28 Correct 86 ms 35384 KB Output is correct
29 Correct 36 ms 22768 KB Output is correct
30 Correct 52 ms 25292 KB Output is correct
31 Correct 7 ms 14432 KB Output is correct
32 Correct 7 ms 14420 KB Output is correct
33 Correct 165 ms 62992 KB Output is correct
34 Correct 121 ms 57732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 118 ms 37760 KB Output is correct
2 Correct 296 ms 51424 KB Output is correct
3 Correct 61 ms 26680 KB Output is correct
4 Correct 156 ms 38944 KB Output is correct
5 Correct 343 ms 51244 KB Output is correct
6 Correct 34 ms 23752 KB Output is correct
7 Correct 94 ms 44236 KB Output is correct
8 Correct 113 ms 49348 KB Output is correct
9 Correct 10 ms 16728 KB Output is correct
10 Correct 35 ms 23700 KB Output is correct
11 Correct 97 ms 46200 KB Output is correct
12 Correct 61 ms 32932 KB Output is correct
13 Correct 7 ms 14292 KB Output is correct
14 Correct 41 ms 24348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 118 ms 37760 KB Output is correct
2 Correct 296 ms 51424 KB Output is correct
3 Correct 61 ms 26680 KB Output is correct
4 Correct 156 ms 38944 KB Output is correct
5 Correct 343 ms 51244 KB Output is correct
6 Correct 34 ms 23752 KB Output is correct
7 Correct 94 ms 44236 KB Output is correct
8 Correct 113 ms 49348 KB Output is correct
9 Correct 10 ms 16728 KB Output is correct
10 Correct 35 ms 23700 KB Output is correct
11 Correct 97 ms 46200 KB Output is correct
12 Correct 61 ms 32932 KB Output is correct
13 Correct 7 ms 14292 KB Output is correct
14 Correct 41 ms 24348 KB Output is correct
15 Correct 9 ms 14420 KB Output is correct
16 Correct 9 ms 14412 KB Output is correct
17 Correct 7 ms 14420 KB Output is correct
18 Correct 7 ms 14404 KB Output is correct
19 Correct 8 ms 14412 KB Output is correct
20 Correct 15 ms 16220 KB Output is correct
21 Correct 7 ms 14420 KB Output is correct
22 Correct 7 ms 14420 KB Output is correct
23 Correct 7 ms 14352 KB Output is correct
24 Correct 8 ms 14308 KB Output is correct
25 Correct 11 ms 14420 KB Output is correct
26 Correct 7 ms 14412 KB Output is correct
27 Correct 7 ms 14416 KB Output is correct
28 Correct 7 ms 14360 KB Output is correct
29 Correct 6 ms 14320 KB Output is correct
30 Correct 6 ms 14412 KB Output is correct
31 Correct 7 ms 14420 KB Output is correct
32 Correct 9 ms 14548 KB Output is correct
33 Correct 8 ms 14556 KB Output is correct
34 Correct 7 ms 14420 KB Output is correct
35 Correct 7 ms 14420 KB Output is correct
36 Correct 214 ms 66612 KB Output is correct
37 Correct 167 ms 55484 KB Output is correct
38 Correct 17 ms 16780 KB Output is correct
39 Correct 9 ms 15060 KB Output is correct
40 Correct 8 ms 15072 KB Output is correct
41 Correct 8 ms 14676 KB Output is correct
42 Correct 86 ms 35384 KB Output is correct
43 Correct 36 ms 22768 KB Output is correct
44 Correct 52 ms 25292 KB Output is correct
45 Correct 7 ms 14432 KB Output is correct
46 Correct 7 ms 14420 KB Output is correct
47 Correct 165 ms 62992 KB Output is correct
48 Correct 121 ms 57732 KB Output is correct
49 Correct 159 ms 35644 KB Output is correct
50 Correct 95 ms 34372 KB Output is correct
51 Correct 120 ms 36720 KB Output is correct
52 Correct 150 ms 39300 KB Output is correct
53 Correct 78 ms 26424 KB Output is correct
54 Correct 140 ms 52464 KB Output is correct
55 Correct 292 ms 54052 KB Output is correct
56 Correct 169 ms 40644 KB Output is correct
57 Correct 192 ms 44096 KB Output is correct
58 Correct 85 ms 29320 KB Output is correct
59 Correct 191 ms 48172 KB Output is correct
60 Correct 162 ms 43608 KB Output is correct
61 Correct 131 ms 41676 KB Output is correct