From 809517eb384f5f104f6487e899d03069f3f9e9b7 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Mon, 23 May 2022 01:23:16 +0800 Subject: [PATCH] D - Circular Spanning Tree https://codeforces.com/contest/1682/submission/158080863 --- Codeforces/1682/D/D.cpp | 54 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Codeforces/1682/D/D.cpp diff --git a/Codeforces/1682/D/D.cpp b/Codeforces/1682/D/D.cpp new file mode 100644 index 00000000..f3684b5c --- /dev/null +++ b/Codeforces/1682/D/D.cpp @@ -0,0 +1,54 @@ +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +int t, n; +std::string s; + +inline int pre(int x) { + return x == 1 ? n : x - 1; +} + +inline int nxt(int x) { + return x == n ? 1 : x + 1; +} + +int main() { + std::ios::sync_with_stdio(false); + + cin >> t; + + while (t--) { + int cnt = 0; + + cin >> n >> s; + + for (char c : s) { + if (c == '1') cnt++; + } + + if (!cnt || (cnt & 1)) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + + int lst = 0; + for (int i = 1; i <= n; i++) { + if (s[i - 1] == '1') lst = nxt(i); + } + + for (int i = nxt(lst); i != lst; i = nxt(i)) { + if (i == nxt(lst) || s[pre(i) - 1] == '1') { + cout << lst << ' ' << i << endl; + } else { + cout << pre(i) << ' ' << i << endl; + } + } + } + } + + return 0; +}