Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int input(){
- int res = 0; char c = ' ';
- while (c < '0') c = getchar();
- while (c >= '0') res = res * 10 + (c - '0'), c = getchar();
- return res;
- }
- const int N = 1e5 + 1;
- int dst[N];
- vector <int> g[2][N];
- int main(){
- int n = input(), m = input(), t = input();
- for (int i = 0; i < m; ++ i){
- int u = input() - 1, v = input() - 1;
- g[0][u].push_back(v), g[1][v].push_back(u);
- }
- for (int i = 1; i < n; ++ i) dst[i] = 2e9;
- queue <pair <int, int> > q;
- q.push({0, 0});
- while (q.size()){
- int v = q.front().first, d = q.front().second;
- q.pop();
- for (auto u : g[d & 1][v])
- if (dst[u] == 2e9)
- q.push({u, dst[u] = d + 1});
- for (auto u : g[~d & 1][v])
- if (dst[u] == 2e9){
- q.push({v, d + 1});
- break;
- }
- }
- for (int i = 0; i < t; ++ i)
- cout << (dst[n - 1] <= input() ? "GGMU" : "FML") << "\n";
- }
Add Comment
Please, Sign In to add comment