Submission #27657

# Submission time Handle Problem Language Result Execution time Memory
27657 2017-07-13T11:27:12 Z repeating Dreaming (IOI13_dreaming) C++11
47 / 100
132 ms 17272 KB
#include <bits/stdc++.h>
#include "dreaming.h"
#define F first
#define S second
#define P push
#define pb push_back
#define MEM(dp,i) memset(dp,i,sizeof(dp))
#define W while
#define R return
#define C continue
#define SI size()
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define pii pair<int,int>
#define SF(x) scanf("%I64d",&x)
#define SF2(x,y) scanf("%I64d%I64d",&x,&y)
#define SF3(x,y,z) scanf("%I64d%I64d%I64d",&x,&y,&z)
#define SF4(x,y,z,o) scanf("%I64d%I64d%I64d%I64d",&x,&y,&z,&o)
#define all(v) v.begin(),v.end()

using namespace std;
const long long INF = 1e9;
const int MX=100005;

int n,m,l,dis[MX],go[MX];
vector<pii> adj[MX];
bool vis[MX];
pii DFS(int ver,int par,bool b){
    vis[ver]=1;
    pii ret;
    ret={0,ver};
    pii p;
    for(auto i : adj[ver]){
        if(i.F==par)C;
        if(b)dis[i.F]=dis[ver]+i.S;
        p=DFS(i.F,ver,b);
        p.F+=i.S;
        if(p.F>=ret.F){
            ret.F=p.F;
            ret.S=p.S;
        }
    }
//    cout<<ver<<" "<<ret.F<<" "<<ret.S<<endl;
    if(b)go[ver]=ret.F;
    R ret;
}
pii dfs(int ver,int dia,int par){
    if(dis[ver]+go[ver]!=dia)R {0,INF};
    pii ret={dis[ver],go[ver]};
//    cout<<ver<<" "<<dis[ver]<<" "<<go[ver]<<endl;
    for(auto i : adj[ver]){
        if(par==i.F)C;
        pii p=dfs(i.F,dia,ver);
        if(abs(p.F-p.S)<abs(ret.F-ret.S)){
            ret=p;
        }
    }
    R ret;
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    n=N,m=M,l=L;
    for(int i=0;i<m;i++){
        adj[A[i]].pb({B[i],T[i]});
        adj[B[i]].pb({A[i],T[i]});
    }
    int mx1=0,mx2=0;
    int ret=0;
    for(int i=0;i<n;i++){
        if(vis[i])C;
        pii p=DFS(i,-1,0);
        int x=p.S;
        p=DFS(p.S,-1,1);
        pii d=dfs(x,p.F,-1);
        ret=max(ret,p.F);
//        cout<<i<<" "<<p.F<<" "<<d.F<<" "<<d.S<<endl;
        if(d.F<d.S)swap(d.F,d.S);
        mx2=max(mx2,d.F);
        if(mx1<mx2)swap(mx1,mx2);
    }
    int b=N-M-1;
    if(b>1){
        ret=max(ret,2*L);
    }
    ret=max(ret,mx1+mx2+(l*(b>0)));
    return ret;
}
# Verdict Execution time Memory Grader output
1 Correct 67 ms 15992 KB Output is correct
2 Correct 88 ms 15992 KB Output is correct
3 Correct 46 ms 11384 KB Output is correct
4 Correct 11 ms 4608 KB Output is correct
5 Correct 10 ms 3712 KB Output is correct
6 Correct 18 ms 5632 KB Output is correct
7 Correct 4 ms 2712 KB Output is correct
8 Correct 29 ms 7040 KB Output is correct
9 Correct 38 ms 9080 KB Output is correct
10 Correct 4 ms 2816 KB Output is correct
11 Correct 59 ms 10720 KB Output is correct
12 Correct 83 ms 13432 KB Output is correct
13 Correct 5 ms 2816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 15992 KB Output is correct
2 Correct 88 ms 15992 KB Output is correct
3 Correct 46 ms 11384 KB Output is correct
4 Correct 11 ms 4608 KB Output is correct
5 Correct 10 ms 3712 KB Output is correct
6 Correct 18 ms 5632 KB Output is correct
7 Correct 4 ms 2712 KB Output is correct
8 Correct 29 ms 7040 KB Output is correct
9 Correct 38 ms 9080 KB Output is correct
10 Correct 4 ms 2816 KB Output is correct
11 Correct 59 ms 10720 KB Output is correct
12 Correct 83 ms 13432 KB Output is correct
13 Correct 5 ms 2816 KB Output is correct
14 Correct 4 ms 2688 KB Output is correct
15 Correct 4 ms 2688 KB Output is correct
16 Correct 4 ms 2688 KB Output is correct
17 Correct 4 ms 2688 KB Output is correct
18 Correct 3 ms 2688 KB Output is correct
19 Correct 3 ms 2688 KB Output is correct
20 Correct 4 ms 2688 KB Output is correct
21 Correct 4 ms 2688 KB Output is correct
22 Correct 4 ms 2688 KB Output is correct
23 Correct 4 ms 2688 KB Output is correct
24 Correct 4 ms 2688 KB Output is correct
25 Correct 4 ms 2688 KB Output is correct
26 Correct 4 ms 2688 KB Output is correct
27 Correct 3 ms 2688 KB Output is correct
28 Correct 4 ms 2688 KB Output is correct
29 Correct 4 ms 2688 KB Output is correct
30 Correct 3 ms 2688 KB Output is correct
31 Correct 4 ms 2688 KB Output is correct
32 Correct 4 ms 2688 KB Output is correct
33 Correct 4 ms 2688 KB Output is correct
34 Correct 4 ms 2688 KB Output is correct
35 Correct 4 ms 2688 KB Output is correct
36 Correct 4 ms 2688 KB Output is correct
37 Correct 3 ms 2688 KB Output is correct
38 Correct 3 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 15992 KB Output is correct
2 Correct 88 ms 15992 KB Output is correct
3 Correct 46 ms 11384 KB Output is correct
4 Correct 11 ms 4608 KB Output is correct
5 Correct 10 ms 3712 KB Output is correct
6 Correct 18 ms 5632 KB Output is correct
7 Correct 4 ms 2712 KB Output is correct
8 Correct 29 ms 7040 KB Output is correct
9 Correct 38 ms 9080 KB Output is correct
10 Correct 4 ms 2816 KB Output is correct
11 Correct 59 ms 10720 KB Output is correct
12 Correct 83 ms 13432 KB Output is correct
13 Correct 5 ms 2816 KB Output is correct
14 Correct 4 ms 2688 KB Output is correct
15 Correct 4 ms 2688 KB Output is correct
16 Correct 4 ms 2688 KB Output is correct
17 Correct 4 ms 2688 KB Output is correct
18 Correct 3 ms 2688 KB Output is correct
19 Correct 3 ms 2688 KB Output is correct
20 Correct 4 ms 2688 KB Output is correct
21 Correct 4 ms 2688 KB Output is correct
22 Correct 4 ms 2688 KB Output is correct
23 Correct 4 ms 2688 KB Output is correct
24 Correct 4 ms 2688 KB Output is correct
25 Correct 4 ms 2688 KB Output is correct
26 Correct 4 ms 2688 KB Output is correct
27 Correct 3 ms 2688 KB Output is correct
28 Correct 4 ms 2688 KB Output is correct
29 Correct 4 ms 2688 KB Output is correct
30 Correct 3 ms 2688 KB Output is correct
31 Correct 4 ms 2688 KB Output is correct
32 Correct 4 ms 2688 KB Output is correct
33 Correct 4 ms 2688 KB Output is correct
34 Correct 4 ms 2688 KB Output is correct
35 Correct 4 ms 2688 KB Output is correct
36 Correct 4 ms 2688 KB Output is correct
37 Correct 3 ms 2688 KB Output is correct
38 Correct 3 ms 2688 KB Output is correct
39 Correct 86 ms 16020 KB Output is correct
40 Correct 72 ms 15992 KB Output is correct
41 Correct 42 ms 11384 KB Output is correct
42 Correct 12 ms 4608 KB Output is correct
43 Correct 4 ms 2688 KB Output is correct
44 Correct 4 ms 2688 KB Output is correct
45 Correct 4 ms 2688 KB Output is correct
46 Correct 3 ms 2688 KB Output is correct
47 Correct 4 ms 2688 KB Output is correct
48 Correct 4 ms 2688 KB Output is correct
49 Correct 5 ms 2688 KB Output is correct
50 Correct 4 ms 2688 KB Output is correct
51 Correct 4 ms 2688 KB Output is correct
52 Correct 4 ms 2688 KB Output is correct
53 Correct 3 ms 2688 KB Output is correct
54 Correct 4 ms 2688 KB Output is correct
55 Correct 4 ms 2688 KB Output is correct
56 Correct 3 ms 2688 KB Output is correct
57 Correct 81 ms 8692 KB Output is correct
58 Correct 77 ms 8696 KB Output is correct
59 Correct 65 ms 8824 KB Output is correct
60 Correct 76 ms 8696 KB Output is correct
61 Correct 79 ms 8572 KB Output is correct
62 Correct 72 ms 8512 KB Output is correct
63 Correct 75 ms 8440 KB Output is correct
64 Correct 69 ms 8440 KB Output is correct
65 Correct 65 ms 8440 KB Output is correct
66 Correct 65 ms 8412 KB Output is correct
67 Correct 76 ms 8824 KB Output is correct
68 Correct 85 ms 8648 KB Output is correct
69 Correct 76 ms 8696 KB Output is correct
70 Correct 69 ms 8696 KB Output is correct
71 Correct 4 ms 2688 KB Output is correct
72 Correct 5 ms 2944 KB Output is correct
73 Correct 5 ms 2816 KB Output is correct
74 Correct 5 ms 2944 KB Output is correct
75 Correct 5 ms 2944 KB Output is correct
76 Correct 5 ms 2944 KB Output is correct
77 Correct 5 ms 2816 KB Output is correct
78 Correct 5 ms 2944 KB Output is correct
79 Correct 5 ms 2944 KB Output is correct
80 Correct 82 ms 8696 KB Output is correct
81 Correct 67 ms 8568 KB Output is correct
82 Correct 82 ms 8568 KB Output is correct
83 Correct 89 ms 8568 KB Output is correct
84 Correct 5 ms 2788 KB Output is correct
85 Correct 5 ms 2816 KB Output is correct
86 Correct 5 ms 2816 KB Output is correct
87 Correct 5 ms 2816 KB Output is correct
88 Correct 5 ms 2816 KB Output is correct
89 Correct 5 ms 2816 KB Output is correct
90 Correct 5 ms 2816 KB Output is correct
91 Correct 5 ms 2944 KB Output is correct
92 Correct 5 ms 2816 KB Output is correct
93 Correct 5 ms 2816 KB Output is correct
94 Correct 4 ms 2688 KB Output is correct
95 Correct 4 ms 2688 KB Output is correct
96 Correct 4 ms 2688 KB Output is correct
97 Correct 3 ms 2688 KB Output is correct
98 Correct 4 ms 2688 KB Output is correct
99 Correct 4 ms 2688 KB Output is correct
100 Correct 4 ms 2688 KB Output is correct
101 Correct 4 ms 2688 KB Output is correct
102 Correct 4 ms 2688 KB Output is correct
103 Correct 4 ms 2688 KB Output is correct
104 Correct 9 ms 3712 KB Output is correct
105 Correct 18 ms 5632 KB Output is correct
106 Correct 4 ms 2688 KB Output is correct
107 Correct 31 ms 7036 KB Output is correct
108 Correct 39 ms 9080 KB Output is correct
109 Correct 4 ms 2816 KB Output is correct
110 Correct 58 ms 10872 KB Output is correct
111 Correct 76 ms 13304 KB Output is correct
112 Correct 7 ms 2816 KB Output is correct
113 Correct 132 ms 17272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 5760 KB Output is correct
2 Incorrect 28 ms 5852 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 67 ms 15992 KB Output is correct
2 Correct 88 ms 15992 KB Output is correct
3 Correct 46 ms 11384 KB Output is correct
4 Correct 11 ms 4608 KB Output is correct
5 Correct 10 ms 3712 KB Output is correct
6 Correct 18 ms 5632 KB Output is correct
7 Correct 4 ms 2712 KB Output is correct
8 Correct 29 ms 7040 KB Output is correct
9 Correct 38 ms 9080 KB Output is correct
10 Correct 4 ms 2816 KB Output is correct
11 Correct 59 ms 10720 KB Output is correct
12 Correct 83 ms 13432 KB Output is correct
13 Correct 5 ms 2816 KB Output is correct
14 Correct 4 ms 2816 KB Output is correct
15 Correct 4 ms 2816 KB Output is correct
16 Correct 5 ms 2816 KB Output is correct
17 Correct 4 ms 2816 KB Output is correct
18 Correct 5 ms 2816 KB Output is correct
19 Correct 5 ms 2816 KB Output is correct
20 Incorrect 4 ms 2688 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 67 ms 15992 KB Output is correct
2 Correct 88 ms 15992 KB Output is correct
3 Correct 46 ms 11384 KB Output is correct
4 Correct 11 ms 4608 KB Output is correct
5 Correct 10 ms 3712 KB Output is correct
6 Correct 18 ms 5632 KB Output is correct
7 Correct 4 ms 2712 KB Output is correct
8 Correct 29 ms 7040 KB Output is correct
9 Correct 38 ms 9080 KB Output is correct
10 Correct 4 ms 2816 KB Output is correct
11 Correct 59 ms 10720 KB Output is correct
12 Correct 83 ms 13432 KB Output is correct
13 Correct 5 ms 2816 KB Output is correct
14 Correct 4 ms 2688 KB Output is correct
15 Correct 4 ms 2688 KB Output is correct
16 Correct 4 ms 2688 KB Output is correct
17 Correct 4 ms 2688 KB Output is correct
18 Correct 3 ms 2688 KB Output is correct
19 Correct 3 ms 2688 KB Output is correct
20 Correct 4 ms 2688 KB Output is correct
21 Correct 4 ms 2688 KB Output is correct
22 Correct 4 ms 2688 KB Output is correct
23 Correct 4 ms 2688 KB Output is correct
24 Correct 4 ms 2688 KB Output is correct
25 Correct 4 ms 2688 KB Output is correct
26 Correct 4 ms 2688 KB Output is correct
27 Correct 3 ms 2688 KB Output is correct
28 Correct 4 ms 2688 KB Output is correct
29 Correct 4 ms 2688 KB Output is correct
30 Correct 3 ms 2688 KB Output is correct
31 Correct 4 ms 2688 KB Output is correct
32 Correct 4 ms 2688 KB Output is correct
33 Correct 4 ms 2688 KB Output is correct
34 Correct 4 ms 2688 KB Output is correct
35 Correct 4 ms 2688 KB Output is correct
36 Correct 4 ms 2688 KB Output is correct
37 Correct 3 ms 2688 KB Output is correct
38 Correct 3 ms 2688 KB Output is correct
39 Correct 86 ms 16020 KB Output is correct
40 Correct 72 ms 15992 KB Output is correct
41 Correct 42 ms 11384 KB Output is correct
42 Correct 12 ms 4608 KB Output is correct
43 Correct 4 ms 2688 KB Output is correct
44 Correct 4 ms 2688 KB Output is correct
45 Correct 4 ms 2688 KB Output is correct
46 Correct 3 ms 2688 KB Output is correct
47 Correct 4 ms 2688 KB Output is correct
48 Correct 4 ms 2688 KB Output is correct
49 Correct 5 ms 2688 KB Output is correct
50 Correct 4 ms 2688 KB Output is correct
51 Correct 4 ms 2688 KB Output is correct
52 Correct 4 ms 2688 KB Output is correct
53 Correct 3 ms 2688 KB Output is correct
54 Correct 4 ms 2688 KB Output is correct
55 Correct 4 ms 2688 KB Output is correct
56 Correct 3 ms 2688 KB Output is correct
57 Correct 81 ms 8692 KB Output is correct
58 Correct 77 ms 8696 KB Output is correct
59 Correct 65 ms 8824 KB Output is correct
60 Correct 76 ms 8696 KB Output is correct
61 Correct 79 ms 8572 KB Output is correct
62 Correct 72 ms 8512 KB Output is correct
63 Correct 75 ms 8440 KB Output is correct
64 Correct 69 ms 8440 KB Output is correct
65 Correct 65 ms 8440 KB Output is correct
66 Correct 65 ms 8412 KB Output is correct
67 Correct 76 ms 8824 KB Output is correct
68 Correct 85 ms 8648 KB Output is correct
69 Correct 76 ms 8696 KB Output is correct
70 Correct 69 ms 8696 KB Output is correct
71 Correct 4 ms 2688 KB Output is correct
72 Correct 5 ms 2944 KB Output is correct
73 Correct 5 ms 2816 KB Output is correct
74 Correct 5 ms 2944 KB Output is correct
75 Correct 5 ms 2944 KB Output is correct
76 Correct 5 ms 2944 KB Output is correct
77 Correct 5 ms 2816 KB Output is correct
78 Correct 5 ms 2944 KB Output is correct
79 Correct 5 ms 2944 KB Output is correct
80 Correct 82 ms 8696 KB Output is correct
81 Correct 67 ms 8568 KB Output is correct
82 Correct 82 ms 8568 KB Output is correct
83 Correct 89 ms 8568 KB Output is correct
84 Correct 5 ms 2788 KB Output is correct
85 Correct 5 ms 2816 KB Output is correct
86 Correct 5 ms 2816 KB Output is correct
87 Correct 5 ms 2816 KB Output is correct
88 Correct 5 ms 2816 KB Output is correct
89 Correct 5 ms 2816 KB Output is correct
90 Correct 5 ms 2816 KB Output is correct
91 Correct 5 ms 2944 KB Output is correct
92 Correct 5 ms 2816 KB Output is correct
93 Correct 5 ms 2816 KB Output is correct
94 Correct 4 ms 2688 KB Output is correct
95 Correct 4 ms 2688 KB Output is correct
96 Correct 4 ms 2688 KB Output is correct
97 Correct 3 ms 2688 KB Output is correct
98 Correct 4 ms 2688 KB Output is correct
99 Correct 4 ms 2688 KB Output is correct
100 Correct 4 ms 2688 KB Output is correct
101 Correct 4 ms 2688 KB Output is correct
102 Correct 4 ms 2688 KB Output is correct
103 Correct 4 ms 2688 KB Output is correct
104 Correct 9 ms 3712 KB Output is correct
105 Correct 18 ms 5632 KB Output is correct
106 Correct 4 ms 2688 KB Output is correct
107 Correct 31 ms 7036 KB Output is correct
108 Correct 39 ms 9080 KB Output is correct
109 Correct 4 ms 2816 KB Output is correct
110 Correct 58 ms 10872 KB Output is correct
111 Correct 76 ms 13304 KB Output is correct
112 Correct 7 ms 2816 KB Output is correct
113 Correct 132 ms 17272 KB Output is correct
114 Correct 23 ms 5760 KB Output is correct
115 Incorrect 28 ms 5852 KB Output isn't correct
116 Halted 0 ms 0 KB -