結果
| 問題 |
No.2912 0次パーシステントホモロジー
|
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2022-11-15 16:47:15 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 68 ms / 2,000 ms |
| コード長 | 2,365 bytes |
| コンパイル時間 | 2,082 ms |
| コンパイル使用メモリ | 199,560 KB |
| 最終ジャッジ日時 | 2025-02-08 20:24:49 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
// #define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
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<remove_reference<decltype( FINAL_PLUS_ONE )>::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;
}