Submission #924241

# Submission time Handle Problem Language Result Execution time Memory
924241 2024-02-08T16:49:08 Z dwuy Cheap flights (LMIO18_pigus_skrydziai) C++14
100 / 100
2472 ms 46968 KB
#include <bits/stdc++.h>

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL)
#define file(a) freopen(a".inp","r",stdin); freopen(a".out", "w",stdout)
#define fi first
#define se second
#define endl "\n"
#define len(s) int32_t(s.length())
#define MASK(k)(1LL<<(k))
#define TASK "test"
#define int long long

using namespace std;

typedef tuple<int, int, int> tpiii;
typedef pair<double, double> pdd;
typedef pair<int, int> pii;
typedef long long ll;

const long long OO = 1e18;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int MX = 300005;

int n, m;
int sum[MX];
int cnt[MX];
vector<pii> G[MX];
tpiii edges[MX<<1];
bitset<MX> ok = 0;
int cost[MX];

void nhap(){
    cin >> n >> m;
    for(int i=1; i<=m; i++){
        int u, v, c;
        cin >> u >> v >> c;
        G[u].push_back({v, c});
        G[v].push_back({u, c});
        edges[i] = {c, u, v};
        sum[u] += c;
        sum[v] += c;
        cnt[u]++;
        cnt[v]++;
    }
}

void solve(){
    int ans = 0;
    for(int i=1; i<=n; i++) ans = max(ans, sum[i]);
    for(int i=1; i<=n; i++) if(cnt[i]*cnt[i]>=n){
        for(pii &tmp: G[i]){
            int j, c;
            tie(j, c) = tmp;
            if(j<i && cnt[j]*cnt[j]>=n) continue;
            ok[j] = 1;
            cost[j] = c;
            for(pii &tmp2: G[j]){
                int k, f;
                tie(k, f) = tmp2;
                if(ok[k]) ans = max(ans, c + f + cost[k]);
            }
        }
        for(pii &tmp: G[i]){
            int f, k;
            tie(f, k) = tmp;
            ok[f] = cost[f] = 0;
        }
    }
    sort(edges+1, edges+1+m, greater<tpiii>());
    for(int i=1, f=0; i<=m; i++){
        int c, u, v;
        tie(c, u, v) = edges[i];
        if(cnt[u]*cnt[u]>=n) continue;
        if(cnt[v]*cnt[v]>=n) continue;
        for(pii &tmp: G[u]){
            int f, k;
            tie(f, k) = tmp;
            ok[f] = 1;
            cost[f] = k;
        }
        for(pii &tmp: G[v]){
            int f, k;
            tie(f, k) = tmp;
            if(ok[f]) ans = max(ans, c + k + cost[f]);
        }
        for(pii &tmp: G[u]){
            int f, k;
            tie(f, k) = tmp;
            ok[f] = cost[f] = 0;
        }
    }
    cout << ans;
}

int32_t main(){
    fastIO;
    //file(TASK);

    nhap();
    solve();

    return 0;
}




Compilation message

pigus_skrydziai.cpp: In function 'void solve()':
pigus_skrydziai.cpp:67:29: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   67 |             ok[f] = cost[f] = 0;
      |                     ~~~~~~~~^~~
pigus_skrydziai.cpp:90:29: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   90 |             ok[f] = cost[f] = 0;
      |                     ~~~~~~~~^~~
pigus_skrydziai.cpp:71:18: warning: unused variable 'f' [-Wunused-variable]
   71 |     for(int i=1, f=0; i<=m; i++){
      |                  ^
# Verdict Execution time Memory Grader output
1 Correct 3 ms 14680 KB Output is correct
2 Correct 3 ms 14680 KB Output is correct
3 Correct 3 ms 14684 KB Output is correct
4 Correct 2 ms 14684 KB Output is correct
5 Correct 3 ms 14684 KB Output is correct
6 Correct 12 ms 15448 KB Output is correct
7 Correct 3 ms 14684 KB Output is correct
8 Correct 2 ms 14684 KB Output is correct
9 Correct 3 ms 14684 KB Output is correct
10 Correct 3 ms 14684 KB Output is correct
11 Correct 3 ms 14684 KB Output is correct
12 Correct 3 ms 14684 KB Output is correct
13 Correct 2 ms 14684 KB Output is correct
14 Correct 2 ms 14684 KB Output is correct
15 Correct 2 ms 14684 KB Output is correct
16 Correct 3 ms 14684 KB Output is correct
17 Correct 2 ms 14684 KB Output is correct
18 Correct 3 ms 14684 KB Output is correct
19 Correct 3 ms 14940 KB Output is correct
20 Correct 3 ms 14684 KB Output is correct
21 Correct 2 ms 14684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 14680 KB Output is correct
2 Correct 3 ms 14680 KB Output is correct
3 Correct 3 ms 14684 KB Output is correct
4 Correct 2 ms 14684 KB Output is correct
5 Correct 3 ms 14684 KB Output is correct
6 Correct 12 ms 15448 KB Output is correct
7 Correct 3 ms 14684 KB Output is correct
8 Correct 2 ms 14684 KB Output is correct
9 Correct 3 ms 14684 KB Output is correct
10 Correct 3 ms 14684 KB Output is correct
11 Correct 3 ms 14684 KB Output is correct
12 Correct 3 ms 14684 KB Output is correct
13 Correct 2 ms 14684 KB Output is correct
14 Correct 2 ms 14684 KB Output is correct
15 Correct 2 ms 14684 KB Output is correct
16 Correct 3 ms 14684 KB Output is correct
17 Correct 2 ms 14684 KB Output is correct
18 Correct 3 ms 14684 KB Output is correct
19 Correct 3 ms 14940 KB Output is correct
20 Correct 3 ms 14684 KB Output is correct
21 Correct 2 ms 14684 KB Output is correct
22 Correct 324 ms 46968 KB Output is correct
23 Correct 723 ms 41368 KB Output is correct
24 Correct 9 ms 15704 KB Output is correct
25 Correct 5 ms 14940 KB Output is correct
26 Correct 6 ms 15104 KB Output is correct
27 Correct 3 ms 14936 KB Output is correct
28 Correct 141 ms 27800 KB Output is correct
29 Correct 136 ms 18528 KB Output is correct
30 Correct 263 ms 21320 KB Output is correct
31 Correct 3 ms 14684 KB Output is correct
32 Correct 3 ms 14684 KB Output is correct
33 Correct 2472 ms 45324 KB Output is correct
34 Correct 2007 ms 44112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 70 ms 29812 KB Output is correct
2 Correct 180 ms 40120 KB Output is correct
3 Correct 41 ms 24172 KB Output is correct
4 Correct 106 ms 31828 KB Output is correct
5 Correct 195 ms 39252 KB Output is correct
6 Correct 95 ms 20816 KB Output is correct
7 Correct 72 ms 36176 KB Output is correct
8 Correct 80 ms 38484 KB Output is correct
9 Correct 4 ms 18264 KB Output is correct
10 Correct 95 ms 20980 KB Output is correct
11 Correct 71 ms 39096 KB Output is correct
12 Correct 169 ms 27088 KB Output is correct
13 Correct 3 ms 14684 KB Output is correct
14 Correct 45 ms 21340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 70 ms 29812 KB Output is correct
2 Correct 180 ms 40120 KB Output is correct
3 Correct 41 ms 24172 KB Output is correct
4 Correct 106 ms 31828 KB Output is correct
5 Correct 195 ms 39252 KB Output is correct
6 Correct 95 ms 20816 KB Output is correct
7 Correct 72 ms 36176 KB Output is correct
8 Correct 80 ms 38484 KB Output is correct
9 Correct 4 ms 18264 KB Output is correct
10 Correct 95 ms 20980 KB Output is correct
11 Correct 71 ms 39096 KB Output is correct
12 Correct 169 ms 27088 KB Output is correct
13 Correct 3 ms 14684 KB Output is correct
14 Correct 45 ms 21340 KB Output is correct
15 Correct 3 ms 14680 KB Output is correct
16 Correct 3 ms 14680 KB Output is correct
17 Correct 3 ms 14684 KB Output is correct
18 Correct 2 ms 14684 KB Output is correct
19 Correct 3 ms 14684 KB Output is correct
20 Correct 12 ms 15448 KB Output is correct
21 Correct 3 ms 14684 KB Output is correct
22 Correct 2 ms 14684 KB Output is correct
23 Correct 3 ms 14684 KB Output is correct
24 Correct 3 ms 14684 KB Output is correct
25 Correct 3 ms 14684 KB Output is correct
26 Correct 3 ms 14684 KB Output is correct
27 Correct 2 ms 14684 KB Output is correct
28 Correct 2 ms 14684 KB Output is correct
29 Correct 2 ms 14684 KB Output is correct
30 Correct 3 ms 14684 KB Output is correct
31 Correct 2 ms 14684 KB Output is correct
32 Correct 3 ms 14684 KB Output is correct
33 Correct 3 ms 14940 KB Output is correct
34 Correct 3 ms 14684 KB Output is correct
35 Correct 2 ms 14684 KB Output is correct
36 Correct 324 ms 46968 KB Output is correct
37 Correct 723 ms 41368 KB Output is correct
38 Correct 9 ms 15704 KB Output is correct
39 Correct 5 ms 14940 KB Output is correct
40 Correct 6 ms 15104 KB Output is correct
41 Correct 3 ms 14936 KB Output is correct
42 Correct 141 ms 27800 KB Output is correct
43 Correct 136 ms 18528 KB Output is correct
44 Correct 263 ms 21320 KB Output is correct
45 Correct 3 ms 14684 KB Output is correct
46 Correct 3 ms 14684 KB Output is correct
47 Correct 2472 ms 45324 KB Output is correct
48 Correct 2007 ms 44112 KB Output is correct
49 Correct 78 ms 29960 KB Output is correct
50 Correct 86 ms 27060 KB Output is correct
51 Correct 297 ms 29704 KB Output is correct
52 Correct 321 ms 33068 KB Output is correct
53 Correct 41 ms 23592 KB Output is correct
54 Correct 416 ms 37584 KB Output is correct
55 Correct 220 ms 40252 KB Output is correct
56 Correct 124 ms 32080 KB Output is correct
57 Correct 117 ms 34484 KB Output is correct
58 Correct 54 ms 27148 KB Output is correct
59 Correct 195 ms 42580 KB Output is correct
60 Correct 120 ms 39432 KB Output is correct
61 Correct 168 ms 36352 KB Output is correct