Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma comment(linker, "/STACK:256000000")
- #include <iostream>
- #include <vector>
- #include <ctime>
- using namespace std;
- const int MAXN = 10000000;
- int n, m;
- vector<int> t[MAXN];
- int dfs(int v) {
- if (v == n - 1) {
- return v;
- } else {
- for (int i = 0; i < (int)t[v].size(); i++) {
- int val = dfs(t[v][i]);
- if (val != -1) {
- return val;
- }
- }
- return -1;
- }
- }
- void dfs2(int v) {
- if (v == n - 1) {
- throw v;
- } else {
- for (int i = 0; i < (int)t[v].size(); i++) {
- dfs2(t[v][i]);
- }
- }
- }
- int main() {
- cin >> n >> m;
- for (int i = 0; i < n - 1; i++) {
- t[i].push_back(i + 1);
- }
- clock_t start = clock();
- int dummy = 0;
- for (int i = 0; i < m; i++) {
- dummy += dfs(0);
- }
- cout << clock() - start << endl;
- start = clock();
- for (int i = 0; i < m; i++) {
- try {
- dfs2(0);
- } catch (int val) {
- dummy += val;
- }
- }
- cout << clock() - start << endl;
- cout << dummy << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement