(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

Submission #298567

#TimeUsernameProblemLanguageResultExecution timeMemory
298567aloo123Traffic (IOI10_traffic)C++14
100 / 100
1319 ms143868 KiB
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <ratio> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #include <climits> // #include "traffic.h" #define ll long long #define ld long double #define mp make_pair #define pb push_back #define in insert #define vll vector<ll> #define endl "\n" #define pll pair<ll,ll> #define f first #define s second #define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++) // #define int ll #define sz(x) (ll)x.size() #define all(x) (x.begin(),x.end()) using namespace std; const int INF = INT_MAX; const int N =(1e6+5); // TODO : change value as per problem // const ll MOD = 1e9+7; vector<int> adj[N]; int sub[N]; int a[N]; int par[N]; void dfs(int u,int p){ sub[u] = a[u]; par[u] = p; for(auto v:adj[u]){ if(v != p){ dfs(v,u); sub[u] += sub[v]; } } } int LocateCentre(int n,int p[],int s[],int d[]){ for(int i = 0;i<n;i++){ a[i+1] = p[i]; } for(int i =0;i<n-1;i++){ int u = s[i],v = d[i]; u++; v++; adj[u].pb(v); adj[v].pb(u); } dfs(1,0); int ans = 0,x = 1; for(auto u:adj[1]){ ans = max(ans,sub[u]); } for(int i = 2;i <= n;i++){ int u = i; int ma = 0; int gg = 0; for(auto v:adj[u]){ if(v != par[i]){ gg = max(gg,sub[v]); } } ma =max(gg,sub[par[i]] -sub[u] + sub[1] - sub[par[i]]); if(ma < ans){ ans = ma; x = i; } } // cout << ans << endl; x--; return x; } // void solve(){ // } // signed main(){ // ios_base::sync_with_stdio(0); // cin.tie(NULL); // // freopen(".in","r",stdin);freopen(".out","w",stdout); // int n; // cin >> n; // int p[n]; // for(int i =0;i<n;i++){ // cin >> p[i]; // } // int s[n-1]; // int d[n-1]; // for(int i =0;i<n-1;i++){ // cin >> s[i] >> d[i]; // } // cout << LocateCentre(n,p,s,d) << endl; // }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...