Submission #924232

# Submission time Handle Problem Language Result Execution time Memory
924232 2024-02-08T16:43:18 Z dwuy Cheap flights (LMIO18_pigus_skrydziai) C++14
28 / 100
2779 ms 47060 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;
            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 && f<=5000; i++){
        if(cnt[i]*cnt[i]>=n) continue;
        else f++;
        int c, u, v;
        tie(c, u, v) = edges[i];
        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:66:29: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   66 |             ok[f] = cost[f] = 0;
      |                     ~~~~~~~~^~~
pigus_skrydziai.cpp:89:29: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   89 |             ok[f] = cost[f] = 0;
      |                     ~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 14684 KB Output is correct
2 Correct 2 ms 14684 KB Output is correct
3 Correct 2 ms 14684 KB Output is correct
4 Correct 2 ms 14684 KB Output is correct
5 Correct 2 ms 14684 KB Output is correct
6 Correct 23 ms 15504 KB Output is correct
7 Correct 2 ms 14684 KB Output is correct
8 Correct 2 ms 14684 KB Output is correct
9 Correct 2 ms 14680 KB Output is correct
10 Correct 2 ms 14684 KB Output is correct
11 Correct 2 ms 14684 KB Output is correct
12 Correct 2 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 2 ms 14684 KB Output is correct
17 Correct 3 ms 14684 KB Output is correct
18 Correct 3 ms 14780 KB Output is correct
19 Correct 3 ms 14940 KB Output is correct
20 Correct 2 ms 14684 KB Output is correct
21 Correct 2 ms 14684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 14684 KB Output is correct
2 Correct 2 ms 14684 KB Output is correct
3 Correct 2 ms 14684 KB Output is correct
4 Correct 2 ms 14684 KB Output is correct
5 Correct 2 ms 14684 KB Output is correct
6 Correct 23 ms 15504 KB Output is correct
7 Correct 2 ms 14684 KB Output is correct
8 Correct 2 ms 14684 KB Output is correct
9 Correct 2 ms 14680 KB Output is correct
10 Correct 2 ms 14684 KB Output is correct
11 Correct 2 ms 14684 KB Output is correct
12 Correct 2 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 2 ms 14684 KB Output is correct
17 Correct 3 ms 14684 KB Output is correct
18 Correct 3 ms 14780 KB Output is correct
19 Correct 3 ms 14940 KB Output is correct
20 Correct 2 ms 14684 KB Output is correct
21 Correct 2 ms 14684 KB Output is correct
22 Correct 536 ms 47060 KB Output is correct
23 Correct 1593 ms 41352 KB Output is correct
24 Incorrect 11 ms 15704 KB Output isn't correct
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 67 ms 27596 KB Output is correct
2 Correct 178 ms 37816 KB Output is correct
3 Correct 39 ms 24144 KB Output is correct
4 Correct 89 ms 31724 KB Output is correct
5 Correct 148 ms 39252 KB Output is correct
6 Correct 182 ms 21076 KB Output is correct
7 Correct 62 ms 35920 KB Output is correct
8 Correct 73 ms 36176 KB Output is correct
9 Correct 4 ms 18264 KB Output is correct
10 Correct 184 ms 21076 KB Output is correct
11 Correct 2779 ms 41196 KB Output is correct
12 Correct 305 ms 26960 KB Output is correct
13 Correct 2 ms 14684 KB Output is correct
14 Correct 62 ms 21228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 27596 KB Output is correct
2 Correct 178 ms 37816 KB Output is correct
3 Correct 39 ms 24144 KB Output is correct
4 Correct 89 ms 31724 KB Output is correct
5 Correct 148 ms 39252 KB Output is correct
6 Correct 182 ms 21076 KB Output is correct
7 Correct 62 ms 35920 KB Output is correct
8 Correct 73 ms 36176 KB Output is correct
9 Correct 4 ms 18264 KB Output is correct
10 Correct 184 ms 21076 KB Output is correct
11 Correct 2779 ms 41196 KB Output is correct
12 Correct 305 ms 26960 KB Output is correct
13 Correct 2 ms 14684 KB Output is correct
14 Correct 62 ms 21228 KB Output is correct
15 Correct 2 ms 14684 KB Output is correct
16 Correct 2 ms 14684 KB Output is correct
17 Correct 2 ms 14684 KB Output is correct
18 Correct 2 ms 14684 KB Output is correct
19 Correct 2 ms 14684 KB Output is correct
20 Correct 23 ms 15504 KB Output is correct
21 Correct 2 ms 14684 KB Output is correct
22 Correct 2 ms 14684 KB Output is correct
23 Correct 2 ms 14680 KB Output is correct
24 Correct 2 ms 14684 KB Output is correct
25 Correct 2 ms 14684 KB Output is correct
26 Correct 2 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 2 ms 14684 KB Output is correct
31 Correct 3 ms 14684 KB Output is correct
32 Correct 3 ms 14780 KB Output is correct
33 Correct 3 ms 14940 KB Output is correct
34 Correct 2 ms 14684 KB Output is correct
35 Correct 2 ms 14684 KB Output is correct
36 Correct 536 ms 47060 KB Output is correct
37 Correct 1593 ms 41352 KB Output is correct
38 Incorrect 11 ms 15704 KB Output isn't correct
39 Halted 0 ms 0 KB -