➕ Upload the memories
This commit is contained in:
9
processing-parts/data.in
Normal file
9
processing-parts/data.in
Normal file
@@ -0,0 +1,9 @@
|
||||
3 2 6
|
||||
1 2
|
||||
2 3
|
||||
1 1
|
||||
2 1
|
||||
3 1
|
||||
1 2
|
||||
2 2
|
||||
3 2
|
60
processing-parts/main.cc
Normal file
60
processing-parts/main.cc
Normal file
@@ -0,0 +1,60 @@
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
|
||||
using namespace std;
|
||||
|
||||
const int MAXN = 10005;
|
||||
|
||||
vector<int> graph[MAXN];
|
||||
bool visited[MAXN];
|
||||
int dis_odd[MAXN], dis_even[MAXN];
|
||||
|
||||
void find_shortest_path() {
|
||||
memset(dis_even, 0x3f, sizeof dis_even);
|
||||
memset(dis_odd, 0x3f, sizeof dis_odd);
|
||||
queue<pair<int, int>> q;
|
||||
for (int &i: graph[1]) {
|
||||
dis_odd[i] = 1;
|
||||
q.emplace(i, 1);
|
||||
}
|
||||
while (!q.empty()) {
|
||||
int x = q.front().first, y = q.front().second;
|
||||
for (int &i: graph[x]) {
|
||||
if (y % 2 == 0) {
|
||||
if (y + 1 < dis_odd[i]) {
|
||||
dis_odd[i] = y + 1;
|
||||
q.emplace(i, y + 1);
|
||||
}
|
||||
} else {
|
||||
if (y + 1 < dis_even[i]) {
|
||||
dis_even[i] = y + 1;
|
||||
q.emplace(i, y + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
q.pop();
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
int n, m, q;
|
||||
cin >> n >> m >> q;
|
||||
for (int i = 0; i < m; i++) {
|
||||
int u, v;
|
||||
cin >> u >> v;
|
||||
graph[u].push_back(v);
|
||||
graph[v].push_back(u);
|
||||
}
|
||||
find_shortest_path();
|
||||
while (q--) {
|
||||
int u, v;
|
||||
cin >> u >> v;
|
||||
if (v % 2 == 0) {
|
||||
if (dis_even[u] > v) cout << "No" << endl;
|
||||
else cout << "Yes" << endl;
|
||||
} else {
|
||||
if (dis_odd[u] > v) cout << "No" << endl;
|
||||
else cout << "Yes" << endl;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user