#include <bits/stdc++.h>
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define sz(v) int(v.size())
#define all(v) v.begin(), v.end()
#define vec vector<int>
#define dead not_bad
#define left not_right
#define y1 what
using namespace std;
const int N = (int) 3e4 + 10;
const int M = (int) 2e4 + 10;
const ll LINF = (ll) 1e18;
const int INF = (int) 1e9 + 7;
const double PI = 3.14159265359;
const double EPS = (double) 1e-9;
int nx[8] = {-1, -2, -2, -1, 1, 1, 2, 2};
int ny[8] = {-2, -1, 1, 2, -2, 2, -1, 1};
int n, m;
int b[N], p[N];
int d[N];
bool u[N];
set v[N];
int main() {
#define fn "teams"
#ifdef witch
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#else
//freopen(fn".in", "r", stdin);
//freopen(fn".out", "w", stdout);
#endif
cin >> n >> m;
for (int i = 0; i < N; i++) {
d[i] = INF;
}
for (int i = 0; i < m; i++) {
cin >> b[i] >> p[i];
v[b[i]].insert(i);
}
//if (n <= m) {
d[b[0]] = 0;
for (int iter = 1; iter < n; iter++) {
int id = -1;
for (int i = 0; i < n; i++) {
if (!u[i] && (id == -1 || d[id] > d[i])) {
id = i;
}
}
if (id == -1 || d[id] == INF)
break;
if (id == b[1])
break;
u[id] = 1;
for (auto it : v[id]) {
for (int x = id, step = 0; x < n; x += p[it], ++step) {
if (d[id] + step < d[x]) {
d[x] = d[id] + step;
}
}
for (int x = id, step = 0; x >= 0; x -= p[it], ++step) {
if (d[id] + step < d[x]) {
d[x] = d[id] + step;
}
}
}
}
if (d[b[1]] == INF) d[b[1]] = -1;
cout << d[b[1]];
return 0;
//}
d[0] = 0;
for (int iter = 1; iter < m; iter++) {
int id = -1;
for (int i = 0; i < m; i++) {
if (!u[i] && (id == -1 || d[id] > d[i])) {
id = i;
}
}
if (id == -1 || d[id] == INF)
break;
if (id == 1)
break;
u[id] = 1;
v[b[id]].erase(id);
for (int x = b[id], step = 0; x < n; x += p[id], ++step) {
for (auto it : v[x]) {
if (d[id] + step < d[it]) {
d[it] = d[id] + step;
}
}
}
for (int x = b[id], step = 0; x >= 0; x -= p[id], ++step) {
for (auto it : v[x]) {
if (d[id] + step < d[it]) {
d[it] = d[id] + step;
}
}
}
}
if (d[1] == INF)
d[1] = -1;
cout << d[1];
return 0;
}
Compilation message
skyscraper.cpp:34:1: error: invalid use of template-name 'std::set' without an argument list
set v[N];
^
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:51:5: error: 'v' was not declared in this scope
v[b[i]].insert(i);
^
skyscraper.cpp:67:22: error: 'v' was not declared in this scope
for (auto it : v[id]) {
^
skyscraper.cpp:97:5: error: 'v' was not declared in this scope
v[b[id]].erase(id);
^