Submission #147458

# Submission time Handle Problem Language Result Execution time Memory
147458 2019-08-29T15:24:01 Z karma Dreaming (IOI13_dreaming) C++14
18 / 100
78 ms 13328 KB
#include <bits/stdc++.h>
#include "dreaming.h"
#define pb      emplace_back
#define fi      first
#define se      second

using namespace std;

typedef pair<int, int> pii;
const int N = int(1e5) + 7;

int dis[N], vis[N], trade[N], cc, d, _mx, mx;
vector<pii> a[N];
vector<int> r;

void DFS(int u, int lim) {
     vis[u] = lim; d = max(d, dis[u]);
     if(mx == -1 || dis[u] > dis[mx]) mx = u;
     for(pii ed: a[u]) {
        if(vis[ed.fi] < lim) {
            dis[ed.fi] = dis[u] + ed.se;
            trade[ed.fi] = u;
            DFS(ed.fi, lim);
        }
     }
}

int Find(int s, int t)
{
    int dist = dis[t], res = dis[t];
    while(t != s) {
        res = min(res, max(dis[t], dist - dis[t]));
        t = trade[t];
    }
    return res;
}

int travelTime(int n, int m, int l, int s[], int t[], int w[])
{
    for(int i = 0; i < m; ++i) a[s[i]].pb(t[i], w[i]), a[t[i]].pb(s[i], w[i]);
    cc = d = 0;
    fill(vis, vis + n, 0);
    for(int i = 0; i < n; ++i) {
        if(!vis[i]) {
            dis[i] = 0, mx = i, DFS(i, 1);
            dis[_mx = mx] = 0, DFS(_mx, 2);
            r.pb(Find(_mx, mx));
            ++cc;
        }
    }
    sort(r.begin(), r.end(), greater<int>());
    if(cc == 1) return d;
    else if(cc == 2) return r[0] + r[1] + l;
    return max(r[1] + r[2] + 2 * l, r[0] + r[1] + l);
}
//
//int _n, _m, _l, _a[N], _b[N], _t[N];
//
//int main()
//{
//    ios_base::sync_with_stdio(0);
//    cin.tie(0), cout.tie(0);
//    if(fopen("test.inp", "r")) {
//        freopen("test.inp", "r", stdin);
//        freopen("test.out", "w", stdout);
//    }
//    cin >> _n >> _m >> _l;
//    for(int i = 0; i < _m; ++i) cin >> _a[i] >> _b[i] >> _t[i];
//    cout << travelTime(_n, _m, _l, _a, _b, _t);
//}
# Verdict Execution time Memory Grader output
1 Incorrect 78 ms 13328 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 78 ms 13328 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 78 ms 13328 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 33 ms 7032 KB Output is correct
2 Correct 35 ms 7004 KB Output is correct
3 Correct 36 ms 6872 KB Output is correct
4 Correct 36 ms 7032 KB Output is correct
5 Correct 31 ms 6904 KB Output is correct
6 Correct 33 ms 7416 KB Output is correct
7 Correct 37 ms 7160 KB Output is correct
8 Correct 35 ms 6904 KB Output is correct
9 Correct 31 ms 6776 KB Output is correct
10 Correct 36 ms 7032 KB Output is correct
11 Correct 5 ms 2680 KB Output is correct
12 Correct 9 ms 4464 KB Output is correct
13 Correct 9 ms 4596 KB Output is correct
14 Correct 9 ms 4468 KB Output is correct
15 Correct 9 ms 4596 KB Output is correct
16 Correct 9 ms 4468 KB Output is correct
17 Correct 9 ms 4212 KB Output is correct
18 Correct 9 ms 4596 KB Output is correct
19 Correct 9 ms 4468 KB Output is correct
20 Correct 4 ms 2680 KB Output is correct
21 Correct 4 ms 2680 KB Output is correct
22 Correct 4 ms 2808 KB Output is correct
23 Correct 9 ms 4468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 78 ms 13328 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 78 ms 13328 KB Output isn't correct
2 Halted 0 ms 0 KB -