Submission #797457

#TimeUsernameProblemLanguageResultExecution timeMemory
797457LiudasTraffic (IOI10_traffic)C++17
100 / 100
942 ms194216 KiB
#include "traffic.h" #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope> //#define int long long #define pb push_back #define s second #define f first #define pf push_front #define inf 100000000000000000 #define bitebi __builtin_popcountll #define FOR( i , n ) for( int i = 0 ; i < n ; i ++ ) #define YES cout <<"YES\n" #define NO cout << "NO\n" #define debug cout << "Here Fine" << endl ; #define pr pair < int , int > #define fbo find_by_order // returns iterator #define ook order_of_key // returns strictly less numbers than key using namespace std ; //#pragma GCC optimize("Ofast") //#pragma GCC target("avx,avx2,fma") using namespace __gnu_pbds; using namespace __gnu_cxx; #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> const double Pi=acos(-1.0); const double EPS=1E-8; const int mod = 1000000007 ; const int mod1 = 998244353 ; const int N = 2e6 + 10 ; mt19937 R(time(0)); map < int , int > ma , ma1 ; vector < int > v[ N ] ; int val[ N ] , ss[ N ] ; void dfs( int node , int parent ){ ss[ node ] = val[ node ] ; for( auto x : v[ node ] ){ if( x == parent ) continue ; dfs( x , node ) ; ss[ node ] += ss[ x ] ; } } pair < int , int > ans = { INT_MAX , 0 } ; void reroot( int node , int parent , int fm ){ int mx = fm ; for( auto x : v[ node ] ){ if( x == parent ) continue ; mx = max( mx , ss[ x ] ) ; int FM = fm + ss[ node ] - ss[ x ] ; reroot( x , node , FM ) ; } if( mx < ans.f ){ ans = { mx , node } ; } } int LocateCentre(int N, int P[], int S[], int D[]){ FOR( i , N ) val[ i ] = P[ i ] ; FOR( i , N - 1 ){ v[ S[ i ] ].pb( D[ i ] ) ; v[ D[ i ] ].pb( S[ i ] ) ; } dfs( 0 , -1 ) ; reroot( 0 , -1 , 0 ) ; return ans.s ; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...