// #define _GLIBCXX_DEBUG #include using namespace std; using uint = unsigned int; using ll = long long; #define CIN( LL , A ) LL A; cin >> A #define UNTIE ios_base::sync_with_stdio( false ); cin.tie( nullptr ) #define FOR( VAR , INITIAL , FINAL_PLUS_ONE ) for( remove_const::type >::type VAR = INITIAL ; VAR < FINAL_PLUS_ONE ; VAR ++ ) #define QUIT return 0 #define RETURN( ANSWER ) cout << ( ANSWER ) << "\n"; QUIT #define MAIN main class Edge { public: int m_i0; int m_i1; int m_w; inline Edge() = default; }; class OrdEdge { public: inline bool operator()( const Edge& e0 , const Edge& e1 ) { return e0.m_w < e1.m_w; } }; class Query { public: int m_r; int m_t; inline Query() = default; }; class OrdQuery { public: inline bool operator()( const Query& q0 , const Query& q1 ) { return q0.m_r < q1.m_r; } }; class Node { public: int m_depth; Node* m_root; inline Node() : m_depth( 0 ) , m_root( this ) {} }; int MAIN() { UNTIE; constexpr const int bound = 100001; CIN( int , N_V ); CIN( int , N_E ); Edge E[bound] = {}; FOR( j , 0 , N_E ){ Edge& ej = E[j]; cin >> ej.m_i0; cin >> ej.m_i1; cin >> ej.m_w; } CIN( int , T ); Query Q[bound]; FOR( t , 0 , T ){ Query& qt = Q[t]; cin >> qt.m_r; qt.m_t = t; } sort( E , E + N_E , OrdEdge() ); sort( Q , Q + T , OrdQuery() ); Node Pi0G[bound] = {}; int answer[bound]; int j = 0; int cc = N_V; int depth_dif; FOR( t , 0 , T ){ Query& qt = Q[t]; while( j < N_E ){ Edge& ej = E[j]; if( ej.m_w <= qt.m_r ){ Node& Pi0Gi0 = Pi0G[ej.m_i0]; while( Pi0Gi0.m_root != Pi0Gi0.m_root->m_root ){ Pi0Gi0.m_root = Pi0Gi0.m_root->m_root; } Node& Pi0Gi1 = Pi0G[ej.m_i1]; while( Pi0Gi1.m_root != Pi0Gi1.m_root->m_root ){ Pi0Gi1.m_root = Pi0Gi1.m_root->m_root; } if( Pi0Gi0.m_root != Pi0Gi1.m_root ){ depth_dif = Pi0Gi1.m_root->m_depth - Pi0Gi0.m_root->m_depth; if( depth_dif > 0 ){ Pi0Gi0.m_root = Pi0Gi0.m_root->m_root = Pi0Gi1.m_root; } else { Pi0Gi1.m_root = Pi0Gi1.m_root->m_root = Pi0Gi0.m_root; if( depth_dif == 0 ){ Pi0Gi0.m_root->m_depth++; } } cc--; } j++; } else { break; } } answer[qt.m_t] = cc; } FOR( t , 0 , T ){ cout << answer[t] << "\n"; } QUIT; }