QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#699218 | #6772. Spicy Restaurant | jkliao# | WA | 316ms | 9160kb | C++17 | 1.3kb | 2024-11-02 06:21:29 | 2024-11-02 06:21:30 |
Judging History
answer
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
using pii = pair<int, int>;
int main() {
int n, m, q;
cin >> n >> m >> q;
vector<vector<int>> restsbyval(101);
vector<int> rests(n + 1);
for (int i = 1; i <= n; i++) {
int w;
cin >> w;
rests[i] = w;
restsbyval[w].push_back(i);
}
vector<vector<int>> graph(n + 1);
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
graph[u].push_back(v);
graph[v].push_back(u);
}
vector<vector<pii>> toursbyval(101);
vector<int> ans(q);
for (int i = 0; i < q; i++) {
int p, a;
cin >> p >> a;
toursbyval[a].push_back({i, p});
}
queue<int> bq;
for (int w = 1; w <= 100; w++) {
vector<bool> visited(n + 1);
vector<int> dists(n + 1, -1);
for (int u : restsbyval[w]) {
bq.push(u);
visited[u] = true;
dists[u] = 0;
}
queue<int> qu(bq);
while (!qu.empty()) {
int u = qu.front();
qu.pop();
for (int v : graph[u]) {
if (visited[v])
continue;
dists[v] = dists[u] + 1;
visited[v] = true;
qu.push(v);
}
}
for (auto x : toursbyval[w]) {
ans[x.first] = dists[x.second];
}
}
for (int x : ans)
cout << x << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3648kb
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
Wrong Answer
time: 316ms
memory: 9160kb
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 ...
output:
0 7 5 4 -1 6 4 4 -1 6 6 5 5 3 5 5 7 4 6 5 7 4 5 6 4 7 6 5 6 5 5 6 4 5 -1 0 5 6 6 -1 6 6 7 -1 6 5 6 0 6 6 7 6 5 6 4 5 7 6 7 7 6 5 -1 5 5 6 6 8 6 5 5 6 5 5 6 6 6 6 6 7 6 -1 5 4 6 5 7 7 6 7 5 6 0 5 -1 6 6 8 7 -1 6 5 5 5 7 5 4 7 4 5 5 7 8 5 7 -1 4 -1 6 6 4 6 5 -1 8 -1 7 7 6 6 0 5 7 5 7 5 5 0 5 7 -1 5 7 ...
result:
wrong answer 2nd lines differ - expected: '8', found: '7'