답안 #1105390

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1105390 2024-10-26T09:09:47 Z badman Hotspot (NOI17_hotspot) C++17
100 / 100
1022 ms 1272 KB
#include <bits/stdc++.h>
//#define int long long
#define Owo "hotspot"
const int N = 5e3 + 5;
const int M = 1;
const int mod = 1e9 + 7;
const int S = 300;
const int base = 31;
using namespace std;
int n, m, k, u, v, d[N][2];
long long dem[N][2];
long double f[N];
vector <int> g[N];
priority_queue <pair <int, int>, vector <pair <int, int>>, greater <pair <int, int>>> pq;

void shortest_path (int ver, int id)
{
	d[ver][id] = 0;
	pq.push ({0, ver});
	while (pq.empty () == 0)
	{
		auto [val, u] = pq.top ();
		pq.pop ();
		if (val != d[u][id])
			continue;
		for (int v : g[u])
			if (d[v][id] > d[u][id] + 1)
			{
				d[v][id] = d[u][id] + 1;
				dem[v][id] = dem[u][id];
				pq.push ({d[v][id], v});
			}
			else if (d[v][id] == d[u][id] + 1)
				dem[v][id] += dem[u][id];
	}
}

int32_t main ()
{
	if (fopen(Owo ".inp", "r"))
	{
		freopen(Owo ".inp", "r", stdin);
		freopen(Owo ".out", "w", stdout);
	}
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie (0);
	cin >> n >> m;
	for (int i = 1; i <= m; i -= -1)
	{
		cin >> u >> v;
		g[u].push_back (v);
		g[v].push_back (u);
	}
	cin >> k;
	while (k --)
	{
		cin >> u >> v;
		for (int i = 0; i < n; i -= -1)
			d[i][0] = d[i][1] = INT_MAX, dem[i][0] = dem[i][1] = 1;
		shortest_path (u, 0);
		shortest_path (v, 1);
		for (int i = 0; i < n; i -= -1)
			if (d[i][0] + d[i][1] == d[v][0])
				f[i] += (dem[i][0] * dem[i][1] * 1.0) / dem[v][0] * 1.0;
	}
	int rs = 0;
	for (int i = 1 ; i < n; i -= -1)
	{
		//cout << f[i] << " ";
		if (f[i] > f[rs])
			rs = i;
	}
	cout << rs;
}

Compilation message

hotspot.cpp: In function 'int32_t main()':
hotspot.cpp:42:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |   freopen(Owo ".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
hotspot.cpp:43:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |   freopen(Owo ".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 592 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 592 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 2 ms 592 KB Output is correct
9 Correct 1 ms 560 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
11 Correct 1 ms 592 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 764 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 592 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 2 ms 592 KB Output is correct
9 Correct 3 ms 592 KB Output is correct
10 Correct 3 ms 592 KB Output is correct
11 Correct 4 ms 592 KB Output is correct
12 Correct 2 ms 592 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 3 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 592 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 2 ms 592 KB Output is correct
9 Correct 1 ms 560 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
11 Correct 1 ms 592 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 764 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 2 ms 592 KB Output is correct
16 Correct 3 ms 592 KB Output is correct
17 Correct 3 ms 592 KB Output is correct
18 Correct 4 ms 592 KB Output is correct
19 Correct 2 ms 592 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 3 ms 592 KB Output is correct
22 Correct 3 ms 592 KB Output is correct
23 Correct 3 ms 592 KB Output is correct
24 Correct 5 ms 764 KB Output is correct
25 Correct 11 ms 668 KB Output is correct
26 Correct 9 ms 592 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 8 ms 764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 592 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 2 ms 592 KB Output is correct
9 Correct 1 ms 560 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
11 Correct 1 ms 592 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 764 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 2 ms 592 KB Output is correct
16 Correct 1 ms 592 KB Output is correct
17 Correct 5 ms 592 KB Output is correct
18 Correct 3 ms 592 KB Output is correct
19 Correct 5 ms 592 KB Output is correct
20 Correct 2 ms 592 KB Output is correct
21 Correct 1 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 592 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 2 ms 592 KB Output is correct
9 Correct 1 ms 560 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
11 Correct 1 ms 592 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 764 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 2 ms 592 KB Output is correct
16 Correct 3 ms 592 KB Output is correct
17 Correct 3 ms 592 KB Output is correct
18 Correct 4 ms 592 KB Output is correct
19 Correct 2 ms 592 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 3 ms 592 KB Output is correct
22 Correct 3 ms 592 KB Output is correct
23 Correct 3 ms 592 KB Output is correct
24 Correct 5 ms 764 KB Output is correct
25 Correct 11 ms 668 KB Output is correct
26 Correct 9 ms 592 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 8 ms 764 KB Output is correct
29 Correct 2 ms 592 KB Output is correct
30 Correct 1 ms 592 KB Output is correct
31 Correct 5 ms 592 KB Output is correct
32 Correct 3 ms 592 KB Output is correct
33 Correct 5 ms 592 KB Output is correct
34 Correct 2 ms 592 KB Output is correct
35 Correct 1 ms 592 KB Output is correct
36 Correct 54 ms 592 KB Output is correct
37 Correct 179 ms 848 KB Output is correct
38 Correct 1022 ms 1272 KB Output is correct
39 Correct 458 ms 848 KB Output is correct
40 Correct 147 ms 848 KB Output is correct
41 Correct 675 ms 1156 KB Output is correct
42 Correct 736 ms 1104 KB Output is correct
43 Correct 60 ms 592 KB Output is correct
44 Correct 51 ms 764 KB Output is correct