Submission #126878

# Submission time Handle Problem Language Result Execution time Memory
126878 2019-07-08T14:44:15 Z Bench0310 Dreaming (IOI13_dreaming) C++17
59 / 100
1000 ms 12536 KB
#include <bits/stdc++.h>
#include "dreaming.h"
#pragma GCC optimize ("Ofast")

using namespace std;
const int N=100005;

vector<pair<int,int>> v[N];
vector<bool> vis(N,0);
vector<int> diameter(N,0);
vector<int> center(N,0);
int dist[N];
vector<int> path;

pair<int,int> get_last(int a)
{
    memset(dist,-1,sizeof dist);
    dist[a]=0;
    queue<int> q;
    q.push(a);
    int last=a;
    while(!q.empty())
    {
        int e=q.front();
        q.pop();
        vis[e]=1;
        for(pair<int,int> p:v[e])
        {
            int to=p.first;
            if(dist[to]!=-1) continue;
            dist[to]=dist[e]+p.second;
            q.push(to);
            if(dist[to]>dist[last]) last=to;
        }
    }
    return make_pair(last,dist[last]);
}

bool get_path(int a,int p,int b)
{
    if(a==b) return 1;
    for(pair<int,int> temp:v[a])
    {
        int to=temp.first;
        if(to==p) continue;
        if(get_path(to,a,b))
        {
            path.push_back(temp.second);
            return 1;
        }
    }
    return 0;
}

void get_center(int a,int id)
{
    int one,two,len;
    tie(one,ignore)=get_last(a);
    tie(two,len)=get_last(one);
    diameter[id]=len;
    path.clear();
    get_path(one,-1,two);
    int best=diameter[id];
    int sum=0;
    for(int i=0;i<(int)path.size();i++)
    {
        sum+=path[i];
        best=min(best,max(sum,diameter[id]-sum));
    }
    center[id]=best;
}

int solve(int n,int l)
{
    int id=0;
    for(int i=0;i<n;i++) if(vis[i]==0) get_center(i,id++);
    int res=0;
    vector<pair<int,int>> root;
    for(int i=0;i<id;i++)
    {
        res=max(res,diameter[i]);
        root.push_back(make_pair(center[i],i));
    }
    sort(root.begin(),root.end(),greater<pair<int,int>>());
    if(id>1) res=max(res,root[0].first+l+root[1].first);
    if(id>2) res=max(res,root[1].first+2*l+root[2].first);
    return res;
}

int travelTime(int n,int m,int l,int a[],int b[],int t[])
{
    for(int i=0;i<m;i++)
    {
        v[a[i]].push_back(make_pair(b[i],t[i]));
        v[b[i]].push_back(make_pair(a[i],t[i]));
    }
    return solve(n,l);
}

/*int main()
{
    freopen("C:\\Users\\Benja\\Downloads\\ioi2013tests\\dreaming\\two-sticks-9.in","r",stdin);
    int n,m,l;
    scanf("%d%d%d",&n,&m,&l);
    for(int i=0;i<m;i++)
    {
        int a,b,t;
        scanf("%d%d%d",&a,&b,&t);
        v[a].push_back(make_pair(b,t));
        v[b].push_back(make_pair(a,t));
    }
    printf("%d\n",solve(n,l));
    return 0;
}*/
# Verdict Execution time Memory Grader output
1 Correct 68 ms 11892 KB Output is correct
2 Correct 65 ms 11896 KB Output is correct
3 Correct 46 ms 9080 KB Output is correct
4 Correct 13 ms 5112 KB Output is correct
5 Correct 11 ms 4600 KB Output is correct
6 Correct 20 ms 5752 KB Output is correct
7 Correct 5 ms 3960 KB Output is correct
8 Correct 34 ms 6676 KB Output is correct
9 Correct 44 ms 7928 KB Output is correct
10 Correct 5 ms 3960 KB Output is correct
11 Correct 60 ms 9080 KB Output is correct
12 Correct 67 ms 10612 KB Output is correct
13 Correct 6 ms 3960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 11892 KB Output is correct
2 Correct 65 ms 11896 KB Output is correct
3 Correct 46 ms 9080 KB Output is correct
4 Correct 13 ms 5112 KB Output is correct
5 Correct 11 ms 4600 KB Output is correct
6 Correct 20 ms 5752 KB Output is correct
7 Correct 5 ms 3960 KB Output is correct
8 Correct 34 ms 6676 KB Output is correct
9 Correct 44 ms 7928 KB Output is correct
10 Correct 5 ms 3960 KB Output is correct
11 Correct 60 ms 9080 KB Output is correct
12 Correct 67 ms 10612 KB Output is correct
13 Correct 6 ms 3960 KB Output is correct
14 Correct 5 ms 3960 KB Output is correct
15 Correct 5 ms 3836 KB Output is correct
16 Correct 5 ms 3960 KB Output is correct
17 Correct 5 ms 3832 KB Output is correct
18 Correct 5 ms 3960 KB Output is correct
19 Correct 5 ms 3960 KB Output is correct
20 Correct 5 ms 3832 KB Output is correct
21 Correct 5 ms 3832 KB Output is correct
22 Correct 5 ms 3832 KB Output is correct
23 Correct 5 ms 3832 KB Output is correct
24 Correct 5 ms 3960 KB Output is correct
25 Correct 5 ms 3832 KB Output is correct
26 Correct 5 ms 3832 KB Output is correct
27 Correct 5 ms 3832 KB Output is correct
28 Correct 5 ms 3832 KB Output is correct
29 Correct 5 ms 3832 KB Output is correct
30 Correct 5 ms 3832 KB Output is correct
31 Correct 5 ms 3832 KB Output is correct
32 Correct 6 ms 3960 KB Output is correct
33 Correct 5 ms 3960 KB Output is correct
34 Correct 5 ms 3960 KB Output is correct
35 Correct 5 ms 3832 KB Output is correct
36 Correct 5 ms 3832 KB Output is correct
37 Correct 5 ms 3836 KB Output is correct
38 Correct 5 ms 3960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 11892 KB Output is correct
2 Correct 65 ms 11896 KB Output is correct
3 Correct 46 ms 9080 KB Output is correct
4 Correct 13 ms 5112 KB Output is correct
5 Correct 11 ms 4600 KB Output is correct
6 Correct 20 ms 5752 KB Output is correct
7 Correct 5 ms 3960 KB Output is correct
8 Correct 34 ms 6676 KB Output is correct
9 Correct 44 ms 7928 KB Output is correct
10 Correct 5 ms 3960 KB Output is correct
11 Correct 60 ms 9080 KB Output is correct
12 Correct 67 ms 10612 KB Output is correct
13 Correct 6 ms 3960 KB Output is correct
14 Correct 5 ms 3960 KB Output is correct
15 Correct 5 ms 3836 KB Output is correct
16 Correct 5 ms 3960 KB Output is correct
17 Correct 5 ms 3832 KB Output is correct
18 Correct 5 ms 3960 KB Output is correct
19 Correct 5 ms 3960 KB Output is correct
20 Correct 5 ms 3832 KB Output is correct
21 Correct 5 ms 3832 KB Output is correct
22 Correct 5 ms 3832 KB Output is correct
23 Correct 5 ms 3832 KB Output is correct
24 Correct 5 ms 3960 KB Output is correct
25 Correct 5 ms 3832 KB Output is correct
26 Correct 5 ms 3832 KB Output is correct
27 Correct 5 ms 3832 KB Output is correct
28 Correct 5 ms 3832 KB Output is correct
29 Correct 5 ms 3832 KB Output is correct
30 Correct 5 ms 3832 KB Output is correct
31 Correct 5 ms 3832 KB Output is correct
32 Correct 6 ms 3960 KB Output is correct
33 Correct 5 ms 3960 KB Output is correct
34 Correct 5 ms 3960 KB Output is correct
35 Correct 5 ms 3832 KB Output is correct
36 Correct 5 ms 3832 KB Output is correct
37 Correct 5 ms 3836 KB Output is correct
38 Correct 5 ms 3960 KB Output is correct
39 Correct 66 ms 11892 KB Output is correct
40 Correct 70 ms 11828 KB Output is correct
41 Correct 47 ms 9036 KB Output is correct
42 Correct 14 ms 5112 KB Output is correct
43 Correct 5 ms 3960 KB Output is correct
44 Correct 5 ms 3832 KB Output is correct
45 Correct 5 ms 3836 KB Output is correct
46 Correct 5 ms 3960 KB Output is correct
47 Correct 5 ms 3960 KB Output is correct
48 Correct 5 ms 3832 KB Output is correct
49 Correct 6 ms 3836 KB Output is correct
50 Correct 5 ms 3832 KB Output is correct
51 Correct 5 ms 3884 KB Output is correct
52 Correct 5 ms 3960 KB Output is correct
53 Correct 5 ms 3960 KB Output is correct
54 Correct 5 ms 3960 KB Output is correct
55 Correct 5 ms 3960 KB Output is correct
56 Correct 5 ms 3832 KB Output is correct
57 Correct 79 ms 8952 KB Output is correct
58 Correct 84 ms 9072 KB Output is correct
59 Correct 83 ms 8920 KB Output is correct
60 Correct 100 ms 9172 KB Output is correct
61 Correct 77 ms 8824 KB Output is correct
62 Correct 78 ms 8824 KB Output is correct
63 Correct 70 ms 8824 KB Output is correct
64 Correct 70 ms 8808 KB Output is correct
65 Correct 72 ms 8824 KB Output is correct
66 Correct 75 ms 8728 KB Output is correct
67 Correct 80 ms 9080 KB Output is correct
68 Correct 78 ms 8952 KB Output is correct
69 Correct 81 ms 8952 KB Output is correct
70 Correct 83 ms 8956 KB Output is correct
71 Correct 5 ms 3832 KB Output is correct
72 Correct 7 ms 4088 KB Output is correct
73 Correct 6 ms 4088 KB Output is correct
74 Correct 7 ms 3960 KB Output is correct
75 Correct 7 ms 3960 KB Output is correct
76 Correct 7 ms 4088 KB Output is correct
77 Correct 7 ms 3960 KB Output is correct
78 Correct 7 ms 3960 KB Output is correct
79 Correct 7 ms 4088 KB Output is correct
80 Correct 77 ms 8952 KB Output is correct
81 Correct 99 ms 8952 KB Output is correct
82 Correct 227 ms 8788 KB Output is correct
83 Correct 92 ms 8952 KB Output is correct
84 Correct 6 ms 3960 KB Output is correct
85 Correct 6 ms 3960 KB Output is correct
86 Correct 6 ms 3960 KB Output is correct
87 Correct 6 ms 3960 KB Output is correct
88 Correct 6 ms 3960 KB Output is correct
89 Correct 6 ms 4088 KB Output is correct
90 Correct 6 ms 3960 KB Output is correct
91 Correct 7 ms 3964 KB Output is correct
92 Correct 6 ms 3960 KB Output is correct
93 Correct 7 ms 3972 KB Output is correct
94 Correct 5 ms 3832 KB Output is correct
95 Correct 5 ms 3804 KB Output is correct
96 Correct 5 ms 3832 KB Output is correct
97 Correct 5 ms 3960 KB Output is correct
98 Correct 5 ms 3960 KB Output is correct
99 Correct 5 ms 3896 KB Output is correct
100 Correct 5 ms 3832 KB Output is correct
101 Correct 5 ms 3832 KB Output is correct
102 Correct 5 ms 3832 KB Output is correct
103 Correct 5 ms 3832 KB Output is correct
104 Correct 12 ms 4472 KB Output is correct
105 Correct 20 ms 5752 KB Output is correct
106 Correct 5 ms 3960 KB Output is correct
107 Correct 35 ms 6776 KB Output is correct
108 Correct 44 ms 7900 KB Output is correct
109 Correct 5 ms 3960 KB Output is correct
110 Correct 63 ms 9080 KB Output is correct
111 Correct 68 ms 10484 KB Output is correct
112 Correct 5 ms 3960 KB Output is correct
113 Correct 89 ms 12536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1083 ms 6264 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 68 ms 11892 KB Output is correct
2 Correct 65 ms 11896 KB Output is correct
3 Correct 46 ms 9080 KB Output is correct
4 Correct 13 ms 5112 KB Output is correct
5 Correct 11 ms 4600 KB Output is correct
6 Correct 20 ms 5752 KB Output is correct
7 Correct 5 ms 3960 KB Output is correct
8 Correct 34 ms 6676 KB Output is correct
9 Correct 44 ms 7928 KB Output is correct
10 Correct 5 ms 3960 KB Output is correct
11 Correct 60 ms 9080 KB Output is correct
12 Correct 67 ms 10612 KB Output is correct
13 Correct 6 ms 3960 KB Output is correct
14 Correct 12 ms 3832 KB Output is correct
15 Correct 19 ms 3960 KB Output is correct
16 Correct 27 ms 4088 KB Output is correct
17 Correct 12 ms 3960 KB Output is correct
18 Correct 19 ms 4044 KB Output is correct
19 Correct 24 ms 3960 KB Output is correct
20 Correct 11 ms 3960 KB Output is correct
21 Correct 16 ms 4040 KB Output is correct
22 Correct 23 ms 4088 KB Output is correct
23 Correct 5 ms 3832 KB Output is correct
24 Correct 5 ms 3832 KB Output is correct
25 Correct 5 ms 3832 KB Output is correct
26 Correct 5 ms 3832 KB Output is correct
27 Correct 5 ms 3856 KB Output is correct
28 Correct 9 ms 3832 KB Output is correct
29 Correct 8 ms 3832 KB Output is correct
30 Correct 5 ms 3832 KB Output is correct
31 Correct 5 ms 3960 KB Output is correct
32 Correct 5 ms 3832 KB Output is correct
33 Correct 5 ms 3832 KB Output is correct
34 Correct 5 ms 3960 KB Output is correct
35 Correct 5 ms 3832 KB Output is correct
36 Correct 5 ms 3832 KB Output is correct
37 Correct 5 ms 3832 KB Output is correct
38 Correct 5 ms 3832 KB Output is correct
39 Correct 5 ms 3832 KB Output is correct
40 Correct 5 ms 3832 KB Output is correct
41 Correct 5 ms 3832 KB Output is correct
42 Correct 7 ms 4088 KB Output is correct
43 Correct 7 ms 4088 KB Output is correct
44 Correct 58 ms 3964 KB Output is correct
45 Correct 99 ms 3960 KB Output is correct
46 Correct 7 ms 3960 KB Output is correct
47 Correct 6 ms 3960 KB Output is correct
48 Correct 107 ms 4088 KB Output is correct
49 Correct 95 ms 3960 KB Output is correct
50 Correct 7 ms 4088 KB Output is correct
51 Correct 7 ms 3960 KB Output is correct
52 Correct 120 ms 3980 KB Output is correct
53 Correct 54 ms 4088 KB Output is correct
54 Correct 7 ms 4088 KB Output is correct
55 Correct 7 ms 4088 KB Output is correct
56 Correct 50 ms 3960 KB Output is correct
57 Correct 44 ms 3960 KB Output is correct
58 Correct 89 ms 3960 KB Output is correct
59 Correct 87 ms 3960 KB Output is correct
60 Correct 7 ms 3960 KB Output is correct
61 Correct 7 ms 3960 KB Output is correct
62 Correct 14 ms 3960 KB Output is correct
63 Correct 13 ms 3960 KB Output is correct
64 Correct 6 ms 4088 KB Output is correct
65 Correct 7 ms 4088 KB Output is correct
66 Correct 85 ms 3992 KB Output is correct
67 Correct 85 ms 3932 KB Output is correct
68 Correct 123 ms 3960 KB Output is correct
69 Correct 122 ms 3920 KB Output is correct
70 Correct 23 ms 4088 KB Output is correct
71 Correct 19 ms 3960 KB Output is correct
72 Correct 86 ms 3980 KB Output is correct
73 Correct 114 ms 3960 KB Output is correct
74 Correct 61 ms 4024 KB Output is correct
75 Correct 17 ms 3960 KB Output is correct
76 Correct 54 ms 4016 KB Output is correct
77 Correct 59 ms 4020 KB Output is correct
78 Correct 78 ms 4088 KB Output is correct
79 Correct 87 ms 3984 KB Output is correct
80 Correct 6 ms 3932 KB Output is correct
81 Correct 6 ms 3960 KB Output is correct
82 Correct 6 ms 4012 KB Output is correct
83 Correct 6 ms 4060 KB Output is correct
84 Correct 6 ms 3964 KB Output is correct
85 Correct 7 ms 3960 KB Output is correct
86 Correct 6 ms 3960 KB Output is correct
87 Correct 7 ms 4036 KB Output is correct
88 Correct 7 ms 4048 KB Output is correct
89 Correct 6 ms 3960 KB Output is correct
90 Correct 5 ms 3832 KB Output is correct
91 Correct 5 ms 3832 KB Output is correct
92 Correct 5 ms 3832 KB Output is correct
93 Correct 5 ms 3832 KB Output is correct
94 Correct 5 ms 3832 KB Output is correct
95 Correct 6 ms 3832 KB Output is correct
96 Correct 5 ms 3832 KB Output is correct
97 Correct 5 ms 3836 KB Output is correct
98 Correct 5 ms 3960 KB Output is correct
99 Correct 5 ms 3832 KB Output is correct
100 Correct 5 ms 3832 KB Output is correct
101 Correct 5 ms 3960 KB Output is correct
102 Correct 6 ms 3960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 11892 KB Output is correct
2 Correct 65 ms 11896 KB Output is correct
3 Correct 46 ms 9080 KB Output is correct
4 Correct 13 ms 5112 KB Output is correct
5 Correct 11 ms 4600 KB Output is correct
6 Correct 20 ms 5752 KB Output is correct
7 Correct 5 ms 3960 KB Output is correct
8 Correct 34 ms 6676 KB Output is correct
9 Correct 44 ms 7928 KB Output is correct
10 Correct 5 ms 3960 KB Output is correct
11 Correct 60 ms 9080 KB Output is correct
12 Correct 67 ms 10612 KB Output is correct
13 Correct 6 ms 3960 KB Output is correct
14 Correct 5 ms 3960 KB Output is correct
15 Correct 5 ms 3836 KB Output is correct
16 Correct 5 ms 3960 KB Output is correct
17 Correct 5 ms 3832 KB Output is correct
18 Correct 5 ms 3960 KB Output is correct
19 Correct 5 ms 3960 KB Output is correct
20 Correct 5 ms 3832 KB Output is correct
21 Correct 5 ms 3832 KB Output is correct
22 Correct 5 ms 3832 KB Output is correct
23 Correct 5 ms 3832 KB Output is correct
24 Correct 5 ms 3960 KB Output is correct
25 Correct 5 ms 3832 KB Output is correct
26 Correct 5 ms 3832 KB Output is correct
27 Correct 5 ms 3832 KB Output is correct
28 Correct 5 ms 3832 KB Output is correct
29 Correct 5 ms 3832 KB Output is correct
30 Correct 5 ms 3832 KB Output is correct
31 Correct 5 ms 3832 KB Output is correct
32 Correct 6 ms 3960 KB Output is correct
33 Correct 5 ms 3960 KB Output is correct
34 Correct 5 ms 3960 KB Output is correct
35 Correct 5 ms 3832 KB Output is correct
36 Correct 5 ms 3832 KB Output is correct
37 Correct 5 ms 3836 KB Output is correct
38 Correct 5 ms 3960 KB Output is correct
39 Correct 66 ms 11892 KB Output is correct
40 Correct 70 ms 11828 KB Output is correct
41 Correct 47 ms 9036 KB Output is correct
42 Correct 14 ms 5112 KB Output is correct
43 Correct 5 ms 3960 KB Output is correct
44 Correct 5 ms 3832 KB Output is correct
45 Correct 5 ms 3836 KB Output is correct
46 Correct 5 ms 3960 KB Output is correct
47 Correct 5 ms 3960 KB Output is correct
48 Correct 5 ms 3832 KB Output is correct
49 Correct 6 ms 3836 KB Output is correct
50 Correct 5 ms 3832 KB Output is correct
51 Correct 5 ms 3884 KB Output is correct
52 Correct 5 ms 3960 KB Output is correct
53 Correct 5 ms 3960 KB Output is correct
54 Correct 5 ms 3960 KB Output is correct
55 Correct 5 ms 3960 KB Output is correct
56 Correct 5 ms 3832 KB Output is correct
57 Correct 79 ms 8952 KB Output is correct
58 Correct 84 ms 9072 KB Output is correct
59 Correct 83 ms 8920 KB Output is correct
60 Correct 100 ms 9172 KB Output is correct
61 Correct 77 ms 8824 KB Output is correct
62 Correct 78 ms 8824 KB Output is correct
63 Correct 70 ms 8824 KB Output is correct
64 Correct 70 ms 8808 KB Output is correct
65 Correct 72 ms 8824 KB Output is correct
66 Correct 75 ms 8728 KB Output is correct
67 Correct 80 ms 9080 KB Output is correct
68 Correct 78 ms 8952 KB Output is correct
69 Correct 81 ms 8952 KB Output is correct
70 Correct 83 ms 8956 KB Output is correct
71 Correct 5 ms 3832 KB Output is correct
72 Correct 7 ms 4088 KB Output is correct
73 Correct 6 ms 4088 KB Output is correct
74 Correct 7 ms 3960 KB Output is correct
75 Correct 7 ms 3960 KB Output is correct
76 Correct 7 ms 4088 KB Output is correct
77 Correct 7 ms 3960 KB Output is correct
78 Correct 7 ms 3960 KB Output is correct
79 Correct 7 ms 4088 KB Output is correct
80 Correct 77 ms 8952 KB Output is correct
81 Correct 99 ms 8952 KB Output is correct
82 Correct 227 ms 8788 KB Output is correct
83 Correct 92 ms 8952 KB Output is correct
84 Correct 6 ms 3960 KB Output is correct
85 Correct 6 ms 3960 KB Output is correct
86 Correct 6 ms 3960 KB Output is correct
87 Correct 6 ms 3960 KB Output is correct
88 Correct 6 ms 3960 KB Output is correct
89 Correct 6 ms 4088 KB Output is correct
90 Correct 6 ms 3960 KB Output is correct
91 Correct 7 ms 3964 KB Output is correct
92 Correct 6 ms 3960 KB Output is correct
93 Correct 7 ms 3972 KB Output is correct
94 Correct 5 ms 3832 KB Output is correct
95 Correct 5 ms 3804 KB Output is correct
96 Correct 5 ms 3832 KB Output is correct
97 Correct 5 ms 3960 KB Output is correct
98 Correct 5 ms 3960 KB Output is correct
99 Correct 5 ms 3896 KB Output is correct
100 Correct 5 ms 3832 KB Output is correct
101 Correct 5 ms 3832 KB Output is correct
102 Correct 5 ms 3832 KB Output is correct
103 Correct 5 ms 3832 KB Output is correct
104 Correct 12 ms 4472 KB Output is correct
105 Correct 20 ms 5752 KB Output is correct
106 Correct 5 ms 3960 KB Output is correct
107 Correct 35 ms 6776 KB Output is correct
108 Correct 44 ms 7900 KB Output is correct
109 Correct 5 ms 3960 KB Output is correct
110 Correct 63 ms 9080 KB Output is correct
111 Correct 68 ms 10484 KB Output is correct
112 Correct 5 ms 3960 KB Output is correct
113 Correct 89 ms 12536 KB Output is correct
114 Execution timed out 1083 ms 6264 KB Time limit exceeded
115 Halted 0 ms 0 KB -