QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#411381 | #6765. Don't Really Like How The Story Ends | ChongQY | WA | 1ms | 5964kb | C++23 | 2.1kb | 2024-05-15 12:27:44 | 2024-05-15 12:27:45 |
Judging History
answer
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <map>
#include <unordered_set>
#include <unordered_map>
#define x first
#define y second
#define IOS ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 110, M = 100010, MOD = 1000000007, INF = 0x3f3f3f3f;
int n, m, q;
int e[2 * M], ne[2 * M], h[M], idx;
int w[M];
int dist[M][N]; //dist[i][j]表示距离i最近的属性值恰好为j的点的距离
bool st[M];
void add(int a, int b)
{
e[idx] = b, ne[idx] = h[a], h[a] = idx++;
}
void bfs(int v)
{
memset(st, 0, sizeof st);
queue<int> q;
for (int i = 1; i <= n; i++)
if (w[i] == v)
{
q.push(i);
st[i] = true;
dist[i][v] = 0;
}
while (!q.empty())
{
auto t = q.front();
q.pop();
for (int i = h[t]; i != -1; i = ne[i])
{
int j = e[i];
if (st[j])
continue;
st[j] = true;
dist[j][v] = dist[t][v] + 1;
q.push(j);
}
}
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
memset(h, -1, sizeof h);
cin >> n >> m >> q;
for (int i = 1; i <= n; i++)
cin >> w[i];
while (m--)
{
int a, b;
cin >> a >> b;
add(a, b), add(b, a);
}
for (int i = 1; i <= n; i ++ )
for (int j = 1; j <= 100; j ++ )
dist[i][j] = INF; //注意dist的初始化不能在bfs里面,且memset会超时
for (int i = 1; i <= 100; i++)
bfs(i);
while (q--)
{
int cur, v;
cin >> cur >> v;
int res = INF;
for (int i = 1; i <= v; i++)
res = min(res, dist[cur][i]);
if (res == INF)
cout << -1 << endl;
else
cout << res << endl;
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5964kb
input:
3 2 3 1 1 1 2 2 1 4 1 1 4 4 2 1 2 3 4
output:
0 0 0
result:
wrong answer 2nd lines differ - expected: '2', found: '0'