답안 #151760

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
151760 2019-09-04T14:59:48 Z abacaba 꿈 (IOI13_dreaming) C++14
47 / 100
278 ms 28396 KB
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iostream>
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <random>
#include <string>
#include <cstring>
#include "dreaming.h"
#include <set>
#include <vector>
#include <map>
#include <time.h>
using namespace __gnu_pbds;
using namespace std;
 
typedef tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>
 
const int inf = 2e9;
const int N = 2e5 + 15;
int n, m, l, maxdiam, sz[N], d[N], center[N], deg[N], p[N];
vector <pii> g[N];
set <int> c, comp;
vector <int> f[N];
bool used[N];
set <pii> q;
 
int find(int v) {
	if(v == p[v])
		return v;
	return p[v] = find(p[v]);
}
 
void unio(int a, int b) {
	a = find(a);
	b = find(b);
	if(a != b) {
		if(sz[a] < sz[b])
			swap(a, b);
		p[b] = a;
		sz[a] += sz[b];
	}
}
 
void bfs(int componen) {
	used[componen] = true;
	int maxlevel = 0;
	for(auto i : f[componen])
		if(deg[i] == 1) {
			--deg[i];
			q.insert(mp(0, i));
		}
	while(!q.empty()) {
		int v = q.begin()->se;
		q.erase(q.begin());
		for(pii to : g[v]) {
			--deg[to.f];
			if(deg[to.f] > 0)
				d[to.f] = max(d[to.f], d[v] + to.se);
			if(deg[to.f] == 1) {
				maxlevel = max(maxlevel, d[to.f]);
				q.insert(mp(d[to.f], to.f));
			}
		}
	}
	for(int i : f[componen])
		if(d[i] == maxlevel) {
			c.insert(i);
			center[componen] = i;
		}
}
 
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)
		p[i] = i, sz[i] = 1;
    for(int i = 0; i < m; ++i) {
    	g[A[i]].pb(mp(B[i], T[i]));
    	g[B[i]].pb(mp(A[i], T[i]));
    	deg[A[i]]++, deg[B[i]]++;
    	unio(A[i], B[i]);
    }
    for(int i = 0; i < n; ++i) {
    	comp.insert(find(i));
    	f[find(i)].pb(i);
    }
    for(int i : comp)
    	if(!used[i])
	    	bfs(i);
    for(int i : c)
    	if(d[i] > d[maxdiam])
    		maxdiam = i;
    for(int i : comp) {
    	if(find(maxdiam) == i)
    		continue;
    	g[maxdiam].pb(mp(center[i], l));
    	g[center[i]].pb(mp(maxdiam, l));
    }
    for(int i = 1; i < n; ++i)
    	d[i] = inf;
    q.insert(mp(0, 0));
    int maxlevel = 0;
    while(!q.empty()) {
    	int v = q.begin()->se;
    	maxlevel = max(maxlevel, d[v]);
    	q.erase(q.begin());
    	for(pii to : g[v]) {
    		if(d[to.f] > d[v] + to.se) {
    			q.erase(mp(d[to.f], to.f));
    			d[to.f] = d[v] + to.se;
    			q.insert(mp(d[to.f], to.f));
    		}
    	}
    }
    for(int i = 0; i < n; ++i)
    	if(d[i] == maxlevel) {
    		q.insert(mp(0, i));
    		d[i] = 0;
    		for(int j = 0; j < n; ++j)
    			if(j != i)
    				d[j] = inf;
    		int maxx = 0;
    		while(!q.empty()) {
    			int v = q.begin()->se;
    			maxx = max(maxx, q.begin()->f);
    			q.erase(q.begin());
    			for(pii to : g[v]) {
    				if(d[to.f] > d[v] + to.se) {
    					q.erase(mp(d[to.f], to.f));
    					d[to.f] = d[v] + to.se;
    					q.insert(mp(d[to.f], to.f));
    				}
    			}
    		}
    		return maxx;
    	}
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:158:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 111 ms 16884 KB Output is correct
2 Correct 116 ms 16888 KB Output is correct
3 Correct 78 ms 14580 KB Output is correct
4 Correct 22 ms 10872 KB Output is correct
5 Correct 21 ms 10484 KB Output is correct
6 Correct 31 ms 11512 KB Output is correct
7 Correct 11 ms 9720 KB Output is correct
8 Correct 54 ms 12920 KB Output is correct
9 Correct 66 ms 13752 KB Output is correct
10 Correct 11 ms 9848 KB Output is correct
11 Correct 97 ms 15600 KB Output is correct
12 Correct 165 ms 16112 KB Output is correct
13 Correct 11 ms 9848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 111 ms 16884 KB Output is correct
2 Correct 116 ms 16888 KB Output is correct
3 Correct 78 ms 14580 KB Output is correct
4 Correct 22 ms 10872 KB Output is correct
5 Correct 21 ms 10484 KB Output is correct
6 Correct 31 ms 11512 KB Output is correct
7 Correct 11 ms 9720 KB Output is correct
8 Correct 54 ms 12920 KB Output is correct
9 Correct 66 ms 13752 KB Output is correct
10 Correct 11 ms 9848 KB Output is correct
11 Correct 97 ms 15600 KB Output is correct
12 Correct 165 ms 16112 KB Output is correct
13 Correct 11 ms 9848 KB Output is correct
14 Correct 11 ms 9848 KB Output is correct
15 Correct 11 ms 9720 KB Output is correct
16 Correct 13 ms 9720 KB Output is correct
17 Correct 13 ms 9724 KB Output is correct
18 Correct 12 ms 9720 KB Output is correct
19 Correct 11 ms 9720 KB Output is correct
20 Correct 11 ms 9720 KB Output is correct
21 Correct 11 ms 9848 KB Output is correct
22 Correct 11 ms 9720 KB Output is correct
23 Correct 11 ms 9720 KB Output is correct
24 Correct 11 ms 9720 KB Output is correct
25 Correct 11 ms 9816 KB Output is correct
26 Correct 11 ms 9820 KB Output is correct
27 Correct 11 ms 9848 KB Output is correct
28 Correct 11 ms 9720 KB Output is correct
29 Correct 11 ms 9804 KB Output is correct
30 Correct 11 ms 9848 KB Output is correct
31 Correct 11 ms 9848 KB Output is correct
32 Correct 11 ms 9720 KB Output is correct
33 Correct 13 ms 9720 KB Output is correct
34 Correct 11 ms 9848 KB Output is correct
35 Correct 11 ms 9848 KB Output is correct
36 Correct 13 ms 9716 KB Output is correct
37 Correct 11 ms 9720 KB Output is correct
38 Correct 11 ms 9720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 111 ms 16884 KB Output is correct
2 Correct 116 ms 16888 KB Output is correct
3 Correct 78 ms 14580 KB Output is correct
4 Correct 22 ms 10872 KB Output is correct
5 Correct 21 ms 10484 KB Output is correct
6 Correct 31 ms 11512 KB Output is correct
7 Correct 11 ms 9720 KB Output is correct
8 Correct 54 ms 12920 KB Output is correct
9 Correct 66 ms 13752 KB Output is correct
10 Correct 11 ms 9848 KB Output is correct
11 Correct 97 ms 15600 KB Output is correct
12 Correct 165 ms 16112 KB Output is correct
13 Correct 11 ms 9848 KB Output is correct
14 Correct 11 ms 9848 KB Output is correct
15 Correct 11 ms 9720 KB Output is correct
16 Correct 13 ms 9720 KB Output is correct
17 Correct 13 ms 9724 KB Output is correct
18 Correct 12 ms 9720 KB Output is correct
19 Correct 11 ms 9720 KB Output is correct
20 Correct 11 ms 9720 KB Output is correct
21 Correct 11 ms 9848 KB Output is correct
22 Correct 11 ms 9720 KB Output is correct
23 Correct 11 ms 9720 KB Output is correct
24 Correct 11 ms 9720 KB Output is correct
25 Correct 11 ms 9816 KB Output is correct
26 Correct 11 ms 9820 KB Output is correct
27 Correct 11 ms 9848 KB Output is correct
28 Correct 11 ms 9720 KB Output is correct
29 Correct 11 ms 9804 KB Output is correct
30 Correct 11 ms 9848 KB Output is correct
31 Correct 11 ms 9848 KB Output is correct
32 Correct 11 ms 9720 KB Output is correct
33 Correct 13 ms 9720 KB Output is correct
34 Correct 11 ms 9848 KB Output is correct
35 Correct 11 ms 9848 KB Output is correct
36 Correct 13 ms 9716 KB Output is correct
37 Correct 11 ms 9720 KB Output is correct
38 Correct 11 ms 9720 KB Output is correct
39 Correct 112 ms 16992 KB Output is correct
40 Correct 109 ms 16872 KB Output is correct
41 Correct 72 ms 14580 KB Output is correct
42 Correct 22 ms 10908 KB Output is correct
43 Correct 11 ms 9724 KB Output is correct
44 Correct 11 ms 9848 KB Output is correct
45 Correct 11 ms 9876 KB Output is correct
46 Correct 11 ms 9720 KB Output is correct
47 Correct 11 ms 9848 KB Output is correct
48 Correct 11 ms 9720 KB Output is correct
49 Correct 11 ms 9848 KB Output is correct
50 Correct 11 ms 9848 KB Output is correct
51 Correct 11 ms 9720 KB Output is correct
52 Correct 11 ms 9848 KB Output is correct
53 Correct 8 ms 9848 KB Output is correct
54 Correct 11 ms 9720 KB Output is correct
55 Correct 11 ms 9848 KB Output is correct
56 Correct 11 ms 9720 KB Output is correct
57 Correct 278 ms 19516 KB Output is correct
58 Correct 240 ms 18996 KB Output is correct
59 Correct 216 ms 19568 KB Output is correct
60 Correct 202 ms 18952 KB Output is correct
61 Correct 226 ms 20024 KB Output is correct
62 Correct 248 ms 19672 KB Output is correct
63 Correct 249 ms 19956 KB Output is correct
64 Correct 248 ms 19956 KB Output is correct
65 Correct 254 ms 20340 KB Output is correct
66 Correct 252 ms 20216 KB Output is correct
67 Correct 213 ms 19440 KB Output is correct
68 Correct 260 ms 19440 KB Output is correct
69 Correct 256 ms 19444 KB Output is correct
70 Correct 262 ms 19316 KB Output is correct
71 Correct 13 ms 9720 KB Output is correct
72 Correct 15 ms 9976 KB Output is correct
73 Correct 17 ms 10104 KB Output is correct
74 Correct 24 ms 10108 KB Output is correct
75 Correct 15 ms 10104 KB Output is correct
76 Correct 15 ms 10104 KB Output is correct
77 Correct 15 ms 9976 KB Output is correct
78 Correct 15 ms 9976 KB Output is correct
79 Correct 14 ms 9980 KB Output is correct
80 Correct 223 ms 19156 KB Output is correct
81 Correct 231 ms 19308 KB Output is correct
82 Correct 234 ms 20020 KB Output is correct
83 Correct 232 ms 20320 KB Output is correct
84 Correct 14 ms 10168 KB Output is correct
85 Correct 13 ms 9976 KB Output is correct
86 Correct 14 ms 10040 KB Output is correct
87 Correct 14 ms 9976 KB Output is correct
88 Correct 15 ms 10104 KB Output is correct
89 Correct 14 ms 9976 KB Output is correct
90 Correct 14 ms 9976 KB Output is correct
91 Correct 15 ms 9976 KB Output is correct
92 Correct 14 ms 9976 KB Output is correct
93 Correct 14 ms 9976 KB Output is correct
94 Correct 11 ms 9720 KB Output is correct
95 Correct 11 ms 9720 KB Output is correct
96 Correct 11 ms 9848 KB Output is correct
97 Correct 11 ms 9720 KB Output is correct
98 Correct 11 ms 9720 KB Output is correct
99 Correct 11 ms 9720 KB Output is correct
100 Correct 11 ms 9720 KB Output is correct
101 Correct 11 ms 9804 KB Output is correct
102 Correct 6 ms 9720 KB Output is correct
103 Correct 11 ms 9720 KB Output is correct
104 Correct 21 ms 10488 KB Output is correct
105 Correct 31 ms 11512 KB Output is correct
106 Correct 11 ms 9720 KB Output is correct
107 Correct 51 ms 13048 KB Output is correct
108 Correct 68 ms 13752 KB Output is correct
109 Correct 11 ms 9848 KB Output is correct
110 Correct 110 ms 15500 KB Output is correct
111 Correct 119 ms 15956 KB Output is correct
112 Correct 12 ms 9848 KB Output is correct
113 Correct 172 ms 17908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 262 ms 28396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 111 ms 16884 KB Output is correct
2 Correct 116 ms 16888 KB Output is correct
3 Correct 78 ms 14580 KB Output is correct
4 Correct 22 ms 10872 KB Output is correct
5 Correct 21 ms 10484 KB Output is correct
6 Correct 31 ms 11512 KB Output is correct
7 Correct 11 ms 9720 KB Output is correct
8 Correct 54 ms 12920 KB Output is correct
9 Correct 66 ms 13752 KB Output is correct
10 Correct 11 ms 9848 KB Output is correct
11 Correct 97 ms 15600 KB Output is correct
12 Correct 165 ms 16112 KB Output is correct
13 Correct 11 ms 9848 KB Output is correct
14 Correct 15 ms 9976 KB Output is correct
15 Correct 14 ms 9976 KB Output is correct
16 Correct 17 ms 10232 KB Output is correct
17 Correct 15 ms 9852 KB Output is correct
18 Correct 13 ms 9976 KB Output is correct
19 Correct 15 ms 10260 KB Output is correct
20 Correct 12 ms 9848 KB Output is correct
21 Correct 14 ms 9976 KB Output is correct
22 Correct 15 ms 10232 KB Output is correct
23 Correct 11 ms 9720 KB Output is correct
24 Correct 11 ms 9720 KB Output is correct
25 Correct 11 ms 9848 KB Output is correct
26 Correct 11 ms 9720 KB Output is correct
27 Correct 11 ms 9848 KB Output is correct
28 Incorrect 11 ms 9720 KB Output isn't correct
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 111 ms 16884 KB Output is correct
2 Correct 116 ms 16888 KB Output is correct
3 Correct 78 ms 14580 KB Output is correct
4 Correct 22 ms 10872 KB Output is correct
5 Correct 21 ms 10484 KB Output is correct
6 Correct 31 ms 11512 KB Output is correct
7 Correct 11 ms 9720 KB Output is correct
8 Correct 54 ms 12920 KB Output is correct
9 Correct 66 ms 13752 KB Output is correct
10 Correct 11 ms 9848 KB Output is correct
11 Correct 97 ms 15600 KB Output is correct
12 Correct 165 ms 16112 KB Output is correct
13 Correct 11 ms 9848 KB Output is correct
14 Correct 11 ms 9848 KB Output is correct
15 Correct 11 ms 9720 KB Output is correct
16 Correct 13 ms 9720 KB Output is correct
17 Correct 13 ms 9724 KB Output is correct
18 Correct 12 ms 9720 KB Output is correct
19 Correct 11 ms 9720 KB Output is correct
20 Correct 11 ms 9720 KB Output is correct
21 Correct 11 ms 9848 KB Output is correct
22 Correct 11 ms 9720 KB Output is correct
23 Correct 11 ms 9720 KB Output is correct
24 Correct 11 ms 9720 KB Output is correct
25 Correct 11 ms 9816 KB Output is correct
26 Correct 11 ms 9820 KB Output is correct
27 Correct 11 ms 9848 KB Output is correct
28 Correct 11 ms 9720 KB Output is correct
29 Correct 11 ms 9804 KB Output is correct
30 Correct 11 ms 9848 KB Output is correct
31 Correct 11 ms 9848 KB Output is correct
32 Correct 11 ms 9720 KB Output is correct
33 Correct 13 ms 9720 KB Output is correct
34 Correct 11 ms 9848 KB Output is correct
35 Correct 11 ms 9848 KB Output is correct
36 Correct 13 ms 9716 KB Output is correct
37 Correct 11 ms 9720 KB Output is correct
38 Correct 11 ms 9720 KB Output is correct
39 Correct 112 ms 16992 KB Output is correct
40 Correct 109 ms 16872 KB Output is correct
41 Correct 72 ms 14580 KB Output is correct
42 Correct 22 ms 10908 KB Output is correct
43 Correct 11 ms 9724 KB Output is correct
44 Correct 11 ms 9848 KB Output is correct
45 Correct 11 ms 9876 KB Output is correct
46 Correct 11 ms 9720 KB Output is correct
47 Correct 11 ms 9848 KB Output is correct
48 Correct 11 ms 9720 KB Output is correct
49 Correct 11 ms 9848 KB Output is correct
50 Correct 11 ms 9848 KB Output is correct
51 Correct 11 ms 9720 KB Output is correct
52 Correct 11 ms 9848 KB Output is correct
53 Correct 8 ms 9848 KB Output is correct
54 Correct 11 ms 9720 KB Output is correct
55 Correct 11 ms 9848 KB Output is correct
56 Correct 11 ms 9720 KB Output is correct
57 Correct 278 ms 19516 KB Output is correct
58 Correct 240 ms 18996 KB Output is correct
59 Correct 216 ms 19568 KB Output is correct
60 Correct 202 ms 18952 KB Output is correct
61 Correct 226 ms 20024 KB Output is correct
62 Correct 248 ms 19672 KB Output is correct
63 Correct 249 ms 19956 KB Output is correct
64 Correct 248 ms 19956 KB Output is correct
65 Correct 254 ms 20340 KB Output is correct
66 Correct 252 ms 20216 KB Output is correct
67 Correct 213 ms 19440 KB Output is correct
68 Correct 260 ms 19440 KB Output is correct
69 Correct 256 ms 19444 KB Output is correct
70 Correct 262 ms 19316 KB Output is correct
71 Correct 13 ms 9720 KB Output is correct
72 Correct 15 ms 9976 KB Output is correct
73 Correct 17 ms 10104 KB Output is correct
74 Correct 24 ms 10108 KB Output is correct
75 Correct 15 ms 10104 KB Output is correct
76 Correct 15 ms 10104 KB Output is correct
77 Correct 15 ms 9976 KB Output is correct
78 Correct 15 ms 9976 KB Output is correct
79 Correct 14 ms 9980 KB Output is correct
80 Correct 223 ms 19156 KB Output is correct
81 Correct 231 ms 19308 KB Output is correct
82 Correct 234 ms 20020 KB Output is correct
83 Correct 232 ms 20320 KB Output is correct
84 Correct 14 ms 10168 KB Output is correct
85 Correct 13 ms 9976 KB Output is correct
86 Correct 14 ms 10040 KB Output is correct
87 Correct 14 ms 9976 KB Output is correct
88 Correct 15 ms 10104 KB Output is correct
89 Correct 14 ms 9976 KB Output is correct
90 Correct 14 ms 9976 KB Output is correct
91 Correct 15 ms 9976 KB Output is correct
92 Correct 14 ms 9976 KB Output is correct
93 Correct 14 ms 9976 KB Output is correct
94 Correct 11 ms 9720 KB Output is correct
95 Correct 11 ms 9720 KB Output is correct
96 Correct 11 ms 9848 KB Output is correct
97 Correct 11 ms 9720 KB Output is correct
98 Correct 11 ms 9720 KB Output is correct
99 Correct 11 ms 9720 KB Output is correct
100 Correct 11 ms 9720 KB Output is correct
101 Correct 11 ms 9804 KB Output is correct
102 Correct 6 ms 9720 KB Output is correct
103 Correct 11 ms 9720 KB Output is correct
104 Correct 21 ms 10488 KB Output is correct
105 Correct 31 ms 11512 KB Output is correct
106 Correct 11 ms 9720 KB Output is correct
107 Correct 51 ms 13048 KB Output is correct
108 Correct 68 ms 13752 KB Output is correct
109 Correct 11 ms 9848 KB Output is correct
110 Correct 110 ms 15500 KB Output is correct
111 Correct 119 ms 15956 KB Output is correct
112 Correct 12 ms 9848 KB Output is correct
113 Correct 172 ms 17908 KB Output is correct
114 Incorrect 262 ms 28396 KB Output isn't correct
115 Halted 0 ms 0 KB -