답안 #240518

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
240518 2020-06-19T19:32:31 Z c4ts0up 꿈 (IOI13_dreaming) C++14
47 / 100
196 ms 15608 KB
#include "dreaming.h"
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define ff first
#define ss second
using namespace std;

const ll INF = 1e10;
const ll NMAX = 1e5+5;

struct Vertex {
	int id, parent;
	ll pdist;

	Vertex () {}
	Vertex (int x) { id = x; }
};

struct Graph {
	vector <Vertex> V;
	vector <pair <ll, int> > Adj[NMAX];
	vector <bool> vis;
	int excluded = -1, sze;

	Graph () {}
	Graph (int s) {
        sze = s;
		V.resize(sze);
		for (int i=0; i<sze; i++) V[i] = Vertex(i);
	}

	// Hace una DFS y devuelve el nodo más lejano
	pair <ll,int> DFS(int o) {
	    ////cerr << "Entrando a DFS..." << endl;
		vector <ll> dist;
		stack <pair <int,int> > to;

		dist.resize(sze);
		vis.resize(sze);
		for (int i=0; i<sze; i++) dist[i] = INF, vis[i] = false;

		// Hace la DFS
		to.push({0LL, o});
		dist[o] = 0;
		while (!to.empty()) {
			pair <int, ll> curr = to.top();
			//cerr << "Visitando " << curr.ss << " (distancia acc " << curr.ff << ")" << endl;
			to.pop();
			dist[curr.ss] = curr.ff;
			vis[curr.ss] = true;

			for (pair <ll, int> p : Adj[curr.ss]) {
				if (!vis[p.ss]) to.push({p.ff + curr.ff, p.ss}), V[p.ss].parent = curr.ss, V[p.ss].pdist = p.ff;
			}
		}

		// Encuentra el más lejano
		pair <ll, int> best = {0, o};
		for (int i=0; i<sze; i++) {
			// No pertence a esta componente
			if (!vis[i]) {
				excluded = i;
				continue;
			}

			if (dist[i] != 0) best = max(best, {dist[i], i});
		}

		return best;
	}

	ll Diametro() {
		// Devuelve el diametro
		pair <ll, int> rx = DFS(0);
		pair <ll, int> ry = DFS(rx.ss);
		return ry.ff;
	}

	// Encuentra el radio. Devuele el centro
	int Radio(int o = 0) {
	    //cerr << "--- PRIMERA DFS ---" << endl;
		pair <ll, int> rx = DFS(o);
		//cerr << "(" << rx.ff << ", " << rx.ss << ")" << endl;
		//cerr << "El excluido es " << excluded << endl;
        //cerr << "--- SEGUNDA DFS ---" << endl;
		pair <ll, int> ry = DFS(rx.ss);
		//cerr << "(" << ry.ff << ", " << ry.ss << ")" << endl;

		int curr = ry.ss;
		int best = curr;
		ll a = ry.ff, b = 0;
		ll maxi = INF;

        ////cerr << "--- BUSCANDO RADIO ---" << endl;
		while (curr != rx.ss) {
            ////cerr << "Revisando " << curr << endl;
			if (max(a,b) < maxi) best = curr, maxi = max(a,b);

			a -= V[curr].pdist;
			b += V[curr].pdist;

			curr = V[curr].parent;
		}

		return best;
	}
};

Graph G;

int travelTime(int n, int m, int l, int A[], int B[], int T[]) {
	G = Graph(n);
	//cerr << "Creando grafo... OK" << endl;

	for (int i=0; i<m; i++) {
		G.Adj[A[i]].pb({T[i], B[i]});
		G.Adj[B[i]].pb({T[i], A[i]});
	}

	//cerr << "Llenando grafo... OK" << endl;

	int g1 = G.Radio();
	//cerr << "Primer centro " << g1 << endl;
	int g2 = G.Radio(G.excluded);
	//cerr << "Segundo centro " << g2 << endl;
	G.Adj[g2].pb({(ll)(l), g1});
	G.Adj[g1].pb({(ll)(l), g2});

	return G.Diametro();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 12636 KB Output is correct
2 Correct 82 ms 12592 KB Output is correct
3 Correct 50 ms 9976 KB Output is correct
4 Correct 16 ms 6272 KB Output is correct
5 Correct 15 ms 6016 KB Output is correct
6 Correct 29 ms 6912 KB Output is correct
7 Correct 8 ms 5120 KB Output is correct
8 Correct 42 ms 8696 KB Output is correct
9 Correct 54 ms 9472 KB Output is correct
10 Correct 8 ms 5120 KB Output is correct
11 Correct 91 ms 11128 KB Output is correct
12 Correct 98 ms 12036 KB Output is correct
13 Correct 8 ms 5120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 12636 KB Output is correct
2 Correct 82 ms 12592 KB Output is correct
3 Correct 50 ms 9976 KB Output is correct
4 Correct 16 ms 6272 KB Output is correct
5 Correct 15 ms 6016 KB Output is correct
6 Correct 29 ms 6912 KB Output is correct
7 Correct 8 ms 5120 KB Output is correct
8 Correct 42 ms 8696 KB Output is correct
9 Correct 54 ms 9472 KB Output is correct
10 Correct 8 ms 5120 KB Output is correct
11 Correct 91 ms 11128 KB Output is correct
12 Correct 98 ms 12036 KB Output is correct
13 Correct 8 ms 5120 KB Output is correct
14 Correct 8 ms 4992 KB Output is correct
15 Correct 9 ms 5120 KB Output is correct
16 Correct 8 ms 5120 KB Output is correct
17 Correct 8 ms 5248 KB Output is correct
18 Correct 8 ms 4992 KB Output is correct
19 Correct 8 ms 4992 KB Output is correct
20 Correct 8 ms 5120 KB Output is correct
21 Correct 8 ms 4992 KB Output is correct
22 Correct 9 ms 4992 KB Output is correct
23 Correct 7 ms 4992 KB Output is correct
24 Correct 7 ms 4992 KB Output is correct
25 Correct 8 ms 4992 KB Output is correct
26 Correct 8 ms 5120 KB Output is correct
27 Correct 8 ms 5120 KB Output is correct
28 Correct 7 ms 4992 KB Output is correct
29 Correct 8 ms 4992 KB Output is correct
30 Correct 8 ms 4992 KB Output is correct
31 Correct 8 ms 5044 KB Output is correct
32 Correct 8 ms 5120 KB Output is correct
33 Correct 7 ms 4992 KB Output is correct
34 Correct 8 ms 4992 KB Output is correct
35 Correct 8 ms 4992 KB Output is correct
36 Correct 8 ms 4992 KB Output is correct
37 Correct 7 ms 4992 KB Output is correct
38 Correct 7 ms 4992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 12636 KB Output is correct
2 Correct 82 ms 12592 KB Output is correct
3 Correct 50 ms 9976 KB Output is correct
4 Correct 16 ms 6272 KB Output is correct
5 Correct 15 ms 6016 KB Output is correct
6 Correct 29 ms 6912 KB Output is correct
7 Correct 8 ms 5120 KB Output is correct
8 Correct 42 ms 8696 KB Output is correct
9 Correct 54 ms 9472 KB Output is correct
10 Correct 8 ms 5120 KB Output is correct
11 Correct 91 ms 11128 KB Output is correct
12 Correct 98 ms 12036 KB Output is correct
13 Correct 8 ms 5120 KB Output is correct
14 Correct 8 ms 4992 KB Output is correct
15 Correct 9 ms 5120 KB Output is correct
16 Correct 8 ms 5120 KB Output is correct
17 Correct 8 ms 5248 KB Output is correct
18 Correct 8 ms 4992 KB Output is correct
19 Correct 8 ms 4992 KB Output is correct
20 Correct 8 ms 5120 KB Output is correct
21 Correct 8 ms 4992 KB Output is correct
22 Correct 9 ms 4992 KB Output is correct
23 Correct 7 ms 4992 KB Output is correct
24 Correct 7 ms 4992 KB Output is correct
25 Correct 8 ms 4992 KB Output is correct
26 Correct 8 ms 5120 KB Output is correct
27 Correct 8 ms 5120 KB Output is correct
28 Correct 7 ms 4992 KB Output is correct
29 Correct 8 ms 4992 KB Output is correct
30 Correct 8 ms 4992 KB Output is correct
31 Correct 8 ms 5044 KB Output is correct
32 Correct 8 ms 5120 KB Output is correct
33 Correct 7 ms 4992 KB Output is correct
34 Correct 8 ms 4992 KB Output is correct
35 Correct 8 ms 4992 KB Output is correct
36 Correct 8 ms 4992 KB Output is correct
37 Correct 7 ms 4992 KB Output is correct
38 Correct 7 ms 4992 KB Output is correct
39 Correct 80 ms 13816 KB Output is correct
40 Correct 82 ms 13744 KB Output is correct
41 Correct 57 ms 10916 KB Output is correct
42 Correct 17 ms 6528 KB Output is correct
43 Correct 8 ms 4992 KB Output is correct
44 Correct 8 ms 5120 KB Output is correct
45 Correct 8 ms 4992 KB Output is correct
46 Correct 8 ms 4992 KB Output is correct
47 Correct 8 ms 4992 KB Output is correct
48 Correct 8 ms 5120 KB Output is correct
49 Correct 7 ms 4992 KB Output is correct
50 Correct 8 ms 5120 KB Output is correct
51 Correct 8 ms 4992 KB Output is correct
52 Correct 8 ms 4992 KB Output is correct
53 Correct 9 ms 4992 KB Output is correct
54 Correct 8 ms 4992 KB Output is correct
55 Correct 8 ms 4992 KB Output is correct
56 Correct 8 ms 4992 KB Output is correct
57 Correct 196 ms 15608 KB Output is correct
58 Correct 137 ms 15608 KB Output is correct
59 Correct 158 ms 15336 KB Output is correct
60 Correct 139 ms 15336 KB Output is correct
61 Correct 132 ms 15208 KB Output is correct
62 Correct 177 ms 15132 KB Output is correct
63 Correct 126 ms 15028 KB Output is correct
64 Correct 118 ms 14968 KB Output is correct
65 Correct 121 ms 14840 KB Output is correct
66 Correct 123 ms 14840 KB Output is correct
67 Correct 138 ms 15404 KB Output is correct
68 Correct 136 ms 15352 KB Output is correct
69 Correct 151 ms 15224 KB Output is correct
70 Correct 143 ms 15224 KB Output is correct
71 Correct 8 ms 4992 KB Output is correct
72 Correct 10 ms 5376 KB Output is correct
73 Correct 9 ms 5376 KB Output is correct
74 Correct 13 ms 5376 KB Output is correct
75 Correct 10 ms 5376 KB Output is correct
76 Correct 9 ms 5376 KB Output is correct
77 Correct 9 ms 5376 KB Output is correct
78 Correct 11 ms 5368 KB Output is correct
79 Correct 10 ms 5376 KB Output is correct
80 Correct 131 ms 15352 KB Output is correct
81 Correct 134 ms 15336 KB Output is correct
82 Correct 137 ms 15208 KB Output is correct
83 Correct 132 ms 15208 KB Output is correct
84 Correct 9 ms 5248 KB Output is correct
85 Correct 8 ms 5248 KB Output is correct
86 Correct 9 ms 5248 KB Output is correct
87 Correct 9 ms 5376 KB Output is correct
88 Correct 9 ms 5248 KB Output is correct
89 Correct 10 ms 5248 KB Output is correct
90 Correct 12 ms 5376 KB Output is correct
91 Correct 9 ms 5248 KB Output is correct
92 Correct 10 ms 5376 KB Output is correct
93 Correct 9 ms 5248 KB Output is correct
94 Correct 8 ms 4992 KB Output is correct
95 Correct 8 ms 4992 KB Output is correct
96 Correct 7 ms 4992 KB Output is correct
97 Correct 8 ms 4992 KB Output is correct
98 Correct 7 ms 4992 KB Output is correct
99 Correct 7 ms 4992 KB Output is correct
100 Correct 7 ms 4992 KB Output is correct
101 Correct 8 ms 4992 KB Output is correct
102 Correct 9 ms 4992 KB Output is correct
103 Correct 8 ms 4992 KB Output is correct
104 Correct 15 ms 6144 KB Output is correct
105 Correct 23 ms 7168 KB Output is correct
106 Correct 9 ms 4992 KB Output is correct
107 Correct 43 ms 9080 KB Output is correct
108 Correct 64 ms 10104 KB Output is correct
109 Correct 8 ms 5120 KB Output is correct
110 Correct 79 ms 12280 KB Output is correct
111 Correct 97 ms 13060 KB Output is correct
112 Correct 8 ms 5120 KB Output is correct
113 Correct 137 ms 14972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 31 ms 9636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 12636 KB Output is correct
2 Correct 82 ms 12592 KB Output is correct
3 Correct 50 ms 9976 KB Output is correct
4 Correct 16 ms 6272 KB Output is correct
5 Correct 15 ms 6016 KB Output is correct
6 Correct 29 ms 6912 KB Output is correct
7 Correct 8 ms 5120 KB Output is correct
8 Correct 42 ms 8696 KB Output is correct
9 Correct 54 ms 9472 KB Output is correct
10 Correct 8 ms 5120 KB Output is correct
11 Correct 91 ms 11128 KB Output is correct
12 Correct 98 ms 12036 KB Output is correct
13 Correct 8 ms 5120 KB Output is correct
14 Incorrect 8 ms 5120 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 12636 KB Output is correct
2 Correct 82 ms 12592 KB Output is correct
3 Correct 50 ms 9976 KB Output is correct
4 Correct 16 ms 6272 KB Output is correct
5 Correct 15 ms 6016 KB Output is correct
6 Correct 29 ms 6912 KB Output is correct
7 Correct 8 ms 5120 KB Output is correct
8 Correct 42 ms 8696 KB Output is correct
9 Correct 54 ms 9472 KB Output is correct
10 Correct 8 ms 5120 KB Output is correct
11 Correct 91 ms 11128 KB Output is correct
12 Correct 98 ms 12036 KB Output is correct
13 Correct 8 ms 5120 KB Output is correct
14 Correct 8 ms 4992 KB Output is correct
15 Correct 9 ms 5120 KB Output is correct
16 Correct 8 ms 5120 KB Output is correct
17 Correct 8 ms 5248 KB Output is correct
18 Correct 8 ms 4992 KB Output is correct
19 Correct 8 ms 4992 KB Output is correct
20 Correct 8 ms 5120 KB Output is correct
21 Correct 8 ms 4992 KB Output is correct
22 Correct 9 ms 4992 KB Output is correct
23 Correct 7 ms 4992 KB Output is correct
24 Correct 7 ms 4992 KB Output is correct
25 Correct 8 ms 4992 KB Output is correct
26 Correct 8 ms 5120 KB Output is correct
27 Correct 8 ms 5120 KB Output is correct
28 Correct 7 ms 4992 KB Output is correct
29 Correct 8 ms 4992 KB Output is correct
30 Correct 8 ms 4992 KB Output is correct
31 Correct 8 ms 5044 KB Output is correct
32 Correct 8 ms 5120 KB Output is correct
33 Correct 7 ms 4992 KB Output is correct
34 Correct 8 ms 4992 KB Output is correct
35 Correct 8 ms 4992 KB Output is correct
36 Correct 8 ms 4992 KB Output is correct
37 Correct 7 ms 4992 KB Output is correct
38 Correct 7 ms 4992 KB Output is correct
39 Correct 80 ms 13816 KB Output is correct
40 Correct 82 ms 13744 KB Output is correct
41 Correct 57 ms 10916 KB Output is correct
42 Correct 17 ms 6528 KB Output is correct
43 Correct 8 ms 4992 KB Output is correct
44 Correct 8 ms 5120 KB Output is correct
45 Correct 8 ms 4992 KB Output is correct
46 Correct 8 ms 4992 KB Output is correct
47 Correct 8 ms 4992 KB Output is correct
48 Correct 8 ms 5120 KB Output is correct
49 Correct 7 ms 4992 KB Output is correct
50 Correct 8 ms 5120 KB Output is correct
51 Correct 8 ms 4992 KB Output is correct
52 Correct 8 ms 4992 KB Output is correct
53 Correct 9 ms 4992 KB Output is correct
54 Correct 8 ms 4992 KB Output is correct
55 Correct 8 ms 4992 KB Output is correct
56 Correct 8 ms 4992 KB Output is correct
57 Correct 196 ms 15608 KB Output is correct
58 Correct 137 ms 15608 KB Output is correct
59 Correct 158 ms 15336 KB Output is correct
60 Correct 139 ms 15336 KB Output is correct
61 Correct 132 ms 15208 KB Output is correct
62 Correct 177 ms 15132 KB Output is correct
63 Correct 126 ms 15028 KB Output is correct
64 Correct 118 ms 14968 KB Output is correct
65 Correct 121 ms 14840 KB Output is correct
66 Correct 123 ms 14840 KB Output is correct
67 Correct 138 ms 15404 KB Output is correct
68 Correct 136 ms 15352 KB Output is correct
69 Correct 151 ms 15224 KB Output is correct
70 Correct 143 ms 15224 KB Output is correct
71 Correct 8 ms 4992 KB Output is correct
72 Correct 10 ms 5376 KB Output is correct
73 Correct 9 ms 5376 KB Output is correct
74 Correct 13 ms 5376 KB Output is correct
75 Correct 10 ms 5376 KB Output is correct
76 Correct 9 ms 5376 KB Output is correct
77 Correct 9 ms 5376 KB Output is correct
78 Correct 11 ms 5368 KB Output is correct
79 Correct 10 ms 5376 KB Output is correct
80 Correct 131 ms 15352 KB Output is correct
81 Correct 134 ms 15336 KB Output is correct
82 Correct 137 ms 15208 KB Output is correct
83 Correct 132 ms 15208 KB Output is correct
84 Correct 9 ms 5248 KB Output is correct
85 Correct 8 ms 5248 KB Output is correct
86 Correct 9 ms 5248 KB Output is correct
87 Correct 9 ms 5376 KB Output is correct
88 Correct 9 ms 5248 KB Output is correct
89 Correct 10 ms 5248 KB Output is correct
90 Correct 12 ms 5376 KB Output is correct
91 Correct 9 ms 5248 KB Output is correct
92 Correct 10 ms 5376 KB Output is correct
93 Correct 9 ms 5248 KB Output is correct
94 Correct 8 ms 4992 KB Output is correct
95 Correct 8 ms 4992 KB Output is correct
96 Correct 7 ms 4992 KB Output is correct
97 Correct 8 ms 4992 KB Output is correct
98 Correct 7 ms 4992 KB Output is correct
99 Correct 7 ms 4992 KB Output is correct
100 Correct 7 ms 4992 KB Output is correct
101 Correct 8 ms 4992 KB Output is correct
102 Correct 9 ms 4992 KB Output is correct
103 Correct 8 ms 4992 KB Output is correct
104 Correct 15 ms 6144 KB Output is correct
105 Correct 23 ms 7168 KB Output is correct
106 Correct 9 ms 4992 KB Output is correct
107 Correct 43 ms 9080 KB Output is correct
108 Correct 64 ms 10104 KB Output is correct
109 Correct 8 ms 5120 KB Output is correct
110 Correct 79 ms 12280 KB Output is correct
111 Correct 97 ms 13060 KB Output is correct
112 Correct 8 ms 5120 KB Output is correct
113 Correct 137 ms 14972 KB Output is correct
114 Incorrect 31 ms 9636 KB Output isn't correct
115 Halted 0 ms 0 KB -