結果

問題 No.3057 Tree Distance Set
ユーザー pockyny
提出日時 2025-07-12 04:33:00
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 851 bytes
コンパイル時間 1,074 ms
コンパイル使用メモリ 85,940 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-07-12 04:33:03
合計ジャッジ時間 2,315 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
int main(){
    int i,k; cin >> k;
    vector<int> d(k);
    for(i=0;i<k;i++) cin >> d[i];
    sort(d.rbegin(),d.rend());
    vector<pair<pair<int,int>,int>> ans;
    vector<int> s;
    int l = d[0]/2,idx = 4,c = 1;
    ans.push_back({{c,2},l});
    ans.push_back({{c,3},l});
    s.push_back(2); s.push_back(3);
    for(i=1;i<k;i++){
        ans.push_back({{c,idx},l - d[i]/2});
        ans.push_back({{idx,idx + 1},d[i]/2});
        ans.push_back({{idx,idx + 2},d[i]/2});
        s.push_back(idx + 1); s.push_back(idx + 2);
        idx += 3;
    }
    cout << idx - 1 << "\n";
    for(auto [uv,w]:ans){
        auto [u,v] = uv;
        cout << u << " " << v << " " << w << "\n";
    }
    cout << s.size() << "\n";
    for(int x:s) cout << x << " ";
    cout << "\n";
}
0