답안 #394404

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
394404 2021-04-26T13:53:50 Z teehandsome 꿈 (IOI13_dreaming) C++11
24 / 100
1000 ms 13396 KB
#include "dreaming.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define INF 1e9+7
#define all(x) x.begin(),x.end()
using namespace std;
using namespace __gnu_pbds;
using ll=long long;
using pii=pair<int,int>;
using ppi=pair<int,pii>;
using oset=tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>;

template<typename T>
void _print(vector<T> x) {cerr<<"{"; for(auto e:x) cerr<<e<<","; cerr<<"}";}
void _print(pii x) {cerr<<"{"<<x.first<<","<<x.second<<"}";}
template<typename T>
void _print(T x) {cerr<<x;}

void dbg() {cerr<<endl;}
template<typename Head,typename... Tail>
void dbg(Head H,Tail... T) {
    _print(H);
    if(sizeof...(T)) cerr<<",";
    else cerr<<"\"]";
    dbg(T...);
}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:[\"",dbg(__VA_ARGS__)

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int mxn=1e5+10;
int n,m,l;
vector<pii> adj[mxn];
set<int> par_list;
vector<int> group[mxn];
int p[mxn];
vector<int> essen;
int ans;

int findp(int x) {
    while(p[x]!=x) p[x]=p[p[x]],x=p[x];
    return x;
}
void unionset(int u,int v) {
    int U=findp(u),V=findp(v);
    p[U]=V;
}
void solve(int root,int ii) {
    vector<int> dist(n,-1);
    queue<pii> q;
    q.push({root,0});
    int mx=0,idx=0;
    while(!q.empty()) {
        int u=q.front().first;
        int d=q.front().second;
        q.pop();
        dist[u]=d;
        if(dist[u]>mx) {
            mx=dist[u]; idx=u;
        }
        for(auto vw:adj[u]) {
            int v=vw.first,w=vw.second;
            if(dist[v]==-1) {
                dist[v]=d+w;
                q.push({v,d+w});
            }
        }
    }
    int mx2=0,idx2=0;
    queue<pii> q2;
    fill(all(dist),-1);
    q2.push({idx,0});
    while(!q2.empty()) {
        int u=q2.front().first;
        int d=q2.front().second;
        q2.pop();
        dist[u]=d;
        if(dist[u]>mx2) {
            mx2=dist[u],idx2=u;
        }
        for(auto vw:adj[u]) {
            int v=vw.first,w=vw.second;
            if(dist[v]==-1) {
                dist[v]=w+d;
                q2.push({v,w+d});
            }
        }
    }
    vector<int> dist2(n,-1);
    queue<pii> q3;
    q3.push({idx2,0});
    while(!q3.empty()) {
        int u=q3.front().first;
        int d=q3.front().second;
        q3.pop();
        dist2[u]=d;

        for(auto vw:adj[u]) {
            int v=vw.first,w=vw.second;
            if(dist2[v]==-1) {
                dist2[v]=w+d;
                q3.push({v,w+d});
            }
        }
    }
    int mn=INF;
    for(auto e:group[root]) {
        mn=min(mn,max(dist[e],dist2[e]));
    }
    ans=max(ans,mx2);
    essen.push_back(mn);
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    n=N,m=M,l=L;
    if(n==1) return 0;
    if(n==2) return l;
    for(int i=0;i<n;i++) p[i]=i;
    for(int i=0;i<m;i++) {
        int u=A[i],v=B[i],w=T[i];
        adj[u].push_back({v,w});
        adj[v].push_back({u,w});
        unionset(u,v);
    }
    for(int i=0;i<n;i++) {
        p[i]=findp(p[i]);
//        group_idx[i]=p[i];
        group[p[i]].push_back(i);
        par_list.insert(p[i]);
    }
    int sz=par_list.size();
    int cnt=0;
    for(auto e:par_list) {
        solve(e,cnt++);
    }
    sort(all(essen),greater<int>());
    ans=max(ans,essen[0]+essen[1]+l);
    return ans;
}


Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:133:9: warning: unused variable 'sz' [-Wunused-variable]
  133 |     int sz=par_list.size();
      |         ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 10436 KB Output is correct
2 Correct 66 ms 10488 KB Output is correct
3 Correct 48 ms 8640 KB Output is correct
4 Correct 10 ms 5800 KB Output is correct
5 Correct 9 ms 5580 KB Output is correct
6 Correct 16 ms 6192 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 30 ms 7492 KB Output is correct
9 Correct 50 ms 8068 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 53 ms 9240 KB Output is correct
12 Correct 63 ms 9736 KB Output is correct
13 Correct 3 ms 5068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 4 ms 4940 KB Output is correct
7 Correct 4 ms 4940 KB Output is correct
8 Correct 4 ms 5000 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 4 ms 5000 KB Output is correct
11 Correct 3 ms 5024 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 3 ms 5004 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 4 ms 4940 KB Output is correct
17 Correct 4 ms 4940 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4940 KB Output is correct
23 Correct 3 ms 5000 KB Output is correct
24 Correct 3 ms 4940 KB Output is correct
25 Correct 3 ms 5004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 10436 KB Output is correct
2 Correct 66 ms 10488 KB Output is correct
3 Correct 48 ms 8640 KB Output is correct
4 Correct 10 ms 5800 KB Output is correct
5 Correct 9 ms 5580 KB Output is correct
6 Correct 16 ms 6192 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 30 ms 7492 KB Output is correct
9 Correct 50 ms 8068 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 53 ms 9240 KB Output is correct
12 Correct 63 ms 9736 KB Output is correct
13 Correct 3 ms 5068 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 4 ms 4940 KB Output is correct
20 Correct 4 ms 4940 KB Output is correct
21 Correct 4 ms 5000 KB Output is correct
22 Correct 3 ms 4940 KB Output is correct
23 Correct 4 ms 5000 KB Output is correct
24 Correct 3 ms 5024 KB Output is correct
25 Correct 3 ms 4940 KB Output is correct
26 Correct 3 ms 5004 KB Output is correct
27 Correct 3 ms 4940 KB Output is correct
28 Correct 3 ms 4940 KB Output is correct
29 Correct 4 ms 4940 KB Output is correct
30 Correct 4 ms 4940 KB Output is correct
31 Correct 3 ms 4940 KB Output is correct
32 Correct 3 ms 4940 KB Output is correct
33 Correct 3 ms 4940 KB Output is correct
34 Correct 3 ms 4948 KB Output is correct
35 Correct 3 ms 4940 KB Output is correct
36 Correct 3 ms 5000 KB Output is correct
37 Correct 3 ms 4940 KB Output is correct
38 Correct 3 ms 5004 KB Output is correct
39 Correct 61 ms 11640 KB Output is correct
40 Correct 65 ms 11608 KB Output is correct
41 Correct 39 ms 9576 KB Output is correct
42 Correct 11 ms 5964 KB Output is correct
43 Correct 4 ms 4940 KB Output is correct
44 Correct 4 ms 4940 KB Output is correct
45 Correct 3 ms 5000 KB Output is correct
46 Correct 3 ms 4940 KB Output is correct
47 Correct 4 ms 4940 KB Output is correct
48 Correct 3 ms 5000 KB Output is correct
49 Correct 3 ms 4940 KB Output is correct
50 Correct 3 ms 4940 KB Output is correct
51 Correct 3 ms 5000 KB Output is correct
52 Correct 3 ms 4940 KB Output is correct
53 Correct 3 ms 4976 KB Output is correct
54 Correct 3 ms 4940 KB Output is correct
55 Correct 3 ms 4940 KB Output is correct
56 Correct 4 ms 4940 KB Output is correct
57 Correct 102 ms 13204 KB Output is correct
58 Correct 94 ms 13132 KB Output is correct
59 Correct 81 ms 12928 KB Output is correct
60 Correct 86 ms 13024 KB Output is correct
61 Correct 94 ms 13180 KB Output is correct
62 Correct 86 ms 13188 KB Output is correct
63 Correct 85 ms 12788 KB Output is correct
64 Incorrect 89 ms 12816 KB Output isn't correct
65 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1097 ms 13396 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 4 ms 4940 KB Output is correct
7 Correct 4 ms 4940 KB Output is correct
8 Correct 4 ms 5000 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 4 ms 5000 KB Output is correct
11 Correct 3 ms 5024 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 3 ms 5004 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 4 ms 4940 KB Output is correct
17 Correct 4 ms 4940 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4940 KB Output is correct
23 Correct 3 ms 5000 KB Output is correct
24 Correct 3 ms 4940 KB Output is correct
25 Correct 3 ms 5004 KB Output is correct
26 Correct 4 ms 5068 KB Output is correct
27 Correct 6 ms 5068 KB Output is correct
28 Correct 10 ms 5280 KB Output is correct
29 Correct 4 ms 5020 KB Output is correct
30 Correct 7 ms 5148 KB Output is correct
31 Correct 8 ms 5196 KB Output is correct
32 Incorrect 5 ms 5068 KB Output isn't correct
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 10436 KB Output is correct
2 Correct 66 ms 10488 KB Output is correct
3 Correct 48 ms 8640 KB Output is correct
4 Correct 10 ms 5800 KB Output is correct
5 Correct 9 ms 5580 KB Output is correct
6 Correct 16 ms 6192 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 30 ms 7492 KB Output is correct
9 Correct 50 ms 8068 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 53 ms 9240 KB Output is correct
12 Correct 63 ms 9736 KB Output is correct
13 Correct 3 ms 5068 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 4 ms 4940 KB Output is correct
20 Correct 4 ms 4940 KB Output is correct
21 Correct 4 ms 5000 KB Output is correct
22 Correct 3 ms 4940 KB Output is correct
23 Correct 4 ms 5000 KB Output is correct
24 Correct 3 ms 5024 KB Output is correct
25 Correct 3 ms 4940 KB Output is correct
26 Correct 3 ms 5004 KB Output is correct
27 Correct 3 ms 4940 KB Output is correct
28 Correct 3 ms 4940 KB Output is correct
29 Correct 4 ms 4940 KB Output is correct
30 Correct 4 ms 4940 KB Output is correct
31 Correct 3 ms 4940 KB Output is correct
32 Correct 3 ms 4940 KB Output is correct
33 Correct 3 ms 4940 KB Output is correct
34 Correct 3 ms 4948 KB Output is correct
35 Correct 3 ms 4940 KB Output is correct
36 Correct 3 ms 5000 KB Output is correct
37 Correct 3 ms 4940 KB Output is correct
38 Correct 3 ms 5004 KB Output is correct
39 Correct 61 ms 11640 KB Output is correct
40 Correct 65 ms 11608 KB Output is correct
41 Correct 39 ms 9576 KB Output is correct
42 Correct 11 ms 5964 KB Output is correct
43 Correct 4 ms 4940 KB Output is correct
44 Correct 4 ms 4940 KB Output is correct
45 Correct 3 ms 5000 KB Output is correct
46 Correct 3 ms 4940 KB Output is correct
47 Correct 4 ms 4940 KB Output is correct
48 Correct 3 ms 5000 KB Output is correct
49 Correct 3 ms 4940 KB Output is correct
50 Correct 3 ms 4940 KB Output is correct
51 Correct 3 ms 5000 KB Output is correct
52 Correct 3 ms 4940 KB Output is correct
53 Correct 3 ms 4976 KB Output is correct
54 Correct 3 ms 4940 KB Output is correct
55 Correct 3 ms 4940 KB Output is correct
56 Correct 4 ms 4940 KB Output is correct
57 Correct 102 ms 13204 KB Output is correct
58 Correct 94 ms 13132 KB Output is correct
59 Correct 81 ms 12928 KB Output is correct
60 Correct 86 ms 13024 KB Output is correct
61 Correct 94 ms 13180 KB Output is correct
62 Correct 86 ms 13188 KB Output is correct
63 Correct 85 ms 12788 KB Output is correct
64 Incorrect 89 ms 12816 KB Output isn't correct
65 Halted 0 ms 0 KB -