Choose Your Own Adventure asks to construct a directed story graph from the stated numbers of scenes and endings; the code produces that required construction.
Graphs & trees
Problem and code
Useful links.
Written by benbenyaojifen. Try the problem first, then compare your approach with the code.
1#include <bits/stdc++.h>2usingnamespace std;3using ll =longlong;4using i128 = __int128;5constint inf =1e9;6const ll INF=1e18; //❄️7intmain() {8 ios::sync_with_stdio(0); cin.tie(0); 9int n, m; cin >> n >> m;10if (m > n +1) {11 cout <<-1<<'\n';12return0;13 }14constint mod = n + m +1;15int x =1;16for (int i =0; i < n; i++) {17int a =++x, b =++x;18 a %= mod; b %= mod;19if (a ==0) a +=2;20if (a ==1) a++;21if (b ==0) b +=3;22if (b ==1) b++;23if (a == b) a++;24if (a == i +1) a++;25if (b == i +1) b++;26 cout << a <<" "<< b <<'\n';27 }28return0;29}
☕
Did this explanation save you time? I'm a Grade 11 student building this free library to make difficult algorithms easier to understand.
Python records executed lines and locals automatically. For selected values in any language, add // @trace i, total on its own valid line; Python uses # @trace i, total.
StatusReady
Output
No run yet.
Diagnostics
No diagnostics yet.
Each run is isolated and has strict limits. Passing one test does not guarantee the judge will accept the solution.