Submission #588040

# Submission time Handle Problem Language Result Execution time Memory
588040 2022-07-02T16:29:02 Z MrDeboo Dreaming (IOI13_dreaming) C++17
59 / 100
1000 ms 42780 KB
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
vector<pair<int,int>>vct[100000];
vector<pair<int,int>>vec[100000];
vector<pair<int,int>>voc[100000];
map<int,int>mp[100000];
int fath[100000];
int val[100000];
int n,m,l,f,ans;
int diam(int in){
	deque<pair<int,int>>dq={{in,0}};
	map<int,bool>vis;
	vis[in]=1;
	int x=0,y=0;
	while(dq.size()){
		int a=dq.front().first,b=dq.front().second;
		dq.pop_front();
		if(b>=y){
			x=a;
			y=b;
		}
		for(auto &i:vct[a]){
			if(!vis[i.first]){
				vis[i.first]=1;
				dq.push_back({i.first,b+i.second});
			}
		}
	}
	dq.push_back({x,0});
	x=0;y=0;
	vis.clear();
    vis[dq.back().first]=1;
	while(dq.size()){
		int a=dq.front().first,b=dq.front().second;
		dq.pop_front();
		if(b>=y){
			x=a;
			y=b;
		}
		for(auto &i:vct[a]){
            if(!vis[i.first]){
				vis[i.first]=1;
				dq.push_back({i.first,b+i.second});
			}
		}
	}
	return y;
}
int dfs1(int in){
	for(auto &i:vec[in]){
        int g=dfs1(i.first)+i.second;
        val[in]=max(val[in],g);
        voc[in].push_back({g,i.first});
    }
    sort(voc[in].begin(),voc[in].end());
    return val[in];
}
void dfs2(int in,int x){
    if(fath[in]!=-1){
        int k=voc[fath[in]].size()-1;
        if(voc[fath[in]][k].second==in)k--;
        x=max(x,voc[fath[in]][k].first+mp[fath[in]][in]);
    }
	f=min(f,max(x,val[in]));
	for(auto &i:vec[in])dfs2(i.first,x+i.second);
}
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<n;i++)voc[i].push_back({0,-1});
    for(int i=0;i<n;i++)fath[i]=-1;
    for(int i=0;i<m;i++){
        vct[a[i]].push_back({b[i],t[i]});
        vct[b[i]].push_back({a[i],t[i]});
    }
    vector<int>vis(n);
    deque<int>v;
    for(int i=0;i<n;i++){
        if(vis[i])continue;
        vis[i]=1;
        vector<int>vc={i};
        {
            deque<int>dq={i};
            while(dq.size()){
                int a=dq.front();
                dq.pop_front();
                for(auto &w:vct[a]){
                    if(!vis[w.first]){
                        vis[w.first]=1;
						vec[a].push_back(w);
						fath[w.first]=a;
                        mp[a][w.first]=w.second;
                        dq.push_back(w.first);
                        vc.push_back(w.first);
                    }
                }
            }
        }
        f=INT_MAX;
		ans=max(ans,diam(i));
		if(vc.size()==1)f=0;
		else{
			dfs1(i);
            dfs2(i,0);
		}
        v.push_back(f);
    }
    sort(v.begin(),v.end());
    while(v.size()>1){
        sort(v.begin(),v.end());
        ans=max(ans,v.back()+v[0]+l);
        v.back()=max(v.back(),v[0]+l);
        v.pop_front();
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 223 ms 35524 KB Output is correct
2 Correct 257 ms 35284 KB Output is correct
3 Correct 135 ms 28912 KB Output is correct
4 Correct 27 ms 15408 KB Output is correct
5 Correct 20 ms 14068 KB Output is correct
6 Correct 41 ms 17132 KB Output is correct
7 Correct 7 ms 12116 KB Output is correct
8 Correct 85 ms 21364 KB Output is correct
9 Correct 124 ms 24548 KB Output is correct
10 Correct 6 ms 12116 KB Output is correct
11 Correct 157 ms 27276 KB Output is correct
12 Correct 202 ms 31060 KB Output is correct
13 Correct 7 ms 12244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12056 KB Output is correct
2 Correct 6 ms 11988 KB Output is correct
3 Correct 7 ms 11988 KB Output is correct
4 Correct 7 ms 11988 KB Output is correct
5 Correct 7 ms 12036 KB Output is correct
6 Correct 6 ms 11988 KB Output is correct
7 Correct 6 ms 12032 KB Output is correct
8 Correct 6 ms 11988 KB Output is correct
9 Correct 7 ms 12052 KB Output is correct
10 Correct 7 ms 12116 KB Output is correct
11 Correct 6 ms 11988 KB Output is correct
12 Correct 7 ms 12048 KB Output is correct
13 Correct 7 ms 11988 KB Output is correct
14 Correct 6 ms 12052 KB Output is correct
15 Correct 6 ms 12048 KB Output is correct
16 Correct 6 ms 11988 KB Output is correct
17 Correct 6 ms 12052 KB Output is correct
18 Correct 7 ms 12056 KB Output is correct
19 Correct 8 ms 12088 KB Output is correct
20 Correct 8 ms 12004 KB Output is correct
21 Correct 7 ms 11988 KB Output is correct
22 Correct 7 ms 11988 KB Output is correct
23 Correct 7 ms 11988 KB Output is correct
24 Correct 7 ms 12040 KB Output is correct
25 Correct 6 ms 12048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 223 ms 35524 KB Output is correct
2 Correct 257 ms 35284 KB Output is correct
3 Correct 135 ms 28912 KB Output is correct
4 Correct 27 ms 15408 KB Output is correct
5 Correct 20 ms 14068 KB Output is correct
6 Correct 41 ms 17132 KB Output is correct
7 Correct 7 ms 12116 KB Output is correct
8 Correct 85 ms 21364 KB Output is correct
9 Correct 124 ms 24548 KB Output is correct
10 Correct 6 ms 12116 KB Output is correct
11 Correct 157 ms 27276 KB Output is correct
12 Correct 202 ms 31060 KB Output is correct
13 Correct 7 ms 12244 KB Output is correct
14 Correct 8 ms 12056 KB Output is correct
15 Correct 6 ms 11988 KB Output is correct
16 Correct 7 ms 11988 KB Output is correct
17 Correct 7 ms 11988 KB Output is correct
18 Correct 7 ms 12036 KB Output is correct
19 Correct 6 ms 11988 KB Output is correct
20 Correct 6 ms 12032 KB Output is correct
21 Correct 6 ms 11988 KB Output is correct
22 Correct 7 ms 12052 KB Output is correct
23 Correct 7 ms 12116 KB Output is correct
24 Correct 6 ms 11988 KB Output is correct
25 Correct 7 ms 12048 KB Output is correct
26 Correct 7 ms 11988 KB Output is correct
27 Correct 6 ms 12052 KB Output is correct
28 Correct 6 ms 12048 KB Output is correct
29 Correct 6 ms 11988 KB Output is correct
30 Correct 6 ms 12052 KB Output is correct
31 Correct 7 ms 12056 KB Output is correct
32 Correct 8 ms 12088 KB Output is correct
33 Correct 8 ms 12004 KB Output is correct
34 Correct 7 ms 11988 KB Output is correct
35 Correct 7 ms 11988 KB Output is correct
36 Correct 7 ms 11988 KB Output is correct
37 Correct 7 ms 12040 KB Output is correct
38 Correct 6 ms 12048 KB Output is correct
39 Correct 223 ms 36792 KB Output is correct
40 Correct 281 ms 36432 KB Output is correct
41 Correct 125 ms 29876 KB Output is correct
42 Correct 26 ms 15604 KB Output is correct
43 Correct 7 ms 12052 KB Output is correct
44 Correct 7 ms 11988 KB Output is correct
45 Correct 6 ms 11988 KB Output is correct
46 Correct 7 ms 11984 KB Output is correct
47 Correct 6 ms 11988 KB Output is correct
48 Correct 7 ms 11988 KB Output is correct
49 Correct 7 ms 11988 KB Output is correct
50 Correct 7 ms 11988 KB Output is correct
51 Correct 7 ms 12008 KB Output is correct
52 Correct 7 ms 11988 KB Output is correct
53 Correct 7 ms 12048 KB Output is correct
54 Correct 6 ms 12052 KB Output is correct
55 Correct 6 ms 12052 KB Output is correct
56 Correct 6 ms 11988 KB Output is correct
57 Correct 273 ms 33804 KB Output is correct
58 Correct 297 ms 32032 KB Output is correct
59 Correct 299 ms 32908 KB Output is correct
60 Correct 295 ms 32108 KB Output is correct
61 Correct 294 ms 33020 KB Output is correct
62 Correct 247 ms 33032 KB Output is correct
63 Correct 284 ms 34456 KB Output is correct
64 Correct 295 ms 34432 KB Output is correct
65 Correct 268 ms 34628 KB Output is correct
66 Correct 313 ms 34648 KB Output is correct
67 Correct 278 ms 33240 KB Output is correct
68 Correct 293 ms 33040 KB Output is correct
69 Correct 264 ms 32804 KB Output is correct
70 Correct 252 ms 32088 KB Output is correct
71 Correct 6 ms 11988 KB Output is correct
72 Correct 12 ms 12616 KB Output is correct
73 Correct 12 ms 12628 KB Output is correct
74 Correct 10 ms 12704 KB Output is correct
75 Correct 10 ms 12628 KB Output is correct
76 Correct 10 ms 12576 KB Output is correct
77 Correct 10 ms 12628 KB Output is correct
78 Correct 10 ms 12572 KB Output is correct
79 Correct 10 ms 12620 KB Output is correct
80 Correct 268 ms 33012 KB Output is correct
81 Correct 275 ms 31264 KB Output is correct
82 Correct 248 ms 32956 KB Output is correct
83 Correct 272 ms 34240 KB Output is correct
84 Correct 9 ms 12500 KB Output is correct
85 Correct 8 ms 12372 KB Output is correct
86 Correct 9 ms 12448 KB Output is correct
87 Correct 10 ms 12504 KB Output is correct
88 Correct 12 ms 12596 KB Output is correct
89 Correct 12 ms 12476 KB Output is correct
90 Correct 11 ms 12500 KB Output is correct
91 Correct 14 ms 12628 KB Output is correct
92 Correct 12 ms 12500 KB Output is correct
93 Correct 11 ms 12500 KB Output is correct
94 Correct 7 ms 11988 KB Output is correct
95 Correct 6 ms 11988 KB Output is correct
96 Correct 7 ms 12052 KB Output is correct
97 Correct 7 ms 12172 KB Output is correct
98 Correct 7 ms 11988 KB Output is correct
99 Correct 6 ms 11988 KB Output is correct
100 Correct 7 ms 12008 KB Output is correct
101 Correct 7 ms 11988 KB Output is correct
102 Correct 7 ms 12004 KB Output is correct
103 Correct 6 ms 12004 KB Output is correct
104 Correct 23 ms 14288 KB Output is correct
105 Correct 42 ms 17472 KB Output is correct
106 Correct 7 ms 12076 KB Output is correct
107 Correct 80 ms 21848 KB Output is correct
108 Correct 130 ms 25244 KB Output is correct
109 Correct 7 ms 12180 KB Output is correct
110 Correct 176 ms 28372 KB Output is correct
111 Correct 197 ms 32124 KB Output is correct
112 Correct 7 ms 12244 KB Output is correct
113 Correct 327 ms 42780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1090 ms 21084 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12056 KB Output is correct
2 Correct 6 ms 11988 KB Output is correct
3 Correct 7 ms 11988 KB Output is correct
4 Correct 7 ms 11988 KB Output is correct
5 Correct 7 ms 12036 KB Output is correct
6 Correct 6 ms 11988 KB Output is correct
7 Correct 6 ms 12032 KB Output is correct
8 Correct 6 ms 11988 KB Output is correct
9 Correct 7 ms 12052 KB Output is correct
10 Correct 7 ms 12116 KB Output is correct
11 Correct 6 ms 11988 KB Output is correct
12 Correct 7 ms 12048 KB Output is correct
13 Correct 7 ms 11988 KB Output is correct
14 Correct 6 ms 12052 KB Output is correct
15 Correct 6 ms 12048 KB Output is correct
16 Correct 6 ms 11988 KB Output is correct
17 Correct 6 ms 12052 KB Output is correct
18 Correct 7 ms 12056 KB Output is correct
19 Correct 8 ms 12088 KB Output is correct
20 Correct 8 ms 12004 KB Output is correct
21 Correct 7 ms 11988 KB Output is correct
22 Correct 7 ms 11988 KB Output is correct
23 Correct 7 ms 11988 KB Output is correct
24 Correct 7 ms 12040 KB Output is correct
25 Correct 6 ms 12048 KB Output is correct
26 Correct 7 ms 12176 KB Output is correct
27 Correct 8 ms 12320 KB Output is correct
28 Correct 10 ms 12500 KB Output is correct
29 Correct 8 ms 12184 KB Output is correct
30 Correct 9 ms 12316 KB Output is correct
31 Correct 11 ms 12540 KB Output is correct
32 Correct 7 ms 12116 KB Output is correct
33 Correct 9 ms 12324 KB Output is correct
34 Correct 12 ms 12448 KB Output is correct
35 Correct 9 ms 11988 KB Output is correct
36 Correct 7 ms 12052 KB Output is correct
37 Correct 6 ms 11988 KB Output is correct
38 Correct 7 ms 11988 KB Output is correct
39 Correct 7 ms 11988 KB Output is correct
40 Correct 6 ms 11988 KB Output is correct
41 Correct 6 ms 12056 KB Output is correct
42 Correct 6 ms 11988 KB Output is correct
43 Correct 7 ms 11988 KB Output is correct
44 Correct 6 ms 11988 KB Output is correct
45 Correct 6 ms 12060 KB Output is correct
46 Correct 6 ms 12004 KB Output is correct
47 Correct 6 ms 11988 KB Output is correct
48 Correct 7 ms 11988 KB Output is correct
49 Correct 6 ms 11988 KB Output is correct
50 Correct 6 ms 11988 KB Output is correct
51 Correct 6 ms 11988 KB Output is correct
52 Correct 6 ms 12052 KB Output is correct
53 Correct 6 ms 11988 KB Output is correct
54 Correct 10 ms 12832 KB Output is correct
55 Correct 10 ms 12856 KB Output is correct
56 Correct 21 ms 12420 KB Output is correct
57 Correct 61 ms 12272 KB Output is correct
58 Correct 13 ms 12628 KB Output is correct
59 Correct 12 ms 12672 KB Output is correct
60 Correct 31 ms 12388 KB Output is correct
61 Correct 42 ms 12252 KB Output is correct
62 Correct 11 ms 12628 KB Output is correct
63 Correct 11 ms 12572 KB Output is correct
64 Correct 63 ms 12180 KB Output is correct
65 Correct 19 ms 12372 KB Output is correct
66 Correct 10 ms 12708 KB Output is correct
67 Correct 10 ms 12628 KB Output is correct
68 Correct 17 ms 12472 KB Output is correct
69 Correct 15 ms 12480 KB Output is correct
70 Correct 43 ms 12340 KB Output is correct
71 Correct 35 ms 12340 KB Output is correct
72 Correct 10 ms 12628 KB Output is correct
73 Correct 10 ms 12576 KB Output is correct
74 Correct 9 ms 12500 KB Output is correct
75 Correct 11 ms 12488 KB Output is correct
76 Correct 10 ms 12572 KB Output is correct
77 Correct 10 ms 12576 KB Output is correct
78 Correct 43 ms 12244 KB Output is correct
79 Correct 37 ms 12364 KB Output is correct
80 Correct 63 ms 12116 KB Output is correct
81 Correct 72 ms 12192 KB Output is correct
82 Correct 10 ms 12500 KB Output is correct
83 Correct 10 ms 12500 KB Output is correct
84 Correct 33 ms 12348 KB Output is correct
85 Correct 66 ms 12220 KB Output is correct
86 Correct 17 ms 12500 KB Output is correct
87 Correct 13 ms 12692 KB Output is correct
88 Correct 19 ms 12460 KB Output is correct
89 Correct 20 ms 12372 KB Output is correct
90 Correct 34 ms 12372 KB Output is correct
91 Correct 38 ms 12244 KB Output is correct
92 Correct 9 ms 12500 KB Output is correct
93 Correct 8 ms 12372 KB Output is correct
94 Correct 9 ms 12500 KB Output is correct
95 Correct 10 ms 12500 KB Output is correct
96 Correct 10 ms 12500 KB Output is correct
97 Correct 10 ms 12500 KB Output is correct
98 Correct 10 ms 12500 KB Output is correct
99 Correct 11 ms 12660 KB Output is correct
100 Correct 10 ms 12500 KB Output is correct
101 Correct 10 ms 12500 KB Output is correct
102 Correct 6 ms 11988 KB Output is correct
103 Correct 6 ms 12052 KB Output is correct
104 Correct 6 ms 11988 KB Output is correct
105 Correct 6 ms 12052 KB Output is correct
106 Correct 6 ms 12048 KB Output is correct
107 Correct 8 ms 12056 KB Output is correct
108 Correct 6 ms 11988 KB Output is correct
109 Correct 7 ms 12056 KB Output is correct
110 Correct 6 ms 11988 KB Output is correct
111 Correct 6 ms 11988 KB Output is correct
112 Correct 7 ms 12052 KB Output is correct
113 Correct 7 ms 12180 KB Output is correct
114 Correct 7 ms 12244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 223 ms 35524 KB Output is correct
2 Correct 257 ms 35284 KB Output is correct
3 Correct 135 ms 28912 KB Output is correct
4 Correct 27 ms 15408 KB Output is correct
5 Correct 20 ms 14068 KB Output is correct
6 Correct 41 ms 17132 KB Output is correct
7 Correct 7 ms 12116 KB Output is correct
8 Correct 85 ms 21364 KB Output is correct
9 Correct 124 ms 24548 KB Output is correct
10 Correct 6 ms 12116 KB Output is correct
11 Correct 157 ms 27276 KB Output is correct
12 Correct 202 ms 31060 KB Output is correct
13 Correct 7 ms 12244 KB Output is correct
14 Correct 8 ms 12056 KB Output is correct
15 Correct 6 ms 11988 KB Output is correct
16 Correct 7 ms 11988 KB Output is correct
17 Correct 7 ms 11988 KB Output is correct
18 Correct 7 ms 12036 KB Output is correct
19 Correct 6 ms 11988 KB Output is correct
20 Correct 6 ms 12032 KB Output is correct
21 Correct 6 ms 11988 KB Output is correct
22 Correct 7 ms 12052 KB Output is correct
23 Correct 7 ms 12116 KB Output is correct
24 Correct 6 ms 11988 KB Output is correct
25 Correct 7 ms 12048 KB Output is correct
26 Correct 7 ms 11988 KB Output is correct
27 Correct 6 ms 12052 KB Output is correct
28 Correct 6 ms 12048 KB Output is correct
29 Correct 6 ms 11988 KB Output is correct
30 Correct 6 ms 12052 KB Output is correct
31 Correct 7 ms 12056 KB Output is correct
32 Correct 8 ms 12088 KB Output is correct
33 Correct 8 ms 12004 KB Output is correct
34 Correct 7 ms 11988 KB Output is correct
35 Correct 7 ms 11988 KB Output is correct
36 Correct 7 ms 11988 KB Output is correct
37 Correct 7 ms 12040 KB Output is correct
38 Correct 6 ms 12048 KB Output is correct
39 Correct 223 ms 36792 KB Output is correct
40 Correct 281 ms 36432 KB Output is correct
41 Correct 125 ms 29876 KB Output is correct
42 Correct 26 ms 15604 KB Output is correct
43 Correct 7 ms 12052 KB Output is correct
44 Correct 7 ms 11988 KB Output is correct
45 Correct 6 ms 11988 KB Output is correct
46 Correct 7 ms 11984 KB Output is correct
47 Correct 6 ms 11988 KB Output is correct
48 Correct 7 ms 11988 KB Output is correct
49 Correct 7 ms 11988 KB Output is correct
50 Correct 7 ms 11988 KB Output is correct
51 Correct 7 ms 12008 KB Output is correct
52 Correct 7 ms 11988 KB Output is correct
53 Correct 7 ms 12048 KB Output is correct
54 Correct 6 ms 12052 KB Output is correct
55 Correct 6 ms 12052 KB Output is correct
56 Correct 6 ms 11988 KB Output is correct
57 Correct 273 ms 33804 KB Output is correct
58 Correct 297 ms 32032 KB Output is correct
59 Correct 299 ms 32908 KB Output is correct
60 Correct 295 ms 32108 KB Output is correct
61 Correct 294 ms 33020 KB Output is correct
62 Correct 247 ms 33032 KB Output is correct
63 Correct 284 ms 34456 KB Output is correct
64 Correct 295 ms 34432 KB Output is correct
65 Correct 268 ms 34628 KB Output is correct
66 Correct 313 ms 34648 KB Output is correct
67 Correct 278 ms 33240 KB Output is correct
68 Correct 293 ms 33040 KB Output is correct
69 Correct 264 ms 32804 KB Output is correct
70 Correct 252 ms 32088 KB Output is correct
71 Correct 6 ms 11988 KB Output is correct
72 Correct 12 ms 12616 KB Output is correct
73 Correct 12 ms 12628 KB Output is correct
74 Correct 10 ms 12704 KB Output is correct
75 Correct 10 ms 12628 KB Output is correct
76 Correct 10 ms 12576 KB Output is correct
77 Correct 10 ms 12628 KB Output is correct
78 Correct 10 ms 12572 KB Output is correct
79 Correct 10 ms 12620 KB Output is correct
80 Correct 268 ms 33012 KB Output is correct
81 Correct 275 ms 31264 KB Output is correct
82 Correct 248 ms 32956 KB Output is correct
83 Correct 272 ms 34240 KB Output is correct
84 Correct 9 ms 12500 KB Output is correct
85 Correct 8 ms 12372 KB Output is correct
86 Correct 9 ms 12448 KB Output is correct
87 Correct 10 ms 12504 KB Output is correct
88 Correct 12 ms 12596 KB Output is correct
89 Correct 12 ms 12476 KB Output is correct
90 Correct 11 ms 12500 KB Output is correct
91 Correct 14 ms 12628 KB Output is correct
92 Correct 12 ms 12500 KB Output is correct
93 Correct 11 ms 12500 KB Output is correct
94 Correct 7 ms 11988 KB Output is correct
95 Correct 6 ms 11988 KB Output is correct
96 Correct 7 ms 12052 KB Output is correct
97 Correct 7 ms 12172 KB Output is correct
98 Correct 7 ms 11988 KB Output is correct
99 Correct 6 ms 11988 KB Output is correct
100 Correct 7 ms 12008 KB Output is correct
101 Correct 7 ms 11988 KB Output is correct
102 Correct 7 ms 12004 KB Output is correct
103 Correct 6 ms 12004 KB Output is correct
104 Correct 23 ms 14288 KB Output is correct
105 Correct 42 ms 17472 KB Output is correct
106 Correct 7 ms 12076 KB Output is correct
107 Correct 80 ms 21848 KB Output is correct
108 Correct 130 ms 25244 KB Output is correct
109 Correct 7 ms 12180 KB Output is correct
110 Correct 176 ms 28372 KB Output is correct
111 Correct 197 ms 32124 KB Output is correct
112 Correct 7 ms 12244 KB Output is correct
113 Correct 327 ms 42780 KB Output is correct
114 Execution timed out 1090 ms 21084 KB Time limit exceeded
115 Halted 0 ms 0 KB -