結果

問題 No.3756 Udon Network
ユーザー ooaiu
提出日時 2026-10-09 18:55:29
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
RE  
実行時間 -
コード長 1,150 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,180 ms
コンパイル使用メモリ 352,284 KB
実行使用メモリ 16,728 KB
最終ジャッジ日時 2026-10-09 18:55:57
合計ジャッジ時間 24,765 ms
ジャッジサーバーID
(参考情報)
judge4_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
サブタスク 配点 結果
Example 0 % AC * 8
Subtask $1$ 2 % AC * 15
Subtask $2$ 4 % AC * 22
Subtask $3$ 8 % AC * 3 RE * 6
Subtask $4$ 16 % AC * 2 RE * 8
Subtask $5$ 32 % AC * 3 RE * 7
Subtask $6$ 38 % AC * 22 RE * 31
合計 4 * 6% = 24 点
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
using ll = long long; 
#define rep(i, n) for (int i = 0; i < (n); i++)
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N, M, Q;
	cin >> N >> M >> Q;
	vector<int> A(N);
	rep(i, N) cin >> A[i];
	vector<vector<pair<int,int>>>G(N);
	rep(i, M) {
		int a, b, c;
		cin >> a >> b >> c;
		a--, b--;
		G[a].push_back({b,c});
		G[b].push_back({a,c});
	}
	if (N <= 1000 && M <= 1000 && Q <= 5000) {
		rep(qi, Q) {
			int s, c;
			cin >> s >> c;
			s--;
			auto check = [&](int w) {
				queue<int>que;
				que.push(s);
				vector<int> vis(N);
				vis[s] = 1;
				while(que.size()) {
					int v = que.front();que.pop();
					for(auto[u,ww]:G[v]) if(w>=ww && !vis[u]) vis[u]=1,que.push(u); 
				}
				vector<int>ks;
				rep(i,N)if(vis[i]) ks.push_back(A[i]);
				sort(ks.begin(),ks.end());
				ks.erase(unique(ks.begin(),ks.end()),ks.end());
				return ks.size()>=c;
			};
			ll ng = -1, ok = 2e9;
			if (!check(ok)) {
				cout << -1 << "\n";
				continue;
			}
			while(ok-ng>1) {
				ll m = (ok + ng) / 2;
				(check(m) ? ok : ng) = m;
			}
			cout << ok << "\n";
		}
		return 0;
	}
	assert(0);
}

0