QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#672254 | #6772. Spicy Restaurant | ACAAA# | TL | 0ms | 9904kb | C++23 | 1.0kb | 2024-10-24 16:10:14 | 2024-10-24 16:10:15 |
Judging History
answer
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
const int N = 5e5 + 10, M = 105;
int n, m,t, w[N],vis[N],dist[N][M];
vector<int>a[N];
void bfs(int val) {
queue<int>q;
for (int i = 1; i <= n; i++) {
vis[i] = 0;
dist[i][val] = 1e9;
if (w[i] == val) {
dist[i][val] = 0;
q.push(i);
}
}
while (!q.empty()) {
int u = q.front();
q.pop();
if (vis[u])continue;
vis[u] = 1;
for (int i = 0; i < a[u].size(); i++) {
int v = a[u][i];
if (!vis[v] && dist[v][val] > dist[u][val] + 1) {
dist[v][val] = dist[u][val] + 1;
q.push(v);
}
}
}
}
int main() {
cin >> n >> m >> t;
for (int i = 1; i <= n; i++)
cin >> w[i];
for (int i = 1; i <= m; i++) {
int u, v;
cin >> u >> v;
a[u].push_back(v);
a[v].push_back(u);
}
for (int i = 1; i <= n; i++)
bfs(i);
while (t--) {
int pos, k;
cin >> pos >> k;
int ans = 1e9;
for (int i = 1; i <= k; i++)
ans = min(ans, dist[pos][i]);
if (ans == 1e9)cout << "-1\n";
else cout << ans << "\n";
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 9904kb
input:
4 4 5 5 4 2 3 1 2 2 3 3 4 4 1 1 1 1 2 1 3 1 4 1 5
output:
-1 2 1 1 0
result:
ok 5 lines
Test #2:
score: -100
Time Limit Exceeded
input:
50000 100000 100000 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 ...