CCCPaste

Untitled

#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
typedef long long ll;
const int maxn = 3005;
vector graph[maxn];
bool visited[maxn][maxn];
int main() {
    ios_base::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    
    for(int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    int k;
    cin >> k;
    map, bool> triplets;
    for(int i = 0; i < k; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        triplets[{a, b, c}] = true;
    }
    
    queue q;
    q.push(0);
    q.push(-1);
    q.push(0);
    while(!q.empty()) {
        int current_node = q.front(); q.pop();
        int prev_node = q.front(); q.pop();
        int cekor = q.front(); q.pop();
        
        if(current_node == n - 1) {
            cout << cekor << endl;
            return 0;
        }
        for(int i = 0; i < (int) graph[current_node].size(); i++) {
            int neighbour = graph[current_node][i];
            if(!triplets[{prev_node, current_node, neighbour}] and !visited[current_node][neighbour]) {
                visited[current_node][neighbour] = true;
                q.push(neighbour);
                q.push(current_node);
                q.push(cekor + 1);
            }
            
        }
    }
    cout << "GRESHKA" << endl;
    
    return 0;
}