Submission #382180

# Submission time Handle Problem Language Result Execution time Memory
382180 2021-03-26T16:16:41 Z mohamedsobhi777 Cheap flights (LMIO18_pigus_skrydziai) C++14
53 / 100
1739 ms 120144 KB
#include <bits/stdc++.h>

using namespace std;

#define vi vector<int>
#define vll vector<ll>
#define vii vector<pair<int, int>>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define loop(_) for (int __ = 0; __ < (_); ++__)
#define pb push_back
#define f first
#define s second
#define sz(_) ((int)_.size())
#define all(_) _.begin(), _.end()
#define lb lower_bound
#define ub upper_bound

using ll = long long;
using ld = long double;

const int N = 3e5 + 7;
const ll mod = 1e9 + 7;

int n, m;
ll a[N];
int viz[N], col = 1;
ll ans;
map<pii, ll> cost;
vi adj[N];
vi adj2[N];
vii e, e2;
ll disto[N];
int fat[N];

void dfs(int x, int p = 0, int pp = 0)
{
       viz[x] = col;
       fat[x] = p;
       for (auto u : adj[x])
       {
              if (u == p)
                     continue;
              if (viz[u] != col)
              {
                     dfs(u, x, p);
              }
              else
              {
                     e2.pb({u, x});
                     if (p && pp && u == pp)
                     {
                            ans = max(ans, cost[{p, pp}] + cost[{x, p}] + cost[{x, pp}]);
                     }
                     adj2[x].pb(u);
              }
       }
}

void dfz(int x, int p)
{
       if (p)
       {
              for (auto u : adj2[x])
              {
                     ans = max(ans, cost[{x, p}] + disto[u] + cost[{x, u}]);
              }
              for (auto u : adj2[p])
              {
                     disto[u] = -2e17;
              }
       }
       for (auto u : adj2[x])
       {
              disto[u] = cost[{x, u}];
       }

       for (auto u : adj[x])
       {
              if (fat[u] == x)
                     dfz(u, x);
       }
}

void prep(vi &act, vii &e)
{
       act.clear();
       for (auto u : e)
       {
              act.pb(u.f);
              act.pb(u.s);
       }
       for (auto u : act)
       {
              adj[u].clear();
              adj2[u].clear();
       }
       for (auto u : e)
       {
              adj[u.f].pb(u.s);
              adj[u.s].pb(u.f);
       }
}

int main()
{
       ios_base::sync_with_stdio(0);
       cin.tie(0);
#ifndef ONLINE_JUDGE
#endif
       cin >> n >> m;
       for (int i = 0; i < N; ++i)
              disto[i] = -2e17;

       vi act;

       for (int i = 0; i < m; ++i)
       {
              int u, v, w;
              cin >> u >> v >> w;
              a[u] += w;
              a[v] += w;
              ans = max({ans, a[u], a[v]});
              e.pb({u, v});
              cost[{u, v}] = cost[{v, u}] = w;
       }

       while (sz(e))
       {
              prep(act, e);
              for (auto u : act)
              {
                     if (viz[u] != col)
                     {
                            dfs(u, 0, 0);
                            dfz(u, 0);
                     }
              }
              e = e2;
              e2.clear();
              ++col;
              break;
       }

       cout << ans;
       return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 10 ms 16748 KB Output is correct
2 Correct 11 ms 16748 KB Output is correct
3 Correct 11 ms 16748 KB Output is correct
4 Correct 10 ms 16748 KB Output is correct
5 Correct 11 ms 16748 KB Output is correct
6 Correct 36 ms 20668 KB Output is correct
7 Correct 11 ms 16748 KB Output is correct
8 Correct 11 ms 16748 KB Output is correct
9 Correct 11 ms 16876 KB Output is correct
10 Correct 11 ms 16748 KB Output is correct
11 Correct 13 ms 16876 KB Output is correct
12 Correct 12 ms 16876 KB Output is correct
13 Correct 12 ms 16876 KB Output is correct
14 Correct 11 ms 16748 KB Output is correct
15 Correct 13 ms 16748 KB Output is correct
16 Correct 11 ms 16748 KB Output is correct
17 Correct 11 ms 16748 KB Output is correct
18 Correct 12 ms 17004 KB Output is correct
19 Correct 16 ms 17260 KB Output is correct
20 Correct 11 ms 16876 KB Output is correct
21 Correct 13 ms 16748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 16748 KB Output is correct
2 Correct 11 ms 16748 KB Output is correct
3 Correct 11 ms 16748 KB Output is correct
4 Correct 10 ms 16748 KB Output is correct
5 Correct 11 ms 16748 KB Output is correct
6 Correct 36 ms 20668 KB Output is correct
7 Correct 11 ms 16748 KB Output is correct
8 Correct 11 ms 16748 KB Output is correct
9 Correct 11 ms 16876 KB Output is correct
10 Correct 11 ms 16748 KB Output is correct
11 Correct 13 ms 16876 KB Output is correct
12 Correct 12 ms 16876 KB Output is correct
13 Correct 12 ms 16876 KB Output is correct
14 Correct 11 ms 16748 KB Output is correct
15 Correct 13 ms 16748 KB Output is correct
16 Correct 11 ms 16748 KB Output is correct
17 Correct 11 ms 16748 KB Output is correct
18 Correct 12 ms 17004 KB Output is correct
19 Correct 16 ms 17260 KB Output is correct
20 Correct 11 ms 16876 KB Output is correct
21 Correct 13 ms 16748 KB Output is correct
22 Correct 1739 ms 114408 KB Output is correct
23 Correct 796 ms 111232 KB Output is correct
24 Correct 45 ms 20964 KB Output is correct
25 Correct 20 ms 18156 KB Output is correct
26 Correct 21 ms 18156 KB Output is correct
27 Correct 15 ms 17260 KB Output is correct
28 Correct 614 ms 55900 KB Output is correct
29 Correct 185 ms 32736 KB Output is correct
30 Correct 345 ms 40664 KB Output is correct
31 Correct 12 ms 17004 KB Output is correct
32 Correct 12 ms 17004 KB Output is correct
33 Correct 1035 ms 111940 KB Output is correct
34 Correct 914 ms 104388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 321 ms 52060 KB Output is correct
2 Correct 824 ms 77904 KB Output is correct
3 Correct 217 ms 37348 KB Output is correct
4 Correct 401 ms 55132 KB Output is correct
5 Correct 1196 ms 88972 KB Output is correct
6 Correct 184 ms 40408 KB Output is correct
7 Correct 279 ms 83040 KB Output is correct
8 Correct 357 ms 81000 KB Output is correct
9 Correct 15 ms 21612 KB Output is correct
10 Correct 188 ms 40408 KB Output is correct
11 Correct 407 ms 77648 KB Output is correct
12 Correct 499 ms 64212 KB Output is correct
13 Correct 12 ms 16748 KB Output is correct
14 Correct 249 ms 36576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 321 ms 52060 KB Output is correct
2 Correct 824 ms 77904 KB Output is correct
3 Correct 217 ms 37348 KB Output is correct
4 Correct 401 ms 55132 KB Output is correct
5 Correct 1196 ms 88972 KB Output is correct
6 Correct 184 ms 40408 KB Output is correct
7 Correct 279 ms 83040 KB Output is correct
8 Correct 357 ms 81000 KB Output is correct
9 Correct 15 ms 21612 KB Output is correct
10 Correct 188 ms 40408 KB Output is correct
11 Correct 407 ms 77648 KB Output is correct
12 Correct 499 ms 64212 KB Output is correct
13 Correct 12 ms 16748 KB Output is correct
14 Correct 249 ms 36576 KB Output is correct
15 Correct 10 ms 16748 KB Output is correct
16 Correct 11 ms 16748 KB Output is correct
17 Correct 11 ms 16748 KB Output is correct
18 Correct 10 ms 16748 KB Output is correct
19 Correct 11 ms 16748 KB Output is correct
20 Correct 36 ms 20668 KB Output is correct
21 Correct 11 ms 16748 KB Output is correct
22 Correct 11 ms 16748 KB Output is correct
23 Correct 11 ms 16876 KB Output is correct
24 Correct 11 ms 16748 KB Output is correct
25 Correct 13 ms 16876 KB Output is correct
26 Correct 12 ms 16876 KB Output is correct
27 Correct 12 ms 16876 KB Output is correct
28 Correct 11 ms 16748 KB Output is correct
29 Correct 13 ms 16748 KB Output is correct
30 Correct 11 ms 16748 KB Output is correct
31 Correct 11 ms 16748 KB Output is correct
32 Correct 12 ms 17004 KB Output is correct
33 Correct 16 ms 17260 KB Output is correct
34 Correct 11 ms 16876 KB Output is correct
35 Correct 13 ms 16748 KB Output is correct
36 Correct 1739 ms 114408 KB Output is correct
37 Correct 796 ms 111232 KB Output is correct
38 Correct 45 ms 20964 KB Output is correct
39 Correct 20 ms 18156 KB Output is correct
40 Correct 21 ms 18156 KB Output is correct
41 Correct 15 ms 17260 KB Output is correct
42 Correct 614 ms 55900 KB Output is correct
43 Correct 185 ms 32736 KB Output is correct
44 Correct 345 ms 40664 KB Output is correct
45 Correct 12 ms 17004 KB Output is correct
46 Correct 12 ms 17004 KB Output is correct
47 Correct 1035 ms 111940 KB Output is correct
48 Correct 914 ms 104388 KB Output is correct
49 Correct 705 ms 57056 KB Output is correct
50 Correct 641 ms 54620 KB Output is correct
51 Correct 579 ms 58936 KB Output is correct
52 Correct 1077 ms 70348 KB Output is correct
53 Correct 187 ms 35812 KB Output is correct
54 Correct 965 ms 77512 KB Output is correct
55 Correct 791 ms 120144 KB Output is correct
56 Correct 455 ms 85852 KB Output is correct
57 Correct 554 ms 72408 KB Output is correct
58 Correct 536 ms 45656 KB Output is correct
59 Correct 1068 ms 78968 KB Output is correct
60 Incorrect 1065 ms 72408 KB Output isn't correct
61 Halted 0 ms 0 KB -