Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- #include <string>
- #include <algorithm>
- #include <vector>
- #include <cmath>
- #include <iomanip>
- #include <map>
- #include <cstring>
- #include <set>
- #include <stack>
- #include <bitset>
- #define ll long long
- #define INF (1e9)
- #define MAX (int) (2e5 + 5)
- #define MOD 1000000007
- #define par pair<int, int>
- #define all(v) v.begin(), v.end()
- #define sz(x) (int) ((x).size())
- #define esq(x) (x<<1)
- #define dir(x) ((x<<1)|1)
- #define lsb(x) (x & -x)
- #define W(x) cout << #x << ": " << x << endl
- #define Wii(x) cout << x.first << ' ' << x.second << endl
- #define _ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
- using namespace std;
- struct tpoint
- {
- double x, y, r;
- };
- tpoint arr[MAX];
- int n, q, a, b;
- double dist[1000][1000];
- int main()
- {_
- while (cin >> n && n)
- {
- for (int i = 1; i <= n; i++)
- cin >> arr[i].x >> arr[i].y >> arr[i].r;
- for (int i = 1; i <= n; i++)
- {
- for (int j = 1; j <= n; j++)
- {
- double d = hypot(arr[i].x-arr[j].x, arr[i].y-arr[j].y);
- dist[i][j] = (arr[i].r >= d ? d : INF);
- }
- }
- for (int i = 1; i <= n; i++)
- for (int j = 1; j <= n; j++)
- for (int k = 1; k <= n; k++)
- dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
- cin >> q;
- while (q--)
- {
- cin >> a >> b;
- cout << (dist[a][b] != INF ? (int) dist[a][b] : -1) << endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement