diff --git a/category-cycles/find_cycles.cpp b/category-cycles/find_cycles.cpp index 460a482..bb21de1 100644 --- a/category-cycles/find_cycles.cpp +++ b/category-cycles/find_cycles.cpp @@ -17,28 +17,28 @@ unordered_map edgeTo; bool first = true; void dfs(int v) { - visited.insert(v); - onStack.insert(v); - for (int i : graph[v]) { - if (visited.find(i) == visited.end()) { // unvisited - edgeTo[i] = v; - dfs(i); - } else if (onStack.find(i) != onStack.end()) { - if (first) { - cout << "["; - first = false; - } else { - cout << ",["; - } - int x = v; - while (x != i) { - cout << x << ","; - x = edgeTo[x]; - } - cout << i << "]"; - } - } - onStack.erase(onStack.find(v)); + visited.insert(v); + onStack.insert(v); + for (int i : graph[v]) { + if (visited.find(i) == visited.end()) { // unvisited + edgeTo[i] = v; + dfs(i); + } else if (onStack.find(i) != onStack.end()) { + if (first) { + cout << "["; + first = false; + } else { + cout << ",["; + } + int x = v; + while (x != i) { + cout << x << ","; + x = edgeTo[x]; + } + cout << i << "]"; + } + } + onStack.erase(onStack.find(v)); } int main() { @@ -46,27 +46,27 @@ int main() { ios_base::sync_with_stdio(0); cin.tie(0); - int parent, sub; - while (1) { - cin >> sub; - if (sub == -1) { // end of input - break; - } - cin >> parent; + int parent, sub; + while (1) { + cin >> sub; + if (sub == -1) { // end of input + break; + } + cin >> parent; - // Build adjacency list representation - graph[parent].insert(sub); - } - // cout << "Finished generating subcategory graph...\n"; + // Build adjacency list representation + graph[parent].insert(sub); + } + // cout << "Finished generating subcategory graph...\n"; - cout << "["; + cout << "["; - // Begin DFS - for (auto p: graph) { - if (visited.find(p.first) == visited.end()) { - dfs(p.first); - } - } + // Begin DFS + for (auto p: graph) { + if (visited.find(p.first) == visited.end()) { + dfs(p.first); + } + } - cout << "]"; + cout << "]"; } diff --git a/category-cycles/prettify.js b/category-cycles/prettify.js index 9ff82db..9f63e0a 100644 --- a/category-cycles/prettify.js +++ b/category-cycles/prettify.js @@ -9,7 +9,7 @@ const {bot, log} = require('../botbase'); const PAGE_SIZE_MAX_LIMIT = 60000; const MAX_PAGES = 100; const ROOT_PAGE = process.env.ROOT_PAGE || 'User:SDZeroBot/Category cycles'; -const PAGE_LEAD = `{{${ROOT_PAGE}/header}}\n`; +const PAGE_LEAD = '{{' + ROOT_PAGE + '/header}}\n'; process.chdir(__dirname); @@ -56,16 +56,15 @@ let cycles = require('./cycles.json').sort((a, b) => a.length - b.length); } } - const wiki_page_name = num => `${ROOT_PAGE}/${num}` - let pageNumber = 1; let page = PAGE_LEAD; for (let cycle of cycles) { page += '*' + cycle.map(e => `[[:Category:${map[e]}|${map[e]}]]`).join(' → ') + '\n'; if (page.length > PAGE_SIZE_MAX_LIMIT) { - await bot.save(wiki_page_name(pageNumber), page, 'Updating category cycles'); - log(`[+] Saved ${wiki_page_name(pageNumber)}`); + const pageName = ROOT_PAGE + '/' + pageNumber; + await bot.save(pageName, page, 'Updating category cycles'); + log(`[+] Saved ${pageName}`); pageNumber++; page = PAGE_LEAD; if (pageNumber > MAX_PAGES) {