/** * author: Misodango * cd `acc config-dir` * この問題を A☆C して †予選突破† させていただきますぞ!wwww **/ // clang-format off #include #include #include using namespace std; using namespace atcoder; /* accelration */ // 高速バイナリ生成 #pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") /* alias */ using ull = unsigned long long; using ll = long long; using vi = vector; using vl = vector; using vll = vector; using vvi = vector; using vvl = vector; using vvll = vector; using vs = vector; using pii = pair; using pll = pair; /* define short */ #define pb push_back #define fi first #define se second #define all(obj) (obj).begin(), (obj).end() #define rall(obj) (obj).rbegin(), (obj).rend() #define YESNO(bool) if(bool){cout<<"YES"<m_parentsOrSize;}; struct segment_tree {int n;vector node_min;vector node_max;segment_tree(int n): n(n), node_min(n << 1, INT_MAX), node_max(n << 1, INT_MIN) {}void set(int i, int x) {node_min[i += n] = x;node_max[i] = x;while (i >>= 1) {node_min[i] = min(node_min[i << 1], node_min[i << 1 | 1]);node_max[i] = max(node_max[i << 1], node_max[i << 1 | 1]);}}int min_fold(int l, int r) {int res = INT_MAX;for (l += n, r += n; l < r; l >>= 1, r >>= 1) {if (l & 1)res = min(res, node_min[l++]);if (r & 1)res = min(node_min[--r], res);}return res;}int max_fold(int l, int r) {int res = INT_MIN;for (l += n, r += n; l < r; l >>= 1, r >>= 1) {if (l & 1)res = max(res, node_max[l++]);if (r & 1)res = max(node_max[--r], res);}return res;}}; /* MIN MAX macro */ template constexpr auto min(T ... a){return min(initializer_list>{a...});} template constexpr auto max(T ... a){return max(initializer_list>{a...});} template inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); } template inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); } /* INPUT macro */ template void input(T&... a){(cin >> ... >> a);} inline void scan(){} template inline void scan(Head&head,Tail&... tail){std::cin>>head;scan(tail...);} #define LL(...) ll __VA_ARGS__;scan(__VA_ARGS__) #define STR(...) string __VA_ARGS__;scan(__VA_ARGS__) #define cerr cerr << "\033[33m" #ifdef LOCAL #include #define debug(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__) #else #define debug(...) (static_cast(0)) #endif // clang-format on int main() { LL(n, m, q); vi a(n), u(m), v(m), w(m); rep(i, n) { cin >> a[i]; a[i]--; } vector EdgeList; rep(i, m) { cin >> u[i] >> v[i] >> w[i]; u[i]--, v[i]--; EdgeList.pb({w[i], i}); } sort(all(EdgeList)); UnionFind uf(n); // {行先, weight} vector> g(n); for (auto [weight, idx] : EdgeList) { if (uf.same(u[idx], v[idx])) continue; uf.unite(u[idx], v[idx]); g[u[idx]].pb({v[idx], weight}); g[v[idx]].pb({u[idx], weight}); } rep(_, q) { int s, c; cin >> s >> c; s--; // sから各頂点へ行くために必要な巡礼度 vi need(n, -1); need[s] = 0; queue que; que.push(s); while (!que.empty()) { int x = que.front(); que.pop(); for (auto [to, weight] : g[x]) { if (need[to] != -1) continue; need[to] = max(need[x], weight); que.push(to); } } const int INF = 1e9 + 10; vi best(n, INF); rep(v, n) { chmin(best[a[v]], need[v]); } vi vals; rep(type, n) { if (best[type] != INF) { vals.pb(best[type]); } } if ((int)vals.size() < c) { cout << -1 << '\n'; continue; } sort(all(vals)); cout << vals[c - 1] << '\n'; } }