답안 #218286

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
218286 2020-04-01T19:49:14 Z summitwei 꿈 (IOI13_dreaming) C++17
18 / 100
1000 ms 12392 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];
pii far(int cn, int p){ //{dist, node}
    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 dsu[MN];
int sz[MN];
int ans[MN];
int fd(int x){
    if(dsu[x] == x) return x;
    dsu[x] = fd(dsu[x]); return dsu[x];
}
void jn(int x, int y){
    x = fd(x); y = fd(y);
    if(x == y) return;
    if(sz[x] < sz[y]) swap(x, y);
    dsu[y] = x;
    sz[x] += sz[y];
    ans[x] = min(ans[x], ans[y]);
}
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]});
    }
    F0R(i, n){
        dsu[i] = i; sz[i] = i;
        pii res = far(i, -1);
        //cout << "far from " << i << " " << res.f << "\n";
        ans[i] = res.f;
    }
    F0R(i, m){
        jn(A[i], B[i]);
    }

    vi hmm;
    F0R(i, n){
        if(dsu[i] == i){
            //cout << ans[i] << " ";
            hmm.pb(ans[i]);
        }
    }
    //cout << "\n";
    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;
}*/
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1087 ms 12392 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1087 ms 12392 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1087 ms 12392 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 6520 KB Output is correct
2 Correct 27 ms 6528 KB Output is correct
3 Correct 29 ms 6528 KB Output is correct
4 Correct 49 ms 6520 KB Output is correct
5 Correct 28 ms 6528 KB Output is correct
6 Correct 30 ms 7032 KB Output is correct
7 Correct 29 ms 6656 KB Output is correct
8 Correct 27 ms 6520 KB Output is correct
9 Correct 27 ms 6400 KB Output is correct
10 Correct 29 ms 6652 KB Output is correct
11 Correct 6 ms 2688 KB Output is correct
12 Correct 9 ms 4476 KB Output is correct
13 Correct 9 ms 4476 KB Output is correct
14 Correct 9 ms 4476 KB Output is correct
15 Correct 9 ms 4476 KB Output is correct
16 Correct 9 ms 4604 KB Output is correct
17 Correct 9 ms 4476 KB Output is correct
18 Correct 10 ms 4604 KB Output is correct
19 Correct 9 ms 4476 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 9 ms 4604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1087 ms 12392 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1087 ms 12392 KB Time limit exceeded
2 Halted 0 ms 0 KB -