Submission #1101368

#TimeUsernameProblemLanguageResultExecution timeMemory
1101368hungeazyHotspot (NOI17_hotspot)C++17
38 / 100
12 ms30804 KiB
/* * @Author: hungeazy * @Date: 2024-10-16 13:45:49 * @Last Modified by: hungeazy * @Last Modified time: 2024-10-16 14:23:09 */ #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; 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.0; queue<int> q; q.push(b); while (!q.empty()) { int u = q.front(); q.pop(); if (visited[u]) continue; visited[u] = true; ans[u] += f[u]; for (int v : g[u]) if (d[v] == d[u]-1) { q.push(v); cnt[v] += (lb)((lb)f[v]/(lb)f[u]*cnt[u]); } } } } lb res = 0.0; int pos; FOR(i,0,N-10) 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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...