結果
問題 | No.1523 +/- Tree |
ユーザー | 👑 Nachia |
提出日時 | 2021-05-13 23:29:29 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 5 ms / 2,000 ms |
コード長 | 975 bytes |
コンパイル時間 | 1,245 ms |
コンパイル使用メモリ | 75,676 KB |
最終ジャッジ日時 | 2025-01-21 10:44:23 |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 44 |
ソースコード
#include <iostream> #include <vector> #include <algorithm> using namespace std; using ll = long long; using ull = unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) struct Edge{ int u,v,d; }; int N, K; vector<Edge> ans; int main(){ cin >> N >> K; if(K == 1){ cout << "No\n"; return 0; } if(K == N-1){ cout << "No\n"; return 0; } if(K == 2){ if(N%2 == 1){ cout << "No\n"; return 0; } for(int i=2; i<=N; i++){ if(i%2==0) ans.push_back({i-1,i,999'999'999}); else ans.push_back({i-1,i,-1'000'000'000}); } } else{ for(int i=1; i<=K-2; i++) ans.push_back({i,i+1,0}); ans.push_back({K-1,K,-1'000'000'000}); for(int i=K+1; i<=N; i++) ans.push_back({K,i,999'999'999}); } cout << "Yes\n"; for(auto e : ans){ cout << e.u << " " << e.v << " " << e.d << "\n"; } return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ ios::sync_with_stdio(false); cin.tie(nullptr); } } ios_do_not_sync_instance;