結果

問題 No.1344 Typical Shortest Path Sum
ユーザー PCTprobability
提出日時 2021-01-13 21:49:01
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,748 bytes
コンパイル時間 3,382 ms
コンパイル使用メモリ 195,452 KB
最終ジャッジ日時 2025-01-17 17:37:02
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other WA * 77
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define all(s) (s).begin(),(s).end()
#define vcin(n) for(ll i=0;i<ll(n.size());i++) cin>>n[i]
#define rever(vec) reverse(vec.begin(), vec.end())
#define sor(vec) sort(vec.begin(), vec.end())
#define fi first
#define se second
const ll mod = 998244353;
//const ll mod = 1000000007;
const ll inf = 2000000000000000000ll;
static const long double pi = 3.141592653589793;
template<class T,class U> void chmax(T& t,const U& u){if(t<u) t=u;}
template<class T,class U> void chmin(T& t,const U& u){if(t>u) t=u;}
ll modPow(ll a, ll n, ll mod) { ll ret = 1; ll p = a % mod; while (n) { if (n & 1) ret = ret * p % mod; p = p * p % mod; n >>= 1; } return ret; }
class UnionFind{
public:
vector<ll> par;
vector<ll> siz;
UnionFind(ll sz_):par(sz_),siz(sz_,1ll){
for(int i=0;i<sz_;i++) par[i]=i;
}
void init(ll sz_){
par.resize(sz_);
siz.assign(sz_,1ll);
for(int i=0;i<sz_;i++) par[i]=i;
}
ll root(ll x){
while(par[x]!=x){
x=par[x]=par[par[x]];
}
return x;
}
bool merge(ll x,ll y){
x=root(x);
y=root(y);
if(x==y) return false;
if(siz[x]<siz[y]) swap(x,y);
siz[x]+=siz[y];
par[y]=x;
return true;
}
bool issame(ll x,ll y){
return root(x)==root(y);
}
ll size(ll x){
return siz[root(x)];
}
};
int main() {
/* mod 1e9+7 */
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
cout<< fixed << setprecision(10);
ll n,m;
cin>>n>>m;
UnionFind t(n);
for(int i=0;i<m;i++){
ll a,b,c;
cin>>a>>b>>c;
a--;
b--;
t.merge(a,b);
}
ll f=t.root(0);
ll ans=0;
for(int i=0;i<n;i++){
if(f!=t.root(i)){
ans++;
}
}
assert(ans==0);
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0