Submission #1101694

# Submission time Handle Problem Language Result Execution time Memory
1101694 2024-10-16T15:33:42 Z hungeazy Hotspot (NOI17_hotspot) C++17
100 / 100
317 ms 25164 KB
/*
* @Author: hungeazy
* @Date:   2024-10-16 13:45:49
* @Last Modified by:   hungeazy
* @Last Modified time: 2024-10-16 22:33:35
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
// #pragma GCC optimize("O3")  
// #pragma GCC optimize("unroll-loops")  
// #pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")  
using namespace std;
using namespace __gnu_pbds; 
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long
#define ll long long 
#define lb long double 
#define ull unsigned long long
#define sz(x) x.size()
#define sqr(x) (1LL * (x) * (x))
#define all(x) x.begin(), x.end()
#define fill(f,x) memset(f,x,sizeof(f))
#define FOR(i,l,r) for(int i=l;i<=r;i++)
#define FOD(i,r,l) for(int i=r;i>=l;i--)
#define debug(x) cout << #x << " = " << x << '\n'
#define ii pair<int,int>
#define iii pair<int,ii>
#define di pair<ii,ii>
#define vi vector<int>
#define vii vector<ii>
#define mii map<int,int>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define fi first
#define se second
#define pb push_back
#define MOD 1000000007
#define __lcm(a,b) (1ll * ((a) / __gcd((a), (b))) * (b))
#define YES cout << "YES\n"
#define NO cout << "NO\n"
#define MASK(i) (1LL << (i))
#define c_bit(i) __builtin_popcountll(i)
#define BIT(x,i) ((x) & MASK(i))
#define SET_ON(x,i) ((x) | MASK(i))
#define SET_OFF(x,i) ((x) & ~MASK(i))
#define oo 1e18
#define name "TRAINCENTRE"
#define endl '\n'
#define time() cerr << endl << "-------------Time:" << 1000.0 * clock() / CLOCKS_PER_SEC << "ms.";
template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; }
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; }
const int N = (int)1e6+10;
vi g[N];
int n,m,k;

namespace sub14 {

	int cnt[N],par[N],h[N];
	bool visited[N];

	bool approved()
	{
		return n <= 1e3 and m <= 1e3 and k <= 200;
	}

	void DFS(int u, int p)
	{
		visited[u] = true;
		par[u] = p;
		if (p != -1) h[u] = h[p]+1;
		for (int v : g[u])
			if (!visited[v])
				DFS(v,u);
	}

	void calc(int u, int v)
	{
		if (h[u] < h[v]) swap(u,v);
		while (h[u] > h[v])
		{
			cnt[u]++;
			u = par[u];
		}
		while (u != v)
		{
			cnt[u]++; cnt[v]++;
			u = par[u]; v = par[v];
		}
		cnt[u]++;
	}

	void solve(void)
	{
		DFS(0,-1);
		while (k--)
		{
			int a,b;
			cin >> a >> b;
			calc(a,b);
		}
		int u = 0;
		FOR(i,0,N-10)
			if (cnt[u] < cnt[i]) u = i;
		cout << u;
	}
	
}

namespace sub56 {

	int f[N],d[N];
	bool visited[N];
	lb cnt[N],ans[N];

	void BFS(int p)
	{
		FOR(i,0,n) d[i] = oo, visited[i] = false, cnt[i] = 0.0, f[i] = 0;
		queue<int> q;
		q.push(p);
		d[p] = 0; f[p] = 1;
		while (!q.empty())
		{
			int u = q.front();
			q.pop();
			for (int v : g[u])
				if (d[v] > d[u]+1) 
				{
					d[v] = d[u]+1;
					f[v] = f[u];
					q.push(v);
				}
				else if (d[v] == d[u]+1) f[v] += f[u];
		}
	}

	void solve(void)
	{
		while (k--)
		{
			int a,b;
			cin >> a >> b;
			BFS(a);
			int cur = f[b];
			if (cur != 0)
			{
				cnt[b] = 1.0L;
				queue<int> q;
				q.push(b);
				while (!q.empty())
				{
					int u = q.front();
					q.pop();
					if (visited[u]) continue;
					visited[u] = true;
					ans[u] += cnt[u];
					for (int v : g[u])
						if (d[v] == d[u]-1) 
						{
							cnt[v] += (f[v]*1.0/f[u]*1.0*cnt[u]);
							q.push(v);
						}
				}
			}
		}
		lb res = 0.0;
		int pos;
		FOR(i,0,n)
			if (res < ans[i]) res = ans[i], pos = i;
		cout << pos;
	}

}

signed main()
{
    fast;
    if (fopen(name".inp","r"))
    {
    	freopen(name".inp","r",stdin);
    	freopen(name".out","w",stdout);
    }
    cin >> n >> m;
    FOR(i,1,m)
    {
    	int u,v;
    	cin >> u >> v;
    	g[u].pb(v); g[v].pb(u);
    }
    cin >> k;
    // if (sub14::approved()) sub14::solve();
    // else 
    sub56::solve();
    time();
    return 0;
}
// ██░ ██  █    ██  ███▄    █   ▄████
//▓██░ ██▒ ██  ▓██▒ ██ ▀█   █  ██▒ ▀█▒
//▒██▀▀██░▓██  ▒██░▓██  ▀█ ██▒▒██░▄▄▄░
//░▓█ ░██ ▓▓█  ░██░▓██▒  ▐▌██▒░▓█  ██▓
//░▓█▒░██▓▒▒█████▓ ▒██░   ▓██░░▒▓███▀▒
// ▒ ░░▒░▒░▒▓▒ ▒ ▒ ░ ▒░   ▒ ▒  ░▒   ▒
// ▒ ░▒░ ░░░▒░ ░ ░ ░ ░░   ░ ▒░  ░   ░
// ░  ░░ ░ ░░░ ░ ░    ░   ░ ░ ░ ░   ░
// ░  ░  ░   ░              ░       ░

Compilation message

hotspot.cpp: In function 'int main()':
hotspot.cpp:179:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  179 |      freopen(name".inp","r",stdin);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
hotspot.cpp:180:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  180 |      freopen(name".out","w",stdout);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 15 ms 24400 KB Output is correct
2 Correct 16 ms 24568 KB Output is correct
3 Correct 15 ms 24268 KB Output is correct
4 Correct 16 ms 24312 KB Output is correct
5 Correct 16 ms 24400 KB Output is correct
6 Correct 15 ms 24400 KB Output is correct
7 Correct 17 ms 24400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 24400 KB Output is correct
2 Correct 16 ms 24568 KB Output is correct
3 Correct 15 ms 24268 KB Output is correct
4 Correct 16 ms 24312 KB Output is correct
5 Correct 16 ms 24400 KB Output is correct
6 Correct 15 ms 24400 KB Output is correct
7 Correct 17 ms 24400 KB Output is correct
8 Correct 18 ms 24400 KB Output is correct
9 Correct 15 ms 24192 KB Output is correct
10 Correct 17 ms 24400 KB Output is correct
11 Correct 16 ms 24400 KB Output is correct
12 Correct 16 ms 24144 KB Output is correct
13 Correct 21 ms 24400 KB Output is correct
14 Correct 15 ms 24400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 24400 KB Output is correct
2 Correct 16 ms 24568 KB Output is correct
3 Correct 15 ms 24268 KB Output is correct
4 Correct 16 ms 24312 KB Output is correct
5 Correct 16 ms 24400 KB Output is correct
6 Correct 15 ms 24400 KB Output is correct
7 Correct 17 ms 24400 KB Output is correct
8 Correct 16 ms 24400 KB Output is correct
9 Correct 16 ms 24400 KB Output is correct
10 Correct 18 ms 24324 KB Output is correct
11 Correct 17 ms 24400 KB Output is correct
12 Correct 15 ms 24144 KB Output is correct
13 Correct 16 ms 24144 KB Output is correct
14 Correct 18 ms 23888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 24400 KB Output is correct
2 Correct 16 ms 24568 KB Output is correct
3 Correct 15 ms 24268 KB Output is correct
4 Correct 16 ms 24312 KB Output is correct
5 Correct 16 ms 24400 KB Output is correct
6 Correct 15 ms 24400 KB Output is correct
7 Correct 17 ms 24400 KB Output is correct
8 Correct 18 ms 24400 KB Output is correct
9 Correct 15 ms 24192 KB Output is correct
10 Correct 17 ms 24400 KB Output is correct
11 Correct 16 ms 24400 KB Output is correct
12 Correct 16 ms 24144 KB Output is correct
13 Correct 21 ms 24400 KB Output is correct
14 Correct 15 ms 24400 KB Output is correct
15 Correct 16 ms 24400 KB Output is correct
16 Correct 16 ms 24400 KB Output is correct
17 Correct 18 ms 24324 KB Output is correct
18 Correct 17 ms 24400 KB Output is correct
19 Correct 15 ms 24144 KB Output is correct
20 Correct 16 ms 24144 KB Output is correct
21 Correct 18 ms 23888 KB Output is correct
22 Correct 18 ms 23888 KB Output is correct
23 Correct 17 ms 23888 KB Output is correct
24 Correct 17 ms 23888 KB Output is correct
25 Correct 19 ms 23888 KB Output is correct
26 Correct 18 ms 23828 KB Output is correct
27 Correct 16 ms 23888 KB Output is correct
28 Correct 22 ms 23888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 24400 KB Output is correct
2 Correct 16 ms 24568 KB Output is correct
3 Correct 15 ms 24268 KB Output is correct
4 Correct 16 ms 24312 KB Output is correct
5 Correct 16 ms 24400 KB Output is correct
6 Correct 15 ms 24400 KB Output is correct
7 Correct 17 ms 24400 KB Output is correct
8 Correct 18 ms 24400 KB Output is correct
9 Correct 15 ms 24192 KB Output is correct
10 Correct 17 ms 24400 KB Output is correct
11 Correct 16 ms 24400 KB Output is correct
12 Correct 16 ms 24144 KB Output is correct
13 Correct 21 ms 24400 KB Output is correct
14 Correct 15 ms 24400 KB Output is correct
15 Correct 18 ms 24144 KB Output is correct
16 Correct 16 ms 23888 KB Output is correct
17 Correct 20 ms 24144 KB Output is correct
18 Correct 19 ms 23976 KB Output is correct
19 Correct 19 ms 24148 KB Output is correct
20 Correct 22 ms 24160 KB Output is correct
21 Correct 16 ms 24064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 24400 KB Output is correct
2 Correct 16 ms 24568 KB Output is correct
3 Correct 15 ms 24268 KB Output is correct
4 Correct 16 ms 24312 KB Output is correct
5 Correct 16 ms 24400 KB Output is correct
6 Correct 15 ms 24400 KB Output is correct
7 Correct 17 ms 24400 KB Output is correct
8 Correct 18 ms 24400 KB Output is correct
9 Correct 15 ms 24192 KB Output is correct
10 Correct 17 ms 24400 KB Output is correct
11 Correct 16 ms 24400 KB Output is correct
12 Correct 16 ms 24144 KB Output is correct
13 Correct 21 ms 24400 KB Output is correct
14 Correct 15 ms 24400 KB Output is correct
15 Correct 16 ms 24400 KB Output is correct
16 Correct 16 ms 24400 KB Output is correct
17 Correct 18 ms 24324 KB Output is correct
18 Correct 17 ms 24400 KB Output is correct
19 Correct 15 ms 24144 KB Output is correct
20 Correct 16 ms 24144 KB Output is correct
21 Correct 18 ms 23888 KB Output is correct
22 Correct 18 ms 23888 KB Output is correct
23 Correct 17 ms 23888 KB Output is correct
24 Correct 17 ms 23888 KB Output is correct
25 Correct 19 ms 23888 KB Output is correct
26 Correct 18 ms 23828 KB Output is correct
27 Correct 16 ms 23888 KB Output is correct
28 Correct 22 ms 23888 KB Output is correct
29 Correct 18 ms 24144 KB Output is correct
30 Correct 16 ms 23888 KB Output is correct
31 Correct 20 ms 24144 KB Output is correct
32 Correct 19 ms 23976 KB Output is correct
33 Correct 19 ms 24148 KB Output is correct
34 Correct 22 ms 24160 KB Output is correct
35 Correct 16 ms 24064 KB Output is correct
36 Correct 45 ms 24348 KB Output is correct
37 Correct 78 ms 24404 KB Output is correct
38 Correct 317 ms 25060 KB Output is correct
39 Correct 202 ms 25080 KB Output is correct
40 Correct 52 ms 24404 KB Output is correct
41 Correct 201 ms 24916 KB Output is correct
42 Correct 281 ms 25164 KB Output is correct
43 Correct 29 ms 24148 KB Output is correct
44 Correct 27 ms 24148 KB Output is correct