# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
846475 | 2023-09-07T15:24:54 Z | serifefedartar | Konstrukcija (COCI20_konstrukcija) | C++17 | 0 ms | 0 KB |
#include <bits/stdc++.h> using namespace std; #define fast ios::sync_with_stdio(0);cin.tie(0); #define s second #define f first typedef long long ll; const ll MOD = 998244353; const ll LOGN = 20; const ll MAXN = 3e5 + 5; int N = 1; vector<pair<int,int>> edges; vector<int> nodes_now; void addEdge(int cnt, bool root) { vector<int> new_nodes; if (root) { edges.push_back({1, N+1}); nodes_nows.push_back(N+1); N++; } for (int i = N+1; i <= N+cnt; i++) new_nodes.push_back(i); N += cnt; for (auto u : nodes_now) { for (auto to : new_nodes) edges.push_back({u, to}); } nodes_now = new_nodes; } void minus1() { addEdge(2, false); } void minus2() { addEdge(3, false); } void minusSp1() { addEdge(1, true); } int main() { fast ll K; cin >> K; ll now = 0; nodes_now.push_back(1); for (int i = 63; i >= 0; i--) { if ((1<<i) & K) { minusSp1(); now = 1 - now; } if (i != 0) { minus2(); now *= -2; } if (now > 0) { minus1(); now = -now; } } if (!((now < 0 && K > 0) || (now > 0 && K < 0))) minus1(); addEdge(1, 0); cout << N << " " << edges.size() << "\n"; for (auto u : edges) cout << u.f << " " << u.s << "\n"; }