Submission #218274

# Submission time Handle Problem Language Result Execution time Memory
218274 2020-04-01T19:22:32 Z summitwei Dreaming (IOI13_dreaming) C++17
18 / 100
74 ms 15996 KB
#include <bits/stdc++.h>
#include <dreaming.h>
using namespace std;
typedef vector<int> vi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
#define INF 0x3f3f3f3f
#define MOD 1000000007LL
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair

#define FOR(i, a, b) for (ll i=(a); i<=(signed)(b); i++)
#define F0R(i, a) for (ll i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (ll i=(a); i >= b; i--)

#define MN 100005
vpii e[MN];
int vis[MN];
pii far(int cn, int p){ //{dist, node}
    vis[cn] = true;
    pii ans = {0, cn};
    for(auto nn : e[cn]) if(nn.f != p){
        pii res = far(nn.f, cn);
        ans = max(ans, {res.f+nn.s, res.s});
    }
    return ans;
}
int d[2][MN];
int cmn;
void gda(int t, int cn, int p){
    if(t == 1){
        cmn = min(cmn, max(d[0][cn], d[1][cn]));
    }
    for(auto nn : e[cn]) if(nn.f != p){
        d[t][nn.f] = d[t][cn]+nn.s;
        gda(t, nn.f, cn);
    }
}
int diam(int x){
    pii res1 = far(x, -1);
    pii res2 = far(res1.s, -1);
    //return {res2.f, {res1.s, res2.s}};
    cmn = INF;
    gda(0, res1.s, 0);
    gda(1, res2.s, 0);
    return cmn;
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]){
    int n = N; int m = M; int l = L;
    F0R(i, m){
        e[A[i]].pb({B[i], T[i]});
        e[B[i]].pb({A[i], T[i]});
    }
    vi hmm;
    F0R(i, n){
        if(!vis[i]){
            hmm.pb(diam(i));
        }
    }
    sort(hmm.begin(), hmm.end(), greater<int>() );
    if(hmm.size() == 1){
        return hmm[0];
    } else if(hmm.size() == 2){
        return hmm[0]+hmm[1]+l;
    } else{
        return max(hmm[0]+hmm[1]+l, hmm[1]+hmm[2]+l+l);
    }
}

/*int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int N, M, L;
    cin >> N >> M >> L;
    int A[M], B[M], T[M];
    F0R(i, M) cin >> A[i] >> B[i] >> T[i];

    cout << travelTime(N, M, L, A, B, T) << "\n";
    
    return 0;
}*/
# Verdict Execution time Memory Grader output
1 Incorrect 74 ms 15996 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 74 ms 15996 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 74 ms 15996 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 33 ms 6912 KB Output is correct
2 Correct 32 ms 6912 KB Output is correct
3 Correct 31 ms 6912 KB Output is correct
4 Correct 35 ms 6904 KB Output is correct
5 Correct 29 ms 6912 KB Output is correct
6 Correct 32 ms 7416 KB Output is correct
7 Correct 31 ms 7040 KB Output is correct
8 Correct 29 ms 6784 KB Output is correct
9 Correct 32 ms 6772 KB Output is correct
10 Correct 31 ms 7036 KB Output is correct
11 Correct 6 ms 2688 KB Output is correct
12 Correct 12 ms 4348 KB Output is correct
13 Correct 12 ms 4348 KB Output is correct
14 Correct 11 ms 4348 KB Output is correct
15 Correct 12 ms 4348 KB Output is correct
16 Correct 11 ms 4220 KB Output is correct
17 Correct 11 ms 3836 KB Output is correct
18 Correct 12 ms 4348 KB Output is correct
19 Correct 11 ms 4348 KB Output is correct
20 Correct 6 ms 2688 KB Output is correct
21 Correct 6 ms 2688 KB Output is correct
22 Correct 6 ms 2816 KB Output is correct
23 Correct 11 ms 4348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 74 ms 15996 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 74 ms 15996 KB Output isn't correct
2 Halted 0 ms 0 KB -