답안 #947382

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
947382 2024-03-16T04:56:34 Z adkjt 꿈 (IOI13_dreaming) C++14
47 / 100
45 ms 18064 KB
#include<bits/stdc++.h>
#include "dreaming.h"
using namespace std;
#define f first
#define s second
#define pii pair<int,int>
#define ll long long
vector<pii> g[111111];
int dis[111111],vis[111111],cendis[111111];
vector<int> diameter[111111];
int mxi=0,mxd=0,cntg=0,st,en,mxg1=-1,mxg2=-1,mxg3=-1,ans=0;
void dfs(int now,int p)
{
    vis[now]=1;
    if(dis[now]>mxd)
        mxd=dis[now],mxi=now;
    //vis[now]=1;
    for(auto x:g[now])
    {
        if(x.f==p) continue;
        dis[x.f]=dis[now]+x.s;
        dfs(x.f,now);
    }
}
bool diamake(int now,int prev,int en)
{
    diameter[cntg].push_back(now);
    if(now==en) return 1;
    for(auto x:g[now])
    {
        if(x.f==prev) continue;
        if(diamake(x.f,now,en)) return 1;
    }
    diameter[cntg].pop_back();
    return 0;
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    for(int i=0;i<M;i++)
    {
        g[A[i]].push_back({B[i],T[i]});
        g[B[i]].push_back({A[i],T[i]});
    }
    //for(int i=1;i<=N;i++) dis[i]=INT_MAX;
    for(int i=0;i<N;i++)
    {
        if(vis[i]) continue;
        cntg++;
        //vis[i]=1;
        mxi=-1,mxd=-1;
        dis[i]=0;
        dfs(i,-1);
        st=mxi;
        mxi=-1,mxd=-1;
        dis[st]=0;
        dfs(st,-1);
        en=mxi;
        ans=max(ans,mxd);
        diamake(st,-1,en);

        //disdia[cntg]=mxd;
        cendis[cntg]=INT_MAX;
        //cout<<mxd<<'\n';
        for(auto x:diameter[cntg]) cendis[cntg]=min(cendis[cntg],max(dis[x],mxd-dis[x]));
        //cout<<cendis[cntg]<<'\n';
        if(cendis[cntg]>=INT_MAX) {
                cendis[cntg]=0;
                continue;
        }
        if(mxg1==-1||cendis[cntg]>mxg1) mxg3=mxg2,mxg2=mxg1,mxg1=cendis[cntg];
        else if(mxg2==-1||cendis[cntg]>mxg2) mxg3=mxg2,mxg2=cendis[cntg];
        else if(mxg3==-1||cendis[cntg]>mxg3) mxg3=cendis[cntg];
        //cout<<st<<' '<<en<<'\n';
    }
    //cout<<mxg1<<' '<<mxg2<<' '<<mxg3<<'\n';
    if(mxg3==-1) return max(ans,mxg1+mxg2+L);
    return max({ans,mxg1+mxg2+L,mxg2+mxg3+2*L});

}
/*int main()
{
    int n,m,l,a[111111],b[111111],t[111111];
    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);
}*/

# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 17108 KB Output is correct
2 Correct 32 ms 17076 KB Output is correct
3 Correct 21 ms 14028 KB Output is correct
4 Correct 6 ms 9308 KB Output is correct
5 Correct 5 ms 8696 KB Output is correct
6 Correct 9 ms 10328 KB Output is correct
7 Correct 2 ms 7772 KB Output is correct
8 Correct 16 ms 11008 KB Output is correct
9 Correct 23 ms 12376 KB Output is correct
10 Correct 3 ms 7772 KB Output is correct
11 Correct 30 ms 13656 KB Output is correct
12 Correct 39 ms 15576 KB Output is correct
13 Correct 2 ms 8024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7772 KB Output is correct
2 Correct 2 ms 7772 KB Output is correct
3 Correct 2 ms 7768 KB Output is correct
4 Correct 2 ms 7772 KB Output is correct
5 Correct 2 ms 7772 KB Output is correct
6 Correct 2 ms 7772 KB Output is correct
7 Correct 2 ms 7772 KB Output is correct
8 Correct 2 ms 7772 KB Output is correct
9 Correct 2 ms 7772 KB Output is correct
10 Correct 2 ms 7772 KB Output is correct
11 Correct 2 ms 7768 KB Output is correct
12 Correct 2 ms 8024 KB Output is correct
13 Correct 2 ms 7960 KB Output is correct
14 Correct 2 ms 7772 KB Output is correct
15 Correct 2 ms 7772 KB Output is correct
16 Correct 2 ms 7772 KB Output is correct
17 Correct 2 ms 7772 KB Output is correct
18 Correct 2 ms 7768 KB Output is correct
19 Correct 2 ms 7768 KB Output is correct
20 Correct 2 ms 7772 KB Output is correct
21 Correct 2 ms 7768 KB Output is correct
22 Correct 2 ms 7768 KB Output is correct
23 Correct 2 ms 7972 KB Output is correct
24 Correct 2 ms 7772 KB Output is correct
25 Correct 2 ms 7772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 17108 KB Output is correct
2 Correct 32 ms 17076 KB Output is correct
3 Correct 21 ms 14028 KB Output is correct
4 Correct 6 ms 9308 KB Output is correct
5 Correct 5 ms 8696 KB Output is correct
6 Correct 9 ms 10328 KB Output is correct
7 Correct 2 ms 7772 KB Output is correct
8 Correct 16 ms 11008 KB Output is correct
9 Correct 23 ms 12376 KB Output is correct
10 Correct 3 ms 7772 KB Output is correct
11 Correct 30 ms 13656 KB Output is correct
12 Correct 39 ms 15576 KB Output is correct
13 Correct 2 ms 8024 KB Output is correct
14 Correct 2 ms 7772 KB Output is correct
15 Correct 2 ms 7772 KB Output is correct
16 Correct 2 ms 7768 KB Output is correct
17 Correct 2 ms 7772 KB Output is correct
18 Correct 2 ms 7772 KB Output is correct
19 Correct 2 ms 7772 KB Output is correct
20 Correct 2 ms 7772 KB Output is correct
21 Correct 2 ms 7772 KB Output is correct
22 Correct 2 ms 7772 KB Output is correct
23 Correct 2 ms 7772 KB Output is correct
24 Correct 2 ms 7768 KB Output is correct
25 Correct 2 ms 8024 KB Output is correct
26 Correct 2 ms 7960 KB Output is correct
27 Correct 2 ms 7772 KB Output is correct
28 Correct 2 ms 7772 KB Output is correct
29 Correct 2 ms 7772 KB Output is correct
30 Correct 2 ms 7772 KB Output is correct
31 Correct 2 ms 7768 KB Output is correct
32 Correct 2 ms 7768 KB Output is correct
33 Correct 2 ms 7772 KB Output is correct
34 Correct 2 ms 7768 KB Output is correct
35 Correct 2 ms 7768 KB Output is correct
36 Correct 2 ms 7972 KB Output is correct
37 Correct 2 ms 7772 KB Output is correct
38 Correct 2 ms 7772 KB Output is correct
39 Correct 33 ms 17108 KB Output is correct
40 Correct 36 ms 17104 KB Output is correct
41 Correct 23 ms 14292 KB Output is correct
42 Correct 7 ms 9304 KB Output is correct
43 Correct 2 ms 7772 KB Output is correct
44 Correct 2 ms 7772 KB Output is correct
45 Correct 2 ms 7772 KB Output is correct
46 Correct 2 ms 7768 KB Output is correct
47 Correct 2 ms 7772 KB Output is correct
48 Correct 2 ms 7772 KB Output is correct
49 Correct 2 ms 7772 KB Output is correct
50 Correct 2 ms 7772 KB Output is correct
51 Correct 2 ms 7772 KB Output is correct
52 Correct 2 ms 7772 KB Output is correct
53 Correct 2 ms 7772 KB Output is correct
54 Correct 2 ms 7956 KB Output is correct
55 Correct 2 ms 7772 KB Output is correct
56 Correct 2 ms 7772 KB Output is correct
57 Correct 35 ms 12128 KB Output is correct
58 Correct 37 ms 11856 KB Output is correct
59 Correct 35 ms 11860 KB Output is correct
60 Correct 36 ms 11868 KB Output is correct
61 Correct 36 ms 11880 KB Output is correct
62 Correct 36 ms 11860 KB Output is correct
63 Correct 37 ms 11864 KB Output is correct
64 Correct 33 ms 11612 KB Output is correct
65 Correct 33 ms 11604 KB Output is correct
66 Correct 33 ms 11716 KB Output is correct
67 Correct 36 ms 11860 KB Output is correct
68 Correct 36 ms 11960 KB Output is correct
69 Correct 38 ms 11868 KB Output is correct
70 Correct 38 ms 11900 KB Output is correct
71 Correct 2 ms 7768 KB Output is correct
72 Correct 3 ms 8024 KB Output is correct
73 Correct 3 ms 8028 KB Output is correct
74 Correct 3 ms 8028 KB Output is correct
75 Correct 3 ms 8028 KB Output is correct
76 Correct 3 ms 8028 KB Output is correct
77 Correct 3 ms 8024 KB Output is correct
78 Correct 3 ms 8028 KB Output is correct
79 Correct 3 ms 8024 KB Output is correct
80 Correct 38 ms 11864 KB Output is correct
81 Correct 37 ms 11868 KB Output is correct
82 Correct 36 ms 11848 KB Output is correct
83 Correct 38 ms 12368 KB Output is correct
84 Correct 2 ms 8028 KB Output is correct
85 Correct 2 ms 8024 KB Output is correct
86 Correct 2 ms 8028 KB Output is correct
87 Correct 3 ms 8028 KB Output is correct
88 Correct 3 ms 8028 KB Output is correct
89 Correct 2 ms 8028 KB Output is correct
90 Correct 2 ms 8028 KB Output is correct
91 Correct 3 ms 8028 KB Output is correct
92 Correct 3 ms 8028 KB Output is correct
93 Correct 5 ms 7860 KB Output is correct
94 Correct 2 ms 7772 KB Output is correct
95 Correct 2 ms 7772 KB Output is correct
96 Correct 2 ms 7772 KB Output is correct
97 Correct 2 ms 7772 KB Output is correct
98 Correct 2 ms 7768 KB Output is correct
99 Correct 2 ms 7772 KB Output is correct
100 Correct 2 ms 7772 KB Output is correct
101 Correct 2 ms 7772 KB Output is correct
102 Correct 2 ms 7772 KB Output is correct
103 Correct 2 ms 7772 KB Output is correct
104 Correct 5 ms 8540 KB Output is correct
105 Correct 9 ms 10076 KB Output is correct
106 Correct 2 ms 7772 KB Output is correct
107 Correct 16 ms 11052 KB Output is correct
108 Correct 21 ms 12504 KB Output is correct
109 Correct 2 ms 7772 KB Output is correct
110 Correct 32 ms 13636 KB Output is correct
111 Correct 33 ms 15560 KB Output is correct
112 Correct 2 ms 8028 KB Output is correct
113 Correct 45 ms 18064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 11864 KB Output is correct
2 Correct 15 ms 11868 KB Output is correct
3 Correct 16 ms 11884 KB Output is correct
4 Correct 16 ms 11868 KB Output is correct
5 Correct 16 ms 11760 KB Output is correct
6 Correct 16 ms 12124 KB Output is correct
7 Correct 17 ms 12124 KB Output is correct
8 Correct 15 ms 11864 KB Output is correct
9 Correct 15 ms 11868 KB Output is correct
10 Correct 16 ms 12124 KB Output is correct
11 Correct 2 ms 7772 KB Output is correct
12 Correct 7 ms 11100 KB Output is correct
13 Correct 7 ms 11096 KB Output is correct
14 Correct 7 ms 10844 KB Output is correct
15 Correct 7 ms 11096 KB Output is correct
16 Correct 7 ms 10852 KB Output is correct
17 Correct 7 ms 10844 KB Output is correct
18 Correct 7 ms 11032 KB Output is correct
19 Correct 8 ms 10844 KB Output is correct
20 Incorrect 1 ms 7772 KB Output isn't correct
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7772 KB Output is correct
2 Correct 2 ms 7772 KB Output is correct
3 Correct 2 ms 7768 KB Output is correct
4 Correct 2 ms 7772 KB Output is correct
5 Correct 2 ms 7772 KB Output is correct
6 Correct 2 ms 7772 KB Output is correct
7 Correct 2 ms 7772 KB Output is correct
8 Correct 2 ms 7772 KB Output is correct
9 Correct 2 ms 7772 KB Output is correct
10 Correct 2 ms 7772 KB Output is correct
11 Correct 2 ms 7768 KB Output is correct
12 Correct 2 ms 8024 KB Output is correct
13 Correct 2 ms 7960 KB Output is correct
14 Correct 2 ms 7772 KB Output is correct
15 Correct 2 ms 7772 KB Output is correct
16 Correct 2 ms 7772 KB Output is correct
17 Correct 2 ms 7772 KB Output is correct
18 Correct 2 ms 7768 KB Output is correct
19 Correct 2 ms 7768 KB Output is correct
20 Correct 2 ms 7772 KB Output is correct
21 Correct 2 ms 7768 KB Output is correct
22 Correct 2 ms 7768 KB Output is correct
23 Correct 2 ms 7972 KB Output is correct
24 Correct 2 ms 7772 KB Output is correct
25 Correct 2 ms 7772 KB Output is correct
26 Correct 2 ms 7768 KB Output is correct
27 Correct 2 ms 8028 KB Output is correct
28 Correct 3 ms 8028 KB Output is correct
29 Correct 2 ms 7948 KB Output is correct
30 Correct 2 ms 8028 KB Output is correct
31 Correct 3 ms 8028 KB Output is correct
32 Correct 2 ms 7772 KB Output is correct
33 Correct 2 ms 8032 KB Output is correct
34 Correct 3 ms 8028 KB Output is correct
35 Correct 2 ms 7772 KB Output is correct
36 Correct 2 ms 7772 KB Output is correct
37 Correct 2 ms 7772 KB Output is correct
38 Correct 2 ms 7772 KB Output is correct
39 Correct 2 ms 7772 KB Output is correct
40 Correct 2 ms 7776 KB Output is correct
41 Correct 2 ms 7772 KB Output is correct
42 Correct 2 ms 7772 KB Output is correct
43 Correct 2 ms 7768 KB Output is correct
44 Correct 2 ms 7772 KB Output is correct
45 Correct 2 ms 7772 KB Output is correct
46 Correct 2 ms 8024 KB Output is correct
47 Correct 2 ms 7772 KB Output is correct
48 Correct 2 ms 7768 KB Output is correct
49 Correct 2 ms 7772 KB Output is correct
50 Correct 2 ms 7772 KB Output is correct
51 Correct 2 ms 7772 KB Output is correct
52 Incorrect 2 ms 7884 KB Output isn't correct
53 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 17108 KB Output is correct
2 Correct 32 ms 17076 KB Output is correct
3 Correct 21 ms 14028 KB Output is correct
4 Correct 6 ms 9308 KB Output is correct
5 Correct 5 ms 8696 KB Output is correct
6 Correct 9 ms 10328 KB Output is correct
7 Correct 2 ms 7772 KB Output is correct
8 Correct 16 ms 11008 KB Output is correct
9 Correct 23 ms 12376 KB Output is correct
10 Correct 3 ms 7772 KB Output is correct
11 Correct 30 ms 13656 KB Output is correct
12 Correct 39 ms 15576 KB Output is correct
13 Correct 2 ms 8024 KB Output is correct
14 Correct 2 ms 7772 KB Output is correct
15 Correct 2 ms 7772 KB Output is correct
16 Correct 2 ms 7768 KB Output is correct
17 Correct 2 ms 7772 KB Output is correct
18 Correct 2 ms 7772 KB Output is correct
19 Correct 2 ms 7772 KB Output is correct
20 Correct 2 ms 7772 KB Output is correct
21 Correct 2 ms 7772 KB Output is correct
22 Correct 2 ms 7772 KB Output is correct
23 Correct 2 ms 7772 KB Output is correct
24 Correct 2 ms 7768 KB Output is correct
25 Correct 2 ms 8024 KB Output is correct
26 Correct 2 ms 7960 KB Output is correct
27 Correct 2 ms 7772 KB Output is correct
28 Correct 2 ms 7772 KB Output is correct
29 Correct 2 ms 7772 KB Output is correct
30 Correct 2 ms 7772 KB Output is correct
31 Correct 2 ms 7768 KB Output is correct
32 Correct 2 ms 7768 KB Output is correct
33 Correct 2 ms 7772 KB Output is correct
34 Correct 2 ms 7768 KB Output is correct
35 Correct 2 ms 7768 KB Output is correct
36 Correct 2 ms 7972 KB Output is correct
37 Correct 2 ms 7772 KB Output is correct
38 Correct 2 ms 7772 KB Output is correct
39 Correct 33 ms 17108 KB Output is correct
40 Correct 36 ms 17104 KB Output is correct
41 Correct 23 ms 14292 KB Output is correct
42 Correct 7 ms 9304 KB Output is correct
43 Correct 2 ms 7772 KB Output is correct
44 Correct 2 ms 7772 KB Output is correct
45 Correct 2 ms 7772 KB Output is correct
46 Correct 2 ms 7768 KB Output is correct
47 Correct 2 ms 7772 KB Output is correct
48 Correct 2 ms 7772 KB Output is correct
49 Correct 2 ms 7772 KB Output is correct
50 Correct 2 ms 7772 KB Output is correct
51 Correct 2 ms 7772 KB Output is correct
52 Correct 2 ms 7772 KB Output is correct
53 Correct 2 ms 7772 KB Output is correct
54 Correct 2 ms 7956 KB Output is correct
55 Correct 2 ms 7772 KB Output is correct
56 Correct 2 ms 7772 KB Output is correct
57 Correct 35 ms 12128 KB Output is correct
58 Correct 37 ms 11856 KB Output is correct
59 Correct 35 ms 11860 KB Output is correct
60 Correct 36 ms 11868 KB Output is correct
61 Correct 36 ms 11880 KB Output is correct
62 Correct 36 ms 11860 KB Output is correct
63 Correct 37 ms 11864 KB Output is correct
64 Correct 33 ms 11612 KB Output is correct
65 Correct 33 ms 11604 KB Output is correct
66 Correct 33 ms 11716 KB Output is correct
67 Correct 36 ms 11860 KB Output is correct
68 Correct 36 ms 11960 KB Output is correct
69 Correct 38 ms 11868 KB Output is correct
70 Correct 38 ms 11900 KB Output is correct
71 Correct 2 ms 7768 KB Output is correct
72 Correct 3 ms 8024 KB Output is correct
73 Correct 3 ms 8028 KB Output is correct
74 Correct 3 ms 8028 KB Output is correct
75 Correct 3 ms 8028 KB Output is correct
76 Correct 3 ms 8028 KB Output is correct
77 Correct 3 ms 8024 KB Output is correct
78 Correct 3 ms 8028 KB Output is correct
79 Correct 3 ms 8024 KB Output is correct
80 Correct 38 ms 11864 KB Output is correct
81 Correct 37 ms 11868 KB Output is correct
82 Correct 36 ms 11848 KB Output is correct
83 Correct 38 ms 12368 KB Output is correct
84 Correct 2 ms 8028 KB Output is correct
85 Correct 2 ms 8024 KB Output is correct
86 Correct 2 ms 8028 KB Output is correct
87 Correct 3 ms 8028 KB Output is correct
88 Correct 3 ms 8028 KB Output is correct
89 Correct 2 ms 8028 KB Output is correct
90 Correct 2 ms 8028 KB Output is correct
91 Correct 3 ms 8028 KB Output is correct
92 Correct 3 ms 8028 KB Output is correct
93 Correct 5 ms 7860 KB Output is correct
94 Correct 2 ms 7772 KB Output is correct
95 Correct 2 ms 7772 KB Output is correct
96 Correct 2 ms 7772 KB Output is correct
97 Correct 2 ms 7772 KB Output is correct
98 Correct 2 ms 7768 KB Output is correct
99 Correct 2 ms 7772 KB Output is correct
100 Correct 2 ms 7772 KB Output is correct
101 Correct 2 ms 7772 KB Output is correct
102 Correct 2 ms 7772 KB Output is correct
103 Correct 2 ms 7772 KB Output is correct
104 Correct 5 ms 8540 KB Output is correct
105 Correct 9 ms 10076 KB Output is correct
106 Correct 2 ms 7772 KB Output is correct
107 Correct 16 ms 11052 KB Output is correct
108 Correct 21 ms 12504 KB Output is correct
109 Correct 2 ms 7772 KB Output is correct
110 Correct 32 ms 13636 KB Output is correct
111 Correct 33 ms 15560 KB Output is correct
112 Correct 2 ms 8028 KB Output is correct
113 Correct 45 ms 18064 KB Output is correct
114 Correct 15 ms 11864 KB Output is correct
115 Correct 15 ms 11868 KB Output is correct
116 Correct 16 ms 11884 KB Output is correct
117 Correct 16 ms 11868 KB Output is correct
118 Correct 16 ms 11760 KB Output is correct
119 Correct 16 ms 12124 KB Output is correct
120 Correct 17 ms 12124 KB Output is correct
121 Correct 15 ms 11864 KB Output is correct
122 Correct 15 ms 11868 KB Output is correct
123 Correct 16 ms 12124 KB Output is correct
124 Correct 2 ms 7772 KB Output is correct
125 Correct 7 ms 11100 KB Output is correct
126 Correct 7 ms 11096 KB Output is correct
127 Correct 7 ms 10844 KB Output is correct
128 Correct 7 ms 11096 KB Output is correct
129 Correct 7 ms 10852 KB Output is correct
130 Correct 7 ms 10844 KB Output is correct
131 Correct 7 ms 11032 KB Output is correct
132 Correct 8 ms 10844 KB Output is correct
133 Incorrect 1 ms 7772 KB Output isn't correct
134 Halted 0 ms 0 KB -