結果

問題 No.1473 おでぶなおばけさん
ユーザー GGanariGGanari
提出日時 2024-03-22 14:17:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,150 bytes
コンパイル時間 3,834 ms
コンパイル使用メモリ 235,496 KB
実行使用メモリ 10,772 KB
最終ジャッジ日時 2024-03-22 14:17:24
合計ジャッジ時間 10,960 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,676 KB
testcase_01 AC 4 ms
6,676 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 7 ms
6,676 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 32 ms
7,700 KB
testcase_42 AC 33 ms
7,700 KB
testcase_43 AC 45 ms
9,492 KB
testcase_44 AC 45 ms
9,492 KB
testcase_45 AC 44 ms
9,492 KB
testcase_46 AC 87 ms
9,108 KB
testcase_47 AC 106 ms
9,620 KB
testcase_48 AC 89 ms
9,492 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2")
#include <bits/stdc++.h>
#define INF 1000000001LL
#define LNF 1000000000000000001LL
#define MOD 1000000007LL
#define MAX 502
#define long long long
#define all(x) x.begin(),x.end()
using namespace std;


vector<pair<int,pair<int,int>>> edge;
vector<int> graph[100001];
vector<int> parent(100001);
int find(int x)
{
    if(parent[x] == x)
        return x;
    return parent[x] = find(parent[x]);
}

bool merge(int x, int y)
{
    x = find(x);
    y = find(y);

    if(x == y)
        return 1;
    if(x < y)
        parent[y] = x;
    else
        parent[x] = y;
    return 0;
}
int check(int n,int x)
{
    for(int i = 0; i<=n; i++)
        parent[i] = i;
    for(int i = 0; i<edge.size(); i++)
    {
        int d = edge[i].first;
        int u = edge[i].second.first;
        int v = edge[i].second.second;
        if(d >= x)
            merge(u,v);
    }
    return merge(1,n);
}
int main()
{
	ios_base::sync_with_stdio(0); 
    cin.tie(0);

    int n,m;
    cin >> n >> m;

    for(int i = 0; i<m; i++)
    {
        int a,b,c;
        cin >> a >> b >> c;

        edge.push_back({c,{a,b}});
    }

    int start = 0;
    int end = INF;
    int res = 0;
    while(start<=end)
    {
        int mid = (start+end)/2;

        if(check(n,mid))
        {
            start = mid+1;
            res = mid;
        }
        else
            end = mid-1;
    }

    for(int i = 0; i<m; i++)
    {
        if(edge[i].first >= res)
        {
            int a = edge[i].second.first;
            int b = edge[i].second.second;
            graph[a].push_back(b);
            graph[b].push_back(a);
        }
    }

    vector<int> vis(n+1,-1);
    queue<int> q;
    q.push(1);
    vis[1] = 0;
    int mx = 0;
    while(!q.empty())
    {
        int x = q.front();
        q.pop();
        mx = max(mx,vis[x]);
        for(int y : graph[x])
        {
            if(vis[y] != -1)
                continue;
            vis[y] = vis[x]+1;
            q.push(y);
        }
    }

    cout << res << " " << mx << endl;
    return 0;
}
0