結果

問題 No.2072 Anatomy
ユーザー junm0rijunm0ri
提出日時 2022-09-17 01:21:05
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 122 ms / 2,000 ms
コード長 4,452 bytes
コンパイル時間 4,574 ms
コンパイル使用メモリ 253,064 KB
実行使用メモリ 11,196 KB
最終ジャッジ日時 2023-08-23 17:20:43
合計ジャッジ時間 8,433 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,504 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 104 ms
9,684 KB
testcase_09 AC 114 ms
10,140 KB
testcase_10 AC 106 ms
9,032 KB
testcase_11 AC 112 ms
9,852 KB
testcase_12 AC 87 ms
8,228 KB
testcase_13 AC 119 ms
10,728 KB
testcase_14 AC 75 ms
7,632 KB
testcase_15 AC 71 ms
7,760 KB
testcase_16 AC 118 ms
10,696 KB
testcase_17 AC 115 ms
10,444 KB
testcase_18 AC 62 ms
7,028 KB
testcase_19 AC 117 ms
10,864 KB
testcase_20 AC 119 ms
10,888 KB
testcase_21 AC 118 ms
10,996 KB
testcase_22 AC 121 ms
11,196 KB
testcase_23 AC 119 ms
10,864 KB
testcase_24 AC 119 ms
10,960 KB
testcase_25 AC 122 ms
11,008 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 117 ms
11,064 KB
testcase_28 AC 112 ms
11,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//らせん階段
// カブト虫
// 廃墟の街
// イチジクのタルト
// カブト虫
//ドロローサへの道
// カブト虫
// 特異点
// ジョット
// エンジェル
// 紫陽花
// カブト虫
// 特異点
// 秘密の皇帝


#include <bits/stdc++.h>
#include<cmath>
#include <ext/pb_ds/assoc_container.hpp>
#include<atcoder/all>
// tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> S;
// #include<boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
using namespace std;
using namespace __gnu_pbds;
using namespace atcoder;
// ↓変数の値はA.val()で取得する
using mint9 = modint998244353;
using mint7 = modint1000000007;
#define ll long long
#define ld long double
#define pi pair<int,int>
#define PQ priority_queue<int>
#define PQG priority_queue<int, vector<int>, greater<int>>
#define MV(V,N) vector<int> (V)(N); for (int i=0;i<(N);i++) cin >>V[i];
#define vi vector<int> 
#define vld vector<long double> 
#define vs vector<string> 
#define vp vector<pi>
#define vvi(V,H,W) vector<vector<int>> (V)((H),vector<int>(W));
#define vvl(V,H,W) vector<vector<ll>> (V)((H),vector<ll>(W));
#define vvld(V,H,W) vector<vector<long double>> (V)((H),vector<long double>(W));
#define vvs(V,H,W) vector<vector<string>> (V)((H),vector<string>(W));
#define vvc(V,H,W) vector<vector<char>> (V)((H),vector<char>(W));
#define checkV(V) for (auto x:V) cout<<x<<" ";cout<<endl;
#define irep(n) for (int i=0; i < (n); ++i)
#define irepf1(n) for (int i=1; i <= (n); ++i)
#define jrep(n) for (int j=0; j < (n); ++j)
#define jrepf1(n) for (int j=1; j <= (n); ++j)
#define krep(n) for (int k=0; k < (n); ++k)
#define krepf1(n) for (int k=1; k <= (n); ++k)
#define rep(i,s,e) for (int (i)=(s); (i)<(e);(i)++)
#define per(i,s,e) for (int (i)=(s); (i)>=(e);(i)--)
#define INF 1000000000000000000
#define PI 3.14159265358979323846264338327950288
#define Banpei 1000000000 //問題毎に設定
#define Max_V 100000
#define mod7 1000000007
#define mod9 998244353
#define eps 0.00000001
#define ALL(V,A) ((V).begin(),(V).end(),(A))
#define Find(V,X) find(V.begin(),V.end(),X)
#define Lbound(V,X) *lower_bound((V).begin(),(V).end(),(X))
#define LboundP(V,X) lower_bound((V).begin(),(V).end(),(X))-(V).begin();
#define Ubound(V,X) *upper_bound((V).begin(),(V).end(),(X))
#define UboundP(V,X) upper_bound((V).begin(),(V).end(),(X))-(V).begin();
#define Sort(V) sort((V).begin(),(V).end())
#define SortPairBySecond(V)  sort((V).begin(), (V).end(), [](auto a, auto b) { return a.second < b.second; });
#define Reverse(V) reverse((V).begin(),(V).end())
#define Greater(V) sort((V).begin(),(V).end(),greater<int>())
#define cmin(ans,A) (ans)=min((ans),(A))
#define cmax(ans,A) (ans)=max((ans),(A))
#define AUTO(x,V) for (auto (x):(V))
#define int long long
//fixed << setprecision(10) <<

using Graph = vector<vector<int>>;
Graph makeGraph(int N, int V) {
  Graph G(N);
  irep (V) {
    int A,B;
    cin >>A>>B;
    A--;B--;
    G[A].push_back(B);
    G[B].push_back(A);
  }
  return G;
}

struct UnionFind { //0オリジンに修正して使用
    vector<int> size, parents;
    UnionFind() {}
    UnionFind(int n) {  // make n trees.
        size.resize(n, 0);
        parents.resize(n, 0);
        for (int i = 0; i < n; i++) {
            makeTree(i);
        }
    }
    void makeTree(int x) {
        parents[x] = x;  // the parent of x is x
        size[x] = 1;
    }
    bool isSame(int x, int y) { return findRoot(x) == findRoot(y); }
    bool unite(int x, int y) {
        x = findRoot(x);
        y = findRoot(y);
        if (x == y) return false;
        if (size[x] > size[y]) {
            parents[y] = x;
            size[x] += size[y];
        } else {
            parents[x] = y;
            size[y] += size[x];
        }
        return true;
    }
    int findRoot(int x) {
        if (x != parents[x]) {
            parents[x] = findRoot(parents[x]);
        }
        return parents[x];
    }
    int treeSize(int x) { return size[findRoot(x)]; }
};

signed main() {
  int N,M;
  cin >>N >>M;

  UnionFind UF=UnionFind(N);
  
  vp V(M);
  irep(M) cin >>V[i].first>>V[i].second;
  Reverse(V);
    
  vi dp(N);
  irep(M) {
    int A=V[i].first,B=V[i].second;
    A--;B--;
    int C=UF.findRoot(A),D=UF.findRoot(B);
    int stock=max(dp[C],dp[D])+1;
    UF.unite(A,B);
    dp[UF.findRoot(A)]=stock;
  }
  cout<<dp[UF.findRoot(0)]<<endl;
//   irep(N) cout<<dp[i]<<" ";
//   cout<<endl;
}
0