結果
| 問題 |
No.3057 Tree Distance Set
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-03-14 22:08:33 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 780 bytes |
| コンパイル時間 | 2,578 ms |
| コンパイル使用メモリ | 207,148 KB |
| 実行使用メモリ | 7,328 KB |
| 最終ジャッジ日時 | 2025-03-14 22:08:37 |
| 合計ジャッジ時間 | 3,452 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 20 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int K; cin >> K;
vector<int> D(K);
for(auto &d : D) cin >> d;
sort(D.begin(),D.end());
int d0 = D.at(0); D.erase(D.begin());
vector<int> S = {0,2};
vector<tuple<int,int,int>> edge;
edge = {{0,1,d0/2},{1,2,d0/2}};
int bring = d0/2,cent = 1;
for(auto d : D){
S.push_back(cent+3);
edge.push_back({cent,cent+2,d/2-bring});
edge.push_back({cent+2,cent+3,d/2});
cent += 2; bring = d/2;
}
cout << edge.size()+1 << "\n";
for(auto [u,v,w] : edge) cout << u+1 << " " << v+1 << " " << w << "\n";
cout << S.size() << "\n";
for(auto &s : S) cout << s+1 << " "; cout << endl;
}