-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path80.cpp
More file actions
144 lines (126 loc) · 3.37 KB
/
80.cpp
File metadata and controls
144 lines (126 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#pragma warning(disable:4996)
#include <iostream>
#include <cstdint>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <unordered_set>
#include <unordered_map>
using namespace std;
#define pw(a) ((a) * (a))
#define vit vector<int>::iterator
#define sit set<int>::iterator
#define dqit deque<int>::iterator
#define FILE_IO {freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);}
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(NULL), cout.tie(NULL)
#define sortRev greater<int>()
const double pi = 3.14159265359;
const long long mod = 1e9 + 7;
typedef uint64_t uit;
typedef long long ll;
typedef long long int lli;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<double, int> pdi;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> p2ll;
typedef pair<string, int> psi;
typedef pair<ld, ld> p2ld;
typedef pair<char, char> pcc;
typedef pair<ll, string> plls;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<string> vstr;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pdi> vpdi;
typedef vector<p2ll> vp2ll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<long long>> vvll;
typedef vector<vector<pii>> vvpii;
typedef vector<vector<vector<int>>> vvvi;
typedef deque<int> dqi;
typedef queue<int> qi;
typedef queue<pii> qpii;
int GCD(int a, int b) { return !b ? a : GCD(b, a % b); }
inline double DIST(const pii& a, const pii& b) { return sqrt(pw((double)(a.first - b.first)) + pw((double)(a.second - b.second))); }
inline int DEC(char x) { return (int)(x - '0'); }
/*__________________________________________________________________________________________________________________________
http://www.lightoj.com/volume_showproblem.php?problem=1074
____________________________________________________________________________________________________________________________*/
const int INF = 1e9;
typedef struct Node {
int src;
int des;
int wgt;
Node(int _src, int _des, int _wgt) {
src = _src;
des = _des;
wgt = _wgt;
}
} Node;
int V, E;
int weight[205];
vector<Node> grp;
inline int calcDist(int u, int v) {
return pow(weight[v] - weight[u], 3.0);
}
inline void BellMan_Ford(int source, vi &dist) {
dist.resize(V + 5, INF);
dist[source] = 0;
for (int i = 1; i < V; ++i) {
for (int j = 0; j < E; ++j) {
int u = grp[j].src;
int v = grp[j].des;
int w = grp[j].wgt;
if (dist[u] != INF && dist[u] + w < dist[v]) {
dist[v] = dist[u] + w;
}
}
}
}
int main() {
FAST_IO;
//FILE_IO;
int tc, cs = 1;
cin >> tc;
while (tc--) {
cin >> V;
for (int i = 1; i <= V; ++i) {
cin >> weight[i];
}
cin >> E;
for (int u, v, i = 0; i < E; ++i) {
cin >> u >> v;
grp.push_back(Node(u, v, calcDist(u, v)));
}
vector<int> dist;
BellMan_Ford(1, dist);
int q, v;
cin >> q;
cout << "Case " << cs++ << ":" << endl;
while (q--) {
cin >> v;
if (dist[v] != INF && dist[v] >= 3) {
cout << dist[v] << endl;
}
else {
cout << "?" << endl;
}
}
grp.clear();
}
return 0;
}