#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>
#include <limits.h>

typedef struct node {
    int id;
    struct node * next;
} Node;

typedef struct {
    Node * front, * rear;
} Queue;

Queue * Initialize() {
    Queue * q = (Queue *) malloc(sizeof(Queue));
    q->front = q->rear = NULL;
    return q;
}

int isEmpty(Queue * q) {
    return (q->rear == NULL) && (q->front == NULL);
}

Queue * push(Queue * q, int ID) {
    Node * newNode = (Node *) malloc(sizeof(Node));
    newNode->id = ID;
    newNode->next = NULL;
    if(isEmpty(q)) {
        q->front = q->rear = newNode;
    }
    else {
        q->rear->next = newNode;
        q->rear = newNode;
    }
    //printf("Push %d to queue\n", q->rear->id);
    return q;
}

int pop(Queue ** q) {
    if(isEmpty(*q)) {
        return -1;
    }
    else {
        Node * temp = (*q)->front;
        (*q)->front = (*q)->front->next;
        int ret = temp->id;
        //printf("pop %d from queue\n", ret);
        free(temp);
        return ret;
    }
}

typedef struct tree {
    int index;
    struct tree * left, * right;            //for saving visited index
} Tree;

Tree * Insert(Tree * root, int ID) {
    if(root == NULL) {
        root = (Tree *) malloc(sizeof(Tree));
        root->index = ID;
        root->left = root->right = NULL;
    }
    else {
        if(root->index > ID) {
            root->left = Insert(root->left, ID);
        }
        else if(root->index < ID) {
            root->right = Insert(root->right, ID);
        }
    }
    return root;

}

bool Search(Tree * root, int search) {
    if(root == NULL) {
        return false;
    }

    if(root->index == search) {
        return true;
    }
    else if(root->index > search) {
        return Search(root->left, search);
    }
    else {
        return Search(root->right, search);
    }
}

Tree * findMinforDelete(Tree * root) {    //for delete function
    Tree * cur = root;
    while(cur->left != NULL) {
        cur = cur->left;
    }
    return cur;
}

Tree * DeleteNode(Tree * root, int key) {
    if(root == NULL) {  //if nothing to be deleted
        return NULL;
    }
    //
    if(root->index == key) {
        //if root has 0 or 1 child
        if(root->left == NULL) {
            Tree * temp = root->right;
            free(root);
            return temp;
        }
        if(root->right == NULL) {
            Tree * temp = root->left;
            free(root);
            return temp;
        }
        //if root has 2 children
        Tree * temp = findMinforDelete(root->right);
        root->index = temp->index;
        root->right = DeleteNode(root->right, temp->index);

    }
    else if(root->index > key) {
        root->left = DeleteNode(root->left, key);
    }
    else {
        root->right = DeleteNode(root->right, key);
    }
    return root;
}

void test() {
    int n, k;
    scanf("%d %d", &n, &k);
    int ID[200];

    for(int i = 0; i < n; i++) {
        scanf("%d", &ID[i]);
    }

    if(k == 1) {
        printf("1\n%d", ID[n - 1]);
        return;
    }
    else {
        Queue * q = Initialize();
        Tree * visited = NULL;

        int j = 0;
        for(int i = 0; i < n; i++) {
            if(!Search(visited, ID[i])) {
                visited = Insert(visited, ID[i]);
                if(j < k) {
                    q = push(q, ID[i]);
                    j++;
                }
                else if(j == k) {
                    int index = pop(&q);
                    visited = DeleteNode(visited, index);
                    q = push(q, ID[i]);
                }
            }
        }

        printf("%d\n", j);
        int result[j];
        int i = 0;
        for(i = 0; i < j; i++) {
            result[i] = pop(&q);
        }
        for(i = j - 1; i >= 0; i--) printf("%d ", result[i]);
        free(visited);
    }
}

int main ()
{
    // int t;
    // scanf("%d", &t);
    // while(t--)
        test();

    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>
#include <limits.h>

typedef struct node {
    int id;
    struct node * next;
} Node;

typedef struct {
    Node * front, * rear;
} Queue;

Queue * Initialize() {
    Queue * q = (Queue *) malloc(sizeof(Queue));
    q->front = q->rear = NULL;
    return q;
}

int isEmpty(Queue * q) {
    return (q->rear == NULL) && (q->front == NULL);
}

Queue * push(Queue * q, int ID) {
    Node * newNode = (Node *) malloc(sizeof(Node));
    newNode->id = ID;
    newNode->next = NULL;
    if(isEmpty(q)) {
        q->front = q->rear = newNode;
    }
    else {
        q->rear->next = newNode;
        q->rear = newNode;
    }
    //printf("Push %d to queue\n", q->rear->id);
    return q;
}

int pop(Queue ** q) {
    if(isEmpty(*q)) {
        return -1;
    }
    else {
        Node * temp = (*q)->front;
        (*q)->front = (*q)->front->next;
        int ret = temp->id;
        //printf("pop %d from queue\n", ret);
        free(temp);
        return ret;
    }
}

void test() {
    int n, k;
    scanf("%d %d", &n, &k);
    int ID[n];
    Queue * q = Initialize();
    int max = INT_MIN;

    for(int i = 0; i < n; i++) {
        scanf("%d", &ID[i]);
        if(max < ID[i])
            max = ID[i];
    }
    int * visited = (int *) malloc(max * sizeof(int));
    memset(visited, 0, max * sizeof(int));

    int j = 0;
    for(int i = 0; i < n; i++) {
        if(*(visited + (ID[i] - 1)) == 0) {
            *(visited + (ID[i] - 1)) = 1;

            if(j < k) {
                q = push(q, ID[i]);
                j++;
            }
            else if(j == k) {
                int index = pop(&q) - 1;
                *(visited + index) = 0;
                q = push(q, ID[i]);
            }
        }
    }

    printf("%d\n", j);
    int result[j];
    int i = 0;
    for(i = 0; i < j; i++) {
        result[i] = pop(&q);
    }
    for(i = j - 1; i >= 0; i--) printf("%d ", result[i]);
    free(visited);
}

int main ()
{
    // int t;
    // scanf("%d", &t);
    // while(t--)
        test();

    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>
#include <limits.h>

typedef struct node {
    int id;
    struct node * next;
} Node;

typedef struct {
    Node * front, * rear;
} Queue;

Queue * Initialize() {
    Queue * q = (Queue *) malloc(sizeof(Queue));
    q->front = q->rear = NULL;
    return q;
}

int isEmpty(Queue * q) {
    return (q->rear == NULL) && (q->front == NULL);
}

Queue * push(Queue * q, int ID) {
    Node * newNode = (Node *) malloc(sizeof(Node));
    newNode->id = ID;
    newNode->next = NULL;
    if(isEmpty(q)) {
        q->front = q->rear = newNode;
    }
    else {
        q->rear->next = newNode;
        q->rear = newNode;
    }
    //printf("Push %d to queue\n", q->rear->id);
    return q;
}

int pop(Queue ** q) {
    if(isEmpty(*q)) {
        return -1;
    }
    else {
        Node * temp = (*q)->front;
        (*q)->front = (*q)->front->next;
        int ret = temp->id;
        //printf("pop %d from queue\n", ret);
        free(temp);
        return ret;
    }
}

typedef struct tree {
    int index;
    struct tree * left, * right;            //for saving visited index
} Tree;

Tree * Insert(Tree * root, int ID) {
    if(root == NULL) {
        root = (Tree *) malloc(sizeof(Tree));
        root->index = ID;
        root->left = root->right = NULL;
    }
    else {
        if(root->index > ID) {
            root->left = Insert(root->left, ID);
        }
        else if(root->index < ID) {
            root->right = Insert(root->right, ID);
        }
    }
    return root;

}

bool Search(Tree * root, int search) {
    if(root == NULL) {
        return false;
    }

    if(root->index == search) {
        return true;
    }
    else if(root->index > search) {
        return Search(root->left, search);
    }
    else {
        return Search(root->right, search);
    }
}

Tree * findMinforDelete(Tree * root) {    //for delete function
    Tree * cur = root;
    while(cur->left != NULL) {
        cur = cur->left;
    }
    return cur;
}

Tree * DeleteNode(Tree * root, int key) {
    if(root == NULL) {  //if nothing to be deleted
        return NULL;
    }
    //
    if(root->index == key) {
        //if root has 0 or 1 child
        if(root->left == NULL) {
            Tree * temp = root->right;
            free(root);
            return temp;
        }
        if(root->right == NULL) {
            Tree * temp = root->left;
            free(root);
            return temp;
        }
        //if root has 2 children
        Tree * temp = findMinforDelete(root->right);
        root->index = temp->index;
        root->right = DeleteNode(root->right, temp->index);

    }
    else if(root->index > key) {
        root->left = DeleteNode(root->left, key);
    }
    else {
        root->right = DeleteNode(root->right, key);
    }
    return root;
}

void test() {
    int n, k;
    scanf("%d %d", &n, &k);
    int ID[n];

    for(int i = 0; i < n; i++) {
        scanf("%d", &ID[i]);
    }

    if(k == 1) {
        printf("%d", ID[n - 1]);
        return;
    }

    Queue * q = Initialize();
    Tree * visited = NULL;

    int j = 0;
    for(int i = 0; i < n; i++) {
        if(!Search(visited, ID[i])) {
            visited = Insert(visited, ID[i]);
            if(j < k) {
                q = push(q, ID[i]);
                j++;
            }
            else if(j == k) {
                int index = pop(&q);
                visited = DeleteNode(visited, index);
                q = push(q, ID[i]);
            }
        }
    }

    printf("%d\n", j);
    int result[j];
    int i = 0;
    for(i = 0; i < j; i++) {
        result[i] = pop(&q);
    }
    for(i = j - 1; i >= 0; i--) printf("%d ", result[i]);
    free(visited);
}

int main ()
{
    // int t;
    // scanf("%d", &t);
    // while(t--)
        test();

    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>

typedef struct list {
    int id;
    struct list * nextPtr;
} List;

List * AddToFront(List * start, int ID) {
    List *newPtr = (List *) malloc(sizeof(List));
    newPtr->id = ID;
    newPtr->nextPtr = start;
    start = newPtr;

    return start;
}

bool Search(List * start, int ID) {
    List * cur = start;
    while(cur != NULL) {
        if(cur->id == ID) {
            return true;
        }
        cur = cur->nextPtr;
    }
    return false;
}

List * DeleteTail(List * start) {
    if(start == NULL)
        return NULL;

    List * last = start;
    List * prev = start;
    while(last->nextPtr != NULL) {
        prev = last;
        last = last->nextPtr;
    }
    prev->nextPtr = last->nextPtr;
    free(last);
    return start;
}

void test() {
    int n, k;
    scanf("%d %d", &n, &k);
    int ID[n];
    List * start = NULL;
    int j = 0;
    for(int i = 0; i < n; i++) {
        scanf("%d", &ID[i]);

        if(Search(start, ID[i])) {
            continue;
        }

        if(!Search(start, ID[i])) {
            if(j < k) {
                //printf("Go 1, i = %d\n", i);
                start = AddToFront(start, ID[i]);
                j++;
            }
            else {
                start = DeleteTail(start);
                start = AddToFront(start, ID[i]);
            }
        }
    }
    printf("%d\n", j);
    for(List * cur = start; cur != NULL; cur = cur->nextPtr) {
        printf("%d ", cur->id);
    }

}

int main ()
{
    // int t;
    // scanf("%d", &t);
    // while(t--)
        test();

    return 0;
}


#include <stdio.h>
#include <stdlib.h>
int main()
{
	int n, k, i, j, di, floor = 1, now = 1;
	scanf("%d %d", &n, &k);
	int* display;
	display = (int*)malloc((k + n) * sizeof(int));
	for (i = 1; i <= k + n; i++)
		display[i] = 0;

	for (i = 0; i < n; i++)
	{
		scanf("%d", &di);
		int flag = 1;
		for (j = floor; j <= now; j++)
		{
			if (display[j] == di)
				flag = 0;
		}
		if (flag)
		{
			display[now] = di;
			if (now > k)
				floor++;
			now++;
		}
	}
	printf("%d\n", now - floor);
	for (i = now - 1; i >= floor; i--) {
		if (i != floor)
			printf("%d ", display[i]);
		else printf("%d", display[i]);
	}
	return 0;
}


#include <stdio.h>
int main ()
{
    int mess, con, i, j = 0, k, flag = 0;
    scanf("%d%d",&mess,&con);
    long long int a[201] = {0}, id;
    for(i = 0; i < mess; i++)
    {
        scanf("%lld",&id);
        for(k = 1; k <= con; k++)
        {
            if(a[k] == id)
            {
                flag = 1;
                break;
            }
        }
        if(flag == 0)
        {
            for(k = con; k >= 1; k--)
            {
              a[k+1] = a[k];
            }
            a[1] = id;
            j++;
        }
        flag = 0;
        if(j > con)
        {
            j = con;
        }
    }
    printf("%d\n",j);
    for(i = 1; i <= j; i++)
    {
        printf("%lld ",a[i]);
    }
    printf("\n");
    return 0;

}


#include<stdio.h>
#include<malloc.h>
int n, k;
int flag(int item, int *base){
	int i;
	for (i = 0; i < k; i++){
		if (item == base[i])return i + 1;
	}
	return 0;
}
int main(){
	//freopen("in.txt", "r", stdin);
	scanf("%d %d", &n, &k);
	int i,f;
	f = 0;
	int a[205];
	int *b;
	b = (int *)malloc(sizeof(int)*k);
	for (i = 0; i < k; i++){
		b[i] = 0;
	}
	for (i = 0; i < n; i++){
		scanf("%d", &a[i]);
	}
	int j = 0,x;
	for (i = 0; i < n; i++){
		if (!flag(a[i], b)){
			if (j == k){
				for (x = 0; x < k - 1; x++){
					b[x] = b[x + 1];
				}
				b[x] = a[i];
			}
			else{
				b[j++] = a[i];
			}
		}
	}
	printf("%d\n", j);
	for (i = j - 1; i >=0; i--){
		printf("%d ", b[i]);
	}
	return 0;
}


#include <stdio.h>
#define l long int

l swap(l *a, l *b){int t;t=*a;*a=*b;*b=t;}

int main()
{
    int n, k, i, j, x, y, t;
    scanf("%d%d",&n,&k);
    l id[n], ma=0;
    for(i=0;i<n;i++)
    {
        scanf("%ld",&id[i]);
        if(id[i]>ma) ma=id[i];
    }
    ma=ma<k?(ma<n?ma:n):(k<n?k:n);
    int sm[201]={0};
    for(i=0, x=1;i<n;i++, x++)
    {
        y=1;
        for(j=1;j<x;j++)
            if(id[i]==sm[j]){y=0;break;}
        if(y)
        {
            if(x<=ma)
                sm[x]=id[i];
            else
            {
                sm[1]=0;
                for(y=2;y<=ma;y++)
                {
                    t=sm[y-1];sm[y-1]=sm[y];sm[y]=t;
                }

                sm[ma]=id[i];
            }
        }
        else x--;
    }
    printf("%d\n",ma);
    for(i=ma;i>0;i--)
        printf("%ld ",sm[i]);
}


#include<stdio.h>

int main()
{
    int n,k,gf=0;
    scanf("%d%d",&n,&k);
    int id[n],ar[k];
    for(int i=0;i<n;i++)
    scanf("%d",&id[i]);
    for(int i=0;i<k;i++)
    ar[i]=0;
    for(int i=0;i<n;i++)
    {
    gf=0;
    for(int j=0;j<k;j++)
    {
    if(id[i]==ar[j])
    {
    gf=1;
    break;
    }
    }
    if(gf==0)
    {
    for(int i=k-1;i>0;i--)
    ar[i]=ar[i-1];
    ar[0]=id[i];
    }
    }
    int z=k;
    for(int i=0;i<k;i++)
    {
    if(ar[i]==0)
    {
    z=i;
    break;
    }
    }
    printf("%d\n",z);
    for(int i=0;i<z;i++)
    printf("%d ",ar[i]);
    return 0;
}


#include<stdio.h>

int main()
{
    int n,k,z=0,f,d=1;
    scanf("%d%d",&n,&k);
    int id[n],sc[k];

    for(int i=0;i<n;i++)
    scanf("%d",&id[i]);
    for(int i=0;i<n;i++)
    {
    f=0;
    for(int j=0;j<z;j++)
    {
    if(id[i]==sc[j])
    {f=1;
    break;}
    }
    if(f==0)
    {
    z++;
    for(int m=0;m<k;m++)
    {
    sc[k-m-1]=sc[k-m-2];
    }
    sc[0]=id[i];
    }
    }
    if(k<z)
    d=k;
    else
    d=z;
    printf("%d\n",d);
    for(int i=0;i<d;i++)
    printf("%d ",sc[i]);
    return 0;
}


/*
 * author : anaksoleh
 * 8 okt 2019
 * link problem : https://codeforces.com/contest/1234/problem/B1
 */

#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#define min(x,y) (x < y ? x : y)

int arr[210];

bool duplicate(int num,int start , int end)
{
    int i;
    bool ok = false;
    for(i = start ; i >= end ; i--){
        if(arr[i] == num){ ok = true;break;}
    }
    return ok;
}
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    memset(arr,0,sizeof(arr));
    int i,num,cnt = 0,tail = n,head = n;
    i = n;
    while(n--)
    {
        scanf("%d",&num);
        if(!duplicate(num,tail,head)){
            arr[i] = num;
            head = i;
            --i;
            ++cnt;
        }
        if(cnt > k){--tail;--cnt;}
    }
    printf("%d\n",cnt);
    for(i = head ; i <= tail ; i++){
        printf("%d",arr[i]);
        if(i != tail)printf(" ");
        else{printf("\n");}
    }
    return 0;
}


/*
 * author : anaksoleh
 * 8 okt 2019
 * link problem : https://codeforces.com/contest/1234/problem/B1
 */

#include <stdio.h>
#include <stdbool.h>
#define min(x,y) (x < y ? x : y)

int arr[210];

bool duplicate(int num,int start , int end)
{
    int i;
    bool ok = false;
    for(i = start ; i >= end ; i--){
        if(arr[i] == num){ ok = true;break;}
    }
    return ok;
}
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    int i,num,cnt = 0,tail = n,head = n;
    for(i = n ; i >= 1 ; i--){
        scanf("%d",&num);
        if(duplicate(num,tail,i))continue;
        else{arr[i] = num;++cnt;head = i;}

        if(cnt > k){--tail;--cnt;}
    }
    printf("%d\n",cnt);
    for(i = head ; i <= tail ; i++){
        if(arr[i] != 0){
           printf("%d",arr[i]);
           if(i == tail){
            printf("\n");
           }else{printf(" ");}
        }
    }
    return 0;
}


#include <stdio.h>
#include <stdbool.h>
#define min(x,y) (x < y ? x : y)

int arr[210];

bool duplicate(int num,int start , int end)
{
    int i;
    bool ok = false;
    for(i = start ; i >= end ; i--){
        if(arr[i] == num){ ok = true;break;}
    }
    return ok;
}
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    int i,num,cnt = 0,tail = n,head = n;
    for(i = n ; i >= 1 ; i--){
        scanf("%d",&num);
        if(duplicate(num,tail,i))continue;
        else{arr[i] = num;++cnt;head = i;}

        if(cnt > k){--tail;--cnt;}
    }
    printf("%d\n",cnt);
    for(i = head ; i <= tail ; i++){
        if(arr[i] != 0){
           printf("%d",arr[i]);
           if(i == tail){
            printf("\n");
           }else{printf(" ");}
        }
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;

#define MP make_pair
typedef pair<int,int> pii;
typedef long long LL;

const int MN=3000+10;
vector<int> G[MN];
LL dis[MN][MN];
LL INF=(LL)1e15;
vector<int> bad[MN][MN];
int n;
queue<pii> Q;
vector<int> path;

void make_path(int b,int c)
{
     if(c==1)
     {
        path.push_back(1);
        return;
     }
     if(b==1)
     {
        path.push_back(1);
        path.push_back(c);
        return;
     }
     for(int i=0;i<(int)G[b].size();i++)
     {
        int a=G[b][i];
        if(dis[b][c]==dis[a][b]+1)
        {
           make_path(a,b);
           path.push_back(c);
        }
     }
}

inline bool valid(int &a,int &b,int &c)
{
       for(int i=0;i<(int)bad[a][b].size();i++)
       {
          if(bad[a][b][i]>c)
             return 1;
          if(bad[a][b][i]==c)
             return 0;
       }
       return 1;
}

void bfs(int st)
{
     for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
           dis[i][j]=INF;
     for(int i=0;i<=n;i++)
        dis[i][st]=0;
     while(!Q.empty())
        Q.pop();
     Q.push(MP(0,st));
     while(!Q.empty())
     {
        int a=Q.front().first;
        int b=Q.front().second;
        Q.pop();
        for(int i=0;i<(int)G[b].size();i++)
        {
           int c=G[b][i];
           if(valid(a,b,c) && dis[a][b]+1<dis[b][c])
           {
              dis[b][c]=dis[a][b]+1;
              Q.push(MP(b,c));
           }
        }
     }
}

int main()
{
    int k,m;
    cin>>n>>m>>k;
    while(m--)
    {
       int a,b;
       cin>>a>>b;
       G[a].push_back(b);
       G[b].push_back(a);
    }
    while(k--)
    {
       int a,b,c;
       cin>>a>>b>>c;
       bad[a][b].push_back(c);
    }
    for(int i=1;i<=n;i++)
       for(int j=1;j<=n;j++)
          sort(bad[i][j].begin(),bad[i][j].end());
    bfs(1);
    LL ans=INF;
    int par=0;
    for(int i=1;i<=n;i++)
    {
       if(dis[i][n]<ans)
       {
          ans=dis[i][n];
          par=i;
       }
    }
    if(ans>=INF)
       cout<<-1<<endl;
    else
    {
       make_path(par,n);
       if(ans+1!=(int)path.size())
          while(1);
       cout<<ans<<endl;
       for(int i=0;i<(int)path.size();i++)
          cout<<path[i]<<' ';
       cout<<endl;
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<ctime>

#include<cmath>
#include<iostream>
#include<fstream>

#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<sstream>
#include<stack>

using namespace std;

#define MAX(a,b) ((a)>(b) ? (a) : (b))
#define MIN(a,b) ((a)<(b) ? (a) : (b))
#define EPS 1e-9

bool vis[3010][3010];
int prev[9080000];

map<pair<int,int>,int> no;
vector<int> res;

queue< pair<int,int> > q;
vector< int > adj[3010];

void ini()
{
      memset(vis,0,sizeof(vis));
      no.clear();
      while(!q.empty()) q.pop();
      int i;
      for(i=0;i<3010;i++) adj[i].clear();
}

int main()
{
      int n,i,j,len,k,now,m,a,b,c,u,uu,v,vv;
      //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    //cout<<(sizeof(prev)/(1<<20));

    //while(1);
    while(scanf("%d %d %d",&n,&m,&k)==3)
    {
            ini();

            for(i=0;i<m;i++)
            {
                  scanf("%d %d",&a,&b);
                  adj[a].push_back(b);
                  adj[b].push_back(a);
            }

            for(i=0;i<k;i++)
            {
                  scanf("%d %d %d",&a,&b,&c);
                  no[make_pair(a,b)]=c;
            }

            pair<int,int> f,t,tt;

            f.first=1;
            f.second=0;

            prev[f.first*3010+f.second]=-1;

            vis[f.first][f.second]=1;

            q.push(f);
            int ans=-1;

           // cout<<n;

           // while(1);

            int now;

            while(!q.empty())
            {
                  f=q.front();q.pop();

                  u=f.first;
                  uu=f.second;

               //   cout<<u<<" "<<vis[u][uu]<<endl;
                  if(u==n)
                  {
                        ans=10;
                        now=u*3010+uu;

                        break;
                  }

                  vv=u;
                  for(i=0;i<adj[u].size();i++)
                  {
                        v=adj[u][i];
                        if(vis[v][vv] || no[make_pair(uu,u)]==v) continue;

                        vis[v][vv]=1;
                        t.first=v;
                        t.second=vv;

                        prev[v*3010+vv]=u*3010+uu;
                        q.push(t);

                  }

            }

            //while(1);

            if(ans==-1)
            {
                  printf("%d\n",ans);
                  continue;
            }

            res.clear();

            while(now!=-1)
            {
                  res.push_back(now/3010);
                  now=prev[now];
            }

            printf("%d\n",res.size()-1);
            reverse(res.begin(),res.end());

            for(i=0;i<res.size();i++)
            {
                  if(i) printf(" ");
                  printf("%d",res[i]);
            }
            printf("\n");

    }
      return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<ctime>

#include<cmath>
#include<iostream>
#include<fstream>

#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<sstream>
#include<stack>

using namespace std;

#define MAX(a,b) ((a)>(b) ? (a) : (b))
#define MIN(a,b) ((a)<(b) ? (a) : (b))
#define EPS 1e-9

bool vis[3010][3010];
int prev[9010000];

map<pair<int,int>,int> no;
vector<int> res;

queue< pair<int,int> > q;
vector< int > adj[3010];

void ini()
{
      memset(vis,0,sizeof(vis));
      no.clear();
      while(!q.empty()) q.pop();
      int i;
      for(i=0;i<3010;i++) adj[i].clear();
}

int main()
{
      int n,i,j,len,k,now,m,a,b,c,u,uu,v,vv;
      //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    //cout<<(sizeof(prev)/(1<<20));

    //while(1);
    while(scanf("%d %d %d",&n,&m,&k)==3)
    {
            ini();

            for(i=0;i<m;i++)
            {
                  scanf("%d %d",&a,&b);
                  adj[a].push_back(b);
                  adj[b].push_back(a);
            }

            for(i=0;i<k;i++)
            {
                  scanf("%d %d %d",&a,&b,&c);
                  no[make_pair(a,b)]=c;
            }

            pair<int,int> f,t,tt;

            f.first=1;
            f.second=0;

            prev[f.first*3010+f.second]=-1;

            vis[f.first][f.second]=1;

            q.push(f);
            int ans=-1;

           // cout<<n;

           // while(1);

            int now;

            while(!q.empty())
            {
                  f=q.front();q.pop();

                  u=f.first;
                  uu=f.second;

                  //cout<<u<<" "<<vis[u][uu]<<endl;
                  if(u==n)
                  {
                        ans=vis[u][uu]-1;
                        now=u*3010+uu;

                        break;
                  }

                  vv=u;
                  for(i=0;i<adj[u].size();i++)
                  {
                        v=adj[u][i];
                        if(vis[v][vv] || no[make_pair(uu,u)]==v) continue;

                        vis[v][vv]=1;
                        t.first=v;
                        t.second=vv;

                        prev[v*3010+vv]=u*3010+uu;
                        q.push(t);

                  }

            }

            //while(1);

            if(ans==-1)
            {
                  printf("%d\n",ans);
                  continue;
            }

            res.clear();

            while(now!=-1)
            {
                  res.push_back(now/3010);
                  now=prev[now];
            }

            printf("%d\n",res.size()-1);
            reverse(res.begin(),res.end());

            for(i=0;i<res.size();i++)
            {
                  if(i) printf(" ");
                  printf("%d",res[i]);
            }
            printf("\n");

    }
      return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<ctime>

#include<cmath>
#include<iostream>
#include<fstream>

#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<sstream>
#include<stack>

using namespace std;

#define MAX(a,b) ((a)>(b) ? (a) : (b))
#define MIN(a,b) ((a)<(b) ? (a) : (b))
#define EPS 1e-9

bool vis[3010][3010];
int prev[9080000];

map<pair<int,int>,int> no;
vector<int> res;

queue< pair<int,int> > q;
vector< int > adj[3010];

void ini()
{
      memset(vis,0,sizeof(vis));
      no.clear();
      while(!q.empty()) q.pop();
      int i;
      for(i=0;i<3010;i++) adj[i].clear();
}

int main()
{
      int n,i,j,len,k,now,m,a,b,c,u,uu,v,vv;
      freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    //cout<<(sizeof(prev)/(1<<20));

    //while(1);
    while(scanf("%d %d %d",&n,&m,&k)==3)
    {
            ini();

            for(i=0;i<m;i++)
            {
                  scanf("%d %d",&a,&b);
                  adj[a].push_back(b);
                  adj[b].push_back(a);
            }

            for(i=0;i<k;i++)
            {
                  scanf("%d %d %d",&a,&b,&c);
                  no[make_pair(a,b)]=c;
            }

            pair<int,int> f,t,tt;

            f.first=1;
            f.second=0;

            prev[f.first*3010+f.second]=-1;

            vis[f.first][f.second]=1;

            q.push(f);
            int ans=-1;

           // cout<<n;

           // while(1);

            int now;

            while(!q.empty())
            {
                  f=q.front();q.pop();

                  u=f.first;
                  uu=f.second;

                  //cout<<u<<" "<<vis[u][uu]<<endl;
                  if(u==n)
                  {
                        ans=vis[u][uu]-1;
                        now=u*3010+uu;

                        break;
                  }

                  vv=u;
                  for(i=0;i<adj[u].size();i++)
                  {
                        v=adj[u][i];
                        if(vis[v][vv] || no[make_pair(uu,u)]==v) continue;

                        vis[v][vv]=1;
                        t.first=v;
                        t.second=vv;

                        prev[v*3010+vv]=u*3010+uu;
                        q.push(t);

                  }

            }

            //while(1);

            if(ans==-1)
            {
                  printf("%d\n",ans);
                  continue;
            }

            res.clear();

            while(now!=-1)
            {
                  res.push_back(now/3010);
                  now=prev[now];
            }

            printf("%d\n",res.size()-1);
            reverse(res.begin(),res.end());

            for(i=0;i<res.size();i++)
            {
                  if(i) printf(" ");
                  printf("%d",res[i]);
            }
            printf("\n");

    }
      return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<ctime>

#include<cmath>
#include<iostream>
#include<fstream>

#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<sstream>
#include<stack>

using namespace std;

#define MAX(a,b) ((a)>(b) ? (a) : (b))
#define MIN(a,b) ((a)<(b) ? (a) : (b))
#define EPS 1e-9

int vis[3010][3010];
int prev[9080000];
set< pair< pair<int,int>,int>   > no;
vector<int> res;

queue< pair<int,int> > q;
vector< int > adj[3010];

void ini()
{
      int i,j;
      memset(vis,0,sizeof(vis));
      memset(prev,0,sizeof(prev));
      no.clear();

      while(!q.empty()) q.pop();
      for(i=0;i<3010;i++) adj[i].clear();
      res.clear();
}

int main()
{
      int n,i,j,len,k,now,m,a,b,c,u,uu,v,vv;
      //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    //cout<<(sizeof(prev)/(1<<20));

    //while(1);
    while(scanf("%d %d %d",&n,&m,&k)==3)
    {
            ini();

            for(i=0;i<m;i++)
            {
                  scanf("%d %d",&a,&b);
                  adj[a].push_back(b);
                  adj[b].push_back(a);
            }

            for(i=0;i<k;i++)
            {
                  scanf("%d %d %d",&a,&b,&c);
                  no.insert( make_pair(make_pair(a,b),c) );
            }

            pair<int,int> f,t,tt;

            f.first=1;
            f.second=0;

            prev[f.first*3010+f.second]=-1;

            vis[f.first][f.second]=1;

            q.push(f);
            int ans=-1;

           // cout<<n;

           // while(1);

            int now;

            while(!q.empty())
            {
                  f=q.front();q.pop();

                  u=f.first;
                  uu=f.second;

                  //cout<<u<<" "<<vis[u][uu]<<endl;
                  if(u==n)
                  {
                        ans=10;
                        now=u*3010+uu;

                        break;
                  }

                  vv=u;
                  for(i=0;i<adj[u].size();i++)
                  {
                        v=adj[u][i];
                        if( vis[v][vv] || (no.find(make_pair(make_pair(uu,u),v))!=no.end() ) ) continue;

                        vis[v][vv]=vis[u][uu]+1;
                        t.first=v;
                        t.second=vv;

                        prev[v*3010+vv]=u*3010+uu;
                        q.push(t);

                  }

            }

            //while(1);

            if(ans==-1)
            {
                  printf("%d\n",ans);
                  return 0;
            }

            res.clear();

            while(now!=-1)
            {
                  res.push_back(now/3010);
                  now=prev[now];
            }

            printf("%d\n",res.size()-1);
            reverse(res.begin(),res.end());

            for(i=0;i<res.size();i++)
            {
                  if(i) printf(" ");
                  printf("%d",res[i]);
            }
            printf("\n");

    }
      return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<ctime>

#include<cmath>
#include<iostream>
#include<fstream>

#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<sstream>
#include<stack>

using namespace std;

#define MAX(a,b) ((a)>(b) ? (a) : (b))
#define MIN(a,b) ((a)<(b) ? (a) : (b))
#define EPS 1e-9

bool vis[3010][3010];
int prev[9080000];

map<pair<int,int>,int> no;
vector<int> res;

queue< pair<int,int> > q;
vector< int > adj[3010];

void ini()
{
      memset(vis,0,sizeof(vis));
      no.clear();
      while(!q.empty()) q.pop();
      int i;
      for(i=0;i<3010;i++) adj[i].clear();
}

int main()
{
      int n,i,j,len,k,now,m,a,b,c,u,uu,v,vv;
      //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    //cout<<(sizeof(prev)/(1<<20));

    //while(1);
    while(scanf("%d %d %d",&n,&m,&k)==3)
    {
            ini();

            for(i=0;i<m;i++)
            {
                  scanf("%d %d",&a,&b);
                  adj[a].push_back(b);
                  adj[b].push_back(a);
            }

            for(i=0;i<k;i++)
            {
                  scanf("%d %d %d",&a,&b,&c);
                  no[make_pair(a,b)]=c;
            }

            pair<int,int> f,t,tt;

            f.first=1;
            f.second=0;

            prev[f.first*3010+f.second]=-1;

            vis[f.first][f.second]=1;

            q.push(f);
            int ans=-1;

           // cout<<n;

           // while(1);

            int now;

            while(!q.empty())
            {
                  f=q.front();q.pop();

                  u=f.first;
                  uu=f.second;

                  //cout<<u<<" "<<vis[u][uu]<<endl;
                  if(u==n)
                  {
                        ans=vis[u][uu]-1;
                        now=u*3010+uu;

                        break;
                  }

                  vv=u;
                  for(i=0;i<adj[u].size();i++)
                  {
                        v=adj[u][i];
                        if(vis[v][vv] || no[make_pair(uu,u)]==v) continue;

                        vis[v][vv]=1;
                        t.first=v;
                        t.second=vv;

                        prev[v*3010+vv]=u*3010+uu;
                        q.push(t);

                  }

            }

            //while(1);

            if(ans==-1)
            {
                  printf("%d\n",ans);
                  continue;
            }

            res.clear();

            while(now!=-1)
            {
                  res.push_back(now/3010);
                  now=prev[now];
            }

            printf("%d\n",res.size()-1);
            reverse(res.begin(),res.end());

            for(i=0;i<res.size();i++)
            {
                  if(i) printf(" ");
                  printf("%d",res[i]);
            }
            printf("\n");

    }
      return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<ctime>

#include<cmath>
#include<iostream>
#include<fstream>

#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<sstream>
#include<stack>

using namespace std;

#define MAX(a,b) ((a)>(b) ? (a) : (b))
#define MIN(a,b) ((a)<(b) ? (a) : (b))
#define EPS 1e-9

int vis[3010][3010];
int no[3010][3010];
int prev[9010000];

queue< pair<int,int> > q;
vector< int > adj[3010];

void ini()
{
      memset(vis,0,sizeof(vis));
      while(!q.empty()) q.pop();
      memset(no,-1,sizeof(no));
      while(!q.empty()) q.pop();
      int i;
      for(i=0;i<3010;i++) adj[i].clear();
}

int main()
{
      int n,i,j,len,k,now,m,a,b,c,u,uu,v,vv;
      //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    while(scanf("%d %d %d",&n,&m,&k)==3)
    {
            ini();

            for(i=0;i<m;i++)
            {
                  scanf("%d %d",&a,&b);
                  adj[a].push_back(b);
                  adj[b].push_back(a);
            }

            for(i=0;i<k;i++)
            {
                  scanf("%d %d %d",&a,&b,&c);
                  no[a][b]=c;
            }

            pair<int,int> f,t,tt;

            f.first=1;
            f.second=0;

            prev[f.first*3010+f.second]=-1;

            vis[f.first][f.second]=1;

            q.push(f);
            int ans=-1;

           // cout<<n;

           // while(1);

            int now;

            while(!q.empty())
            {
                  f=q.front();q.pop();

                  u=f.first;
                  uu=f.second;

                  //cout<<u<<" "<<vis[u][uu]<<endl;
                  if(u==n)
                  {
                        ans=vis[u][uu]-1;
                        now=u*3010+uu;

                        break;
                  }

                  vv=u;
                  for(i=0;i<adj[u].size();i++)
                  {
                        v=adj[u][i];
                        if(vis[v][vv] || no[uu][u]==v) continue;

                        vis[v][vv]=vis[u][uu]+1;
                        t.first=v;
                        t.second=vv;

                        prev[v*3010+vv]=u*3010+uu;
                        q.push(t);

                  }

            }

            //while(1);

            printf("%d\n",ans);
            if(ans==-1) continue;

            vector<int> res;

            while(now!=-1)
            {
                  res.push_back(now/3010);
             //     printf("%d ",now/3010);
                  now=prev[now];
            }

            reverse(res.begin(),res.end());

            for(i=0;i<res.size();i++)
            {
                  if(i) printf(" ");
                  printf("%d",res[i]);
            }
            printf("\n");

    }
      return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<ctime>

#include<cmath>
#include<iostream>
#include<fstream>

#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<sstream>
#include<stack>

using namespace std;

#define MAX(a,b) ((a)>(b) ? (a) : (b))
#define MIN(a,b) ((a)<(b) ? (a) : (b))
#define EPS 1e-9

bool vis[3010][3010];
int prev[9010000];

map<pair<int,int>,int> no;
vector<int> res;

queue< pair<int,int> > q;
vector< int > adj[3010];

void ini()
{
      memset(vis,0,sizeof(vis));
      no.clear();
      while(!q.empty()) q.pop();
      int i;
      for(i=0;i<3010;i++) adj[i].clear();
}

int main()
{
      int n,i,j,len,k,now,m,a,b,c,u,uu,v,vv;
      //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    //cout<<(sizeof(prev)/(1<<20));

    while(1);
    while(scanf("%d %d %d",&n,&m,&k)==3)
    {
            ini();

            for(i=0;i<m;i++)
            {
                  scanf("%d %d",&a,&b);
                  adj[a].push_back(b);
                  adj[b].push_back(a);
            }

            for(i=0;i<k;i++)
            {
                  scanf("%d %d %d",&a,&b,&c);
                  no[make_pair(a,b)]=c;
            }

            pair<int,int> f,t,tt;

            f.first=1;
            f.second=0;

            prev[f.first*3010+f.second]=-1;

            vis[f.first][f.second]=1;

            q.push(f);
            int ans=-1;

           // cout<<n;

           // while(1);

            int now;

            while(!q.empty())
            {
                  f=q.front();q.pop();

                  u=f.first;
                  uu=f.second;

                  //cout<<u<<" "<<vis[u][uu]<<endl;
                  if(u==n)
                  {
                        ans=vis[u][uu]-1;
                        now=u*3010+uu;

                        break;
                  }

                  vv=u;
                  for(i=0;i<adj[u].size();i++)
                  {
                        v=adj[u][i];
                        if(vis[v][vv] || no[make_pair(uu,u)]==v) continue;

                        vis[v][vv]=1;
                        t.first=v;
                        t.second=vv;

                        prev[v*3010+vv]=u*3010+uu;
                        q.push(t);

                  }

            }

            //while(1);

            if(ans==-1)
            {
                  printf("%d\n",ans);
                  continue;
            }

            res.clear();

            while(now!=-1)
            {
                  res.push_back(now/3010);
                  now=prev[now];
            }

            printf("%d\n",res.size()-1);
            reverse(res.begin(),res.end());

            for(i=0;i<res.size();i++)
            {
                  if(i) printf(" ");
                  printf("%d",res[i]);
            }
            printf("\n");

    }
      return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<ctime>

#include<cmath>
#include<iostream>
#include<fstream>

#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<sstream>
#include<stack>

using namespace std;

#define MAX(a,b) ((a)>(b) ? (a) : (b))
#define MIN(a,b) ((a)<(b) ? (a) : (b))
#define EPS 1e-9

bool vis[3010][3010];
int prev[9080000];

map<pair<int,int>,int> no;
vector<int> res;

queue< pair<int,int> > q;
vector< int > adj[3010];

void ini()
{
      memset(vis,0,sizeof(vis));
      memset(prev,0,sizeof(prev));

      no.clear();
      while(!q.empty()) q.pop();
      int i;
      for(i=0;i<3010;i++) adj[i].clear();
      res.clear();
}

int main()
{
      int n,i,j,len,k,now,m,a,b,c,u,uu,v,vv;
      //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    //cout<<(sizeof(prev)/(1<<20));

    //while(1);
    while(scanf("%d %d %d",&n,&m,&k)==3)
    {
            ini();

            for(i=0;i<m;i++)
            {
                  scanf("%d %d",&a,&b);
                  adj[a].push_back(b);
                  adj[b].push_back(a);
            }

            for(i=0;i<k;i++)
            {
                  scanf("%d %d %d",&a,&b,&c);
                  no[make_pair(a,b)]=c;
            }

            pair<int,int> f,t,tt;

            f.first=1;
            f.second=0;

            prev[f.first*3010+f.second]=-1;

            vis[f.first][f.second]=1;

            q.push(f);
            int ans=-1;

           // cout<<n;

           // while(1);

            int now;

            while(!q.empty())
            {
                  f=q.front();q.pop();

                  u=f.first;
                  uu=f.second;

               //   cout<<u<<" "<<vis[u][uu]<<endl;
                  if(u==n)
                  {
                        ans=10;
                        now=u*3010+uu;

                        break;
                  }

                  vv=u;
                  for(i=0;i<adj[u].size();i++)
                  {
                        v=adj[u][i];
                        if(vis[v][vv] || no[make_pair(uu,u)]==v) continue;

                        vis[v][vv]=1;
                        t.first=v;
                        t.second=vv;

                        prev[v*3010+vv]=u*3010+uu;
                        q.push(t);

                  }

            }

            //while(1);

            if(ans==-1)
            {
                  printf("%d\n",ans);
                  continue;
            }

            res.clear();

            while(now!=-1)
            {
                  res.push_back(now/3010);
                  now=prev[now];
            }

            printf("%d\n",res.size()-1);
            reverse(res.begin(),res.end());

            for(i=0;i<res.size();i++)
            {
                  if(i) printf(" ");
                  printf("%d",res[i]);
            }
            printf("\n");

    }
      return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<ctime>

#include<cmath>
#include<iostream>
#include<fstream>

#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<sstream>
#include<stack>

using namespace std;

#define MAX(a,b) ((a)>(b) ? (a) : (b))
#define MIN(a,b) ((a)<(b) ? (a) : (b))
#define EPS 1e-9

bool vis[3010][3010];
int prev[9080000];

map<pair<int,int>,int> no;
vector<int> res;

queue< pair<int,int> > q;
vector< int > adj[3010];

void ini()
{
      memset(vis,0,sizeof(vis));
      memset(prev,0,sizeof(prev));

      no.clear();
      while(!q.empty()) q.pop();
      int i;
      for(i=0;i<3010;i++) adj[i].clear();
      res.clear();
}

int main()
{
      int n,i,j,len,k,now,m,a,b,c,u,uu,v,vv;
      //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    //cout<<(sizeof(prev)/(1<<20));

    //while(1);
    scanf("%d %d %d",&n,&m,&k);
    {
            ini();

            for(i=0;i<m;i++)
            {
                  scanf("%d %d",&a,&b);
                  adj[a].push_back(b);
                  adj[b].push_back(a);
            }

            for(i=0;i<k;i++)
            {
                  scanf("%d %d %d",&a,&b,&c);
                  no[make_pair(a,b)]=c;
            }

            pair<int,int> f,t,tt;

            f.first=1;
            f.second=0;

            prev[f.first*3010+f.second]=-1;

            vis[f.first][f.second]=1;

            q.push(f);
            int ans=-1;

           // cout<<n;

           // while(1);

            int now;

            while(!q.empty())
            {
                  f=q.front();q.pop();

                  u=f.first;
                  uu=f.second;

               //   cout<<u<<" "<<vis[u][uu]<<endl;
                  if(u==n)
                  {
                        ans=10;
                        now=u*3010+uu;

                        break;
                  }

                  vv=u;
                  for(i=0;i<adj[u].size();i++)
                  {
                        v=adj[u][i];
                        if(vis[v][vv] || no[make_pair(uu,u)]==v) continue;

                        vis[v][vv]=1;
                        t.first=v;
                        t.second=vv;

                        prev[v*3010+vv]=u*3010+uu;
                        q.push(t);

                  }

            }

            //while(1);

            if(ans==-1)
            {
                  printf("%d\n",ans);
                  return 0;
            }

            res.clear();

            while(now!=-1)
            {
                  res.push_back(now/3010);
                  now=prev[now];
            }

            printf("%d\n",res.size()-1);
            reverse(res.begin(),res.end());

            for(i=0;i<res.size();i++)
            {
                  if(i) printf(" ");
                  printf("%d",res[i]);
            }
            printf("\n");

    }
      return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<ctime>

#include<cmath>
#include<iostream>
#include<fstream>

#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<sstream>
#include<stack>

using namespace std;

#define MAX(a,b) ((a)>(b) ? (a) : (b))
#define MIN(a,b) ((a)<(b) ? (a) : (b))
#define EPS 1e-9

int vis[3010][3010];
int prev[9010000];

map<pair<int,int>,int> no;
  vector<int> res;

queue< pair<int,int> > q;
vector< int > adj[3010];

void ini()
{
      memset(vis,0,sizeof(vis));
      no.clear();
      while(!q.empty()) q.pop();
      int i;
      for(i=0;i<3010;i++) adj[i].clear();
}

int main()
{
      int n,i,j,len,k,now,m,a,b,c,u,uu,v,vv;
      //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    while(scanf("%d %d %d",&n,&m,&k)==3)
    {
            ini();

            for(i=0;i<m;i++)
            {
                  scanf("%d %d",&a,&b);
                  adj[a].push_back(b);
                  adj[b].push_back(a);
            }

            for(i=0;i<k;i++)
            {
                  scanf("%d %d %d",&a,&b,&c);
                  no[make_pair(a,b)]=c;
            }

            pair<int,int> f,t,tt;

            f.first=1;
            f.second=0;

            prev[f.first*3010+f.second]=-1;

            vis[f.first][f.second]=1;

            q.push(f);
            int ans=-1;

           // cout<<n;

           // while(1);

            int now;

            while(!q.empty())
            {
                  f=q.front();q.pop();

                  u=f.first;
                  uu=f.second;

                  //cout<<u<<" "<<vis[u][uu]<<endl;
                  if(u==n)
                  {
                        ans=vis[u][uu]-1;
                        now=u*3010+uu;

                        break;
                  }

                  vv=u;
                  for(i=0;i<adj[u].size();i++)
                  {
                        v=adj[u][i];
                        if(vis[v][vv] || no[make_pair(uu,u)]==v) continue;

                        vis[v][vv]=vis[u][uu]+1;
                        t.first=v;
                        t.second=vv;

                        prev[v*3010+vv]=u*3010+uu;
                        q.push(t);

                  }

            }

            //while(1);

            printf("%d\n",ans);
            if(ans==-1) continue;

            res.clear();

            while(now!=-1)
            {
                  res.push_back(now/3010);
                  now=prev[now];
            }

            reverse(res.begin(),res.end());

            for(i=0;i<res.size();i++)
            {
                  if(i) printf(" ");
                  printf("%d",res[i]);
            }
            printf("\n");

    }
      return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const int INFTY = 1<<30;
const int MAXN = 3005;
int N, M, K;
vector<int> adj[MAXN];
map<ll, bool> mp;
int dist[MAXN][MAXN];
int par[MAXN][MAXN];
int order[MAXN];

int main()
{
	ios::sync_with_stdio(false);

	cin >> N >> M >> K;
	for (int i = 0; i < M; i++)
	{
		int x, y;
		cin >> x >> y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	for (int i = 0; i < K; i++)
	{
		int a, b, c;
		cin >> a >> b >> c;
		mp[(ll)a*100000000 + b*10000 + c] = true;
	}

	queue<pii> q;
	q.push(pii(0, 1));

	while (!q.empty())
	{
		int a = q.front().first, b = q.front().second;
		q.pop();

		for (int i = 0; i < adj[b].size(); i++)
		{
			int next = adj[b][i];
			if (par[b][next] == 0 && !mp[(ll)a*100000000 + b*10000 + next])
			{
				dist[b][next] = dist[a][b] + 1;
				par[b][next] = a;
				q.push(pii(b, next));
			}
		}
	}

	int ans = INFTY, a = 0, b = N;
	for (int i = 1; i < N; i++)
		if (dist[i][N] > 0 && dist[i][N] < ans)
		{
			ans = dist[i][N];
			a = i;
		}

	if (ans == INFTY)
	{
		cout << "-1\n";
		return 0;
	}

	for (int i = 0; i <= ans; i++)
	{
		order[ans - i] = b;
		int temp = a;
		a = par[a][b];
		b = temp;
	}

	cout << ans << "\n";
	for (int i = 0; i <= ans; i++)
		cout << order[i] << " ";

	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const int INFTY = 1<<30;
const int MAXN = 3005;
int N, M, K;
vector<int> adj[MAXN];
map<ll, bool> mp;
int dist[MAXN][MAXN];
int par[MAXN][MAXN];
int order[MAXN];

int main()
{
	ios::sync_with_stdio(false);

	cin >> N >> M >> K;
	for (int i = 0; i < M; i++)
	{
		int x, y;
		cin >> x >> y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	for (int i = 0; i < K; i++)
	{
		int a, b, c;
		cin >> a >> b >> c;
		mp[(ll)a*100000000 + b*10000 + c] = true;
	}

	queue<pii> q;
	q.push(pii(1, 1));

	dist[1][1] = 1;
	while (!q.empty())
	{
		int a = q.front().first, b = q.front().second;
		q.pop();

		for (int i = 0; i < adj[b].size(); i++)
		{
			int next = adj[b][i];
			if (par[b][next] == 0 && !mp[(ll)a*100000000 + b*10000 + next])
			{
				dist[b][next] = dist[a][b] + 1;
				par[b][next] = a;
				q.push(pii(b, next));
			}
		}
	}

	int ans = INFTY, a = 0, b = N;
	for (int i = 1; i <= N; i++)
		if (dist[i][N] > 0 && dist[i][N] < ans)
		{
			ans = dist[i][N];
			a = i;
		}

	if (ans == INFTY)
	{
		cout << "-1\n";
		return 0;
	}

	ans--;

	for (int i = 0; i <= ans; i++)
	{
		order[ans - i] = b;
		int temp = a;
		a = par[a][b];
		b = temp;
	}

	cout << ans << "\n";
	for (int i = 0; i <= ans; i++)
		cout << order[i] << " ";

	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
using namespace std;
typedef pair<int, int> pii;

const int MAXN = 3005;
int N, M, K;
vector<int> adj[MAXN];
map<pair<pii, int>, bool> mp;
bool vis[MAXN][MAXN];
int P[MAXN*MAXN];
int last[MAXN*MAXN];
int idx = 1;
int order[MAXN];

int bfs()
{
	queue<pair<pii, pii> > q;
	q.push(make_pair(pii(0, 0), pii(0, 1)));

	while (!q.empty())
	{
		pair<int, int> node = q.front().second;
		int len = q.front().first.first, key = q.front().first.second;
		q.pop();

		vis[node.first][node.second] = true;
		P[idx] = node.second;
		last[idx] = key;
		if (node.second == N)
			return len;

		for (int i = 0; i < adj[node.second].size(); i++)
		{
			int next = adj[node.second][i];
			if (!vis[node.second][next] && !mp[make_pair(node, next)])
				q.push(make_pair(pii(len+1, idx), pii(node.second, next)));
		}

		idx++;
	}

	return -1;
}

int main()
{
	ios::sync_with_stdio(false);

	cin >> N >> M >> K;
	for (int i = 0; i < M; i++)
	{
		int x, y;
		cin >> x >> y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	for (int i = 0; i < K; i++)
	{
		int a, b, c;
		cin >> a >> b >> c;
		mp[make_pair(make_pair(a, b), c)] = true;
	}

	int dist = bfs();
	for (int i = 0, j = idx; i <= dist; i++)
	{
		order[i] = P[j];
		j = last[j];
	}

	cout << dist << "\n";
	for (int i = dist; i >= 0; i--)
		cout << order[i] << " ";

	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

struct node
{
	int len, key, a, b;
	node() { }
	node(int len, int key, int a, int b)
		: len(len), key(key), a(a), b(b) { }
};

const int MAXN = 3005;
int N, M, K;
vector<int> adj[MAXN];
map<ll, bool> mp;
bool vis[MAXN][MAXN];
int P[MAXN*MAXN];
int last[MAXN*MAXN];
int idx = 1;
int order[MAXN];

int bfs()
{
	queue<node> q;
	q.push(node(0, 0, 0, 1));

	while (!q.empty())
	{
		int len = q.front().len, key = q.front().key;
		int a = q.front().a, b = q.front().b;
		q.pop();

		vis[a][b] = true;
		P[idx] = b;
		last[idx] = key;
		if (b == N)
			return len;

		for (int i = 0; i < adj[b].size(); i++)
		{
			int next = adj[b][i];
			if (!vis[b][next] && !mp[(ll)a*100000000 + b*10000 + next])
				q.push(node(len+1, idx, b, next));
		}

		idx++;
	}

	return -1;
}

int main()
{
	ios::sync_with_stdio(false);

	cin >> N >> M >> K;
	for (int i = 0; i < M; i++)
	{
		int x, y;
		cin >> x >> y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	for (int i = 0; i < K; i++)
	{
		int a, b, c;
		cin >> a >> b >> c;
		mp[(ll)a*100000000 + b*10000 + c] = true;
	}

	int dist = bfs();
	for (int i = 0, j = idx; i <= dist; i++)
	{
		order[i] = P[j];
		j = last[j];
	}

	cout << dist << "\n";
	for (int i = dist; i >= 0; i--)
		cout << order[i] << " ";

	return 0;
}


// be name OO
#include <cstdio>
#include <vector>
#include <utility>
#include <cstring>
#include <queue>
using namespace std;
const int MN=3000+10;
typedef pair<int,int> pie;
bool mark[MN][MN];
int par[MN][MN];
vector <int> no[MN][MN];
vector <int> list[MN];
vector <int> sol;
queue<pie> Q;
int n,m,k;
// 1 BASE
void find(int a,int b)
{
	if (b!=1)
		find(par[a][b],a);
	sol.push_back(b);
}
bool bfs(int p,int v)
{
	memset(par,-1,sizeof(par));
	mark[p][v]=1;
	Q.push(pie(p,v));
	while (!Q.empty())
	{
		pie now=Q.front();
		Q.pop();
		int a=now.first,b=now.second;
		for (int i=0;i<list[b].size();i++)
		{
			int u=list[b][i];
			if (mark[b][u]==0)
			{
				bool av=true;
				for (int k=0;k<no[a][b].size();k++) if (no[a][b][k]==u)
				{
					av=false;
					break;
				}
				if (!av)
					continue;
				mark[b][u]=1;
				par[b][u]=a;
				Q.push(pie(b,u));
				if (u==n)
				{
					find(b,u);
					printf("%d\n",sol.size()-1);
					for (int i=0;i<sol.size();i++)
						printf("%d ",sol[i]);
					printf("\n");
					return 1;
				}
			}
		}
	}
	return 0;
}
int main()
{
	scanf("%d %d %d",&n,&m,&k);
	for (int i=0;i<m;i++)
	{
		int a,b;
		scanf("%d %d",&a,&b);
		list[a].push_back(b);
		list[b].push_back(a);
	}
	for (int i=0;i<k;i++)
	{
		int a,b,c;
		scanf("%d %d %d",&a,&b,&c);
		no[a][b].push_back(c);
	}
	if (!bfs(0,1))
	{
		printf("-1\n");
		return 0;
	}
	return 0;
}


// be name OO
#include <cstdio>
#include <vector>
#include <utility>
#include <cstring>
#include <queue>
using namespace std;
const int MN=3000+10;
typedef pair<int,int> pie;
bool mark[MN][MN];
int par[MN][MN];
vector <int> no[MN][MN];
vector <int> list[MN];
vector <int> sol;
queue<pie> Q;
int n,m,k;
// 1 BASE
void find(int a,int b)
{
	if (par[a][b])
		find(par[a][b],a);
	sol.push_back(b);
}
bool bfs(int p,int v)
{
	memset(par,-1,sizeof(par));
	mark[p][v]=1;
	Q.push(pie(p,v));
	while (!Q.empty())
	{
		pie now=Q.front();
		Q.pop();
		int a=now.first,b=now.second;
		for (int i=0;i<list[b].size();i++)
		{
			int u=list[b][i];
			if (mark[b][u]==0)
			{
				bool av=true;
				for (int k=0;k<no[a][b].size();k++) if (no[a][b][k]==u)
				{
					av=false;
					break;
				}
				if (!av)
					continue;
				mark[b][u]=1;
				par[b][u]=a;
				Q.push(pie(b,u));
				if (u==n)
				{
					find(b,u);
					printf("%d\n",sol.size()-1);
					for (int i=0;i<sol.size();i++)
						printf("%d ",sol[i]);
					printf("\n");
					return 1;
				}
			}
		}
	}
	return 0;
}
int main()
{
	scanf("%d %d %d",&n,&m,&k);
	for (int i=0;i<m;i++)
	{
		int a,b;
		scanf("%d %d",&a,&b);
		list[a].push_back(b);
		list[b].push_back(a);
	}
	for (int i=0;i<k;i++)
	{
		int a,b,c;
		scanf("%d %d %d",&a,&b,&c);
		no[a][b].push_back(c);
	}
	if (!bfs(0,1))
	{
		printf("-1\n");
		return 0;
	}
	return 0;
}


// be name OO
#include <cstdio>
#include <vector>
#include <utility>
#include <cstring>
#include <queue>
#include <set>
using namespace std;
const int MN=3000+5;
typedef pair<int,int> pie;
typedef pair<pie,int> tp;
set <tp> ill;
bool mark[MN][MN];
int par[MN][MN];
vector <int> list[MN];
vector <int> sol;
queue<pie> Q;
int n,m,k;
// 1 BASE
void find(int a,int b)
{
	if (b!=1)
		find(par[a][b],a);
	sol.push_back(b);
}
bool bfs(int p,int v)
{
	memset(par,-1,sizeof(par));
	mark[p][v]=1;
	Q.push(pie(p,v));
	while (!Q.empty())
	{
		pie now=Q.front();
		Q.pop();
		int a=now.first,b=now.second;
		for (int i=0;i<list[b].size();i++)
		{
			int u=list[b][i];
			if (mark[b][u]==0)
			{
				if (ill.find(tp(pie(a,b),u))!=ill.end())
					continue;
				mark[b][u]=1;
				par[b][u]=a;
				Q.push(pie(b,u));
				if (u==n)
				{
					find(b,u);
					printf("%d\n",sol.size()-1);
					for (int i=0;i<sol.size();i++)
						printf("%d ",sol[i]);
					printf("\n");
					return 1;
				}
			}
		}
	}
	return 0;
}
int main()
{
	scanf("%d %d %d",&n,&m,&k);
	for (int i=0;i<m;i++)
	{
		int a,b;
		scanf("%d %d",&a,&b);
		list[a].push_back(b);
		list[b].push_back(a);
	}
	for (int i=0;i<k;i++)
	{
		int a,b,c;
		scanf("%d %d %d",&a,&b,&c);
		ill.insert(tp(pie(a,b),c));
	}
	if (!bfs(0,1))
	{
		printf("-1\n");
		return 0;
	}
	return 0;
}


// be name OO
#include <cstdio>
#include <vector>
#include <utility>
#include <cstring>
#include <queue>
using namespace std;
const int MN=3000+100;
typedef pair<int,int> pie;
bool mark[MN][MN];
pie par[MN][MN];
vector <int> no[MN][MN];
vector <int> list[MN];
vector <int> sol;
queue<pie> Q;
int n,m,k;
// 1 BASE
void find(int a,int b)
{
	if (par[a][b].first!=-1)
		find(par[a][b].first,par[a][b].second);
	sol.push_back(b);
}
bool bfs(int p,int v)
{
	memset(par,-1,sizeof(par));
	mark[p][v]=1;
	Q.push(pie(p,v));
	while (!Q.empty())
	{
		pie now=Q.front();
		Q.pop();
		int a=now.first,b=now.second;
		for (int i=0;i<list[b].size();i++)
		{
			int u=list[b][i];
			if (mark[b][u]==0)
			{
				bool av=true;
				for (int k=0;k<no[a][b].size();k++) if (no[a][b][k]==u)
				{
					av=false;
					break;
				}
				if (!av)
					continue;
				mark[b][u]=1;
				par[b][u]=pie(a,b);
				Q.push(pie(b,u));
				if (u==n)
				{
					find(b,u);
					printf("%d\n",sol.size()-1);
					for (int i=0;i<sol.size();i++)
						printf("%d ",sol[i]);
					printf("\n");
					return 1;
				}
			}
		}
	}
	return 0;
}
int main()
{
	scanf("%d %d %d",&n,&m,&k);
	for (int i=0;i<m;i++)
	{
		int a,b;
		scanf("%d %d",&a,&b);
		list[a].push_back(b);
		list[b].push_back(a);
	}
	for (int i=0;i<k;i++)
	{
		int a,b,c;
		scanf("%d %d %d",&a,&b,&c);
		no[a][b].push_back(c);
	}
	if (!bfs(0,1))
	{
		printf("-1\n");
		return 0;
	}
	return 0;
}


// be name OO
#include <cstdio>
#include <vector>
#include <utility>
#include <cstring>
#include <queue>
#include <set>
using namespace std;
const int MN=3000+10;
typedef pair<int,int> pie;
typedef pair<pie,int> tp;
set <tp> ill;
bool mark[MN][MN];
int par[MN][MN];
vector <int> list[MN];
vector <int> sol;
queue<pie> Q;
int n,m,k;
// 1 BASE
void find(int a,int b)
{
	if (b!=1)
		find(par[a][b],a);
	sol.push_back(b);
}
bool bfs(int p,int v)
{
	memset(par,-1,sizeof(par));
	mark[p][v]=1;
	Q.push(pie(p,v));
	while (!Q.empty())
	{
		pie now=Q.front();
		Q.pop();
		int a=now.first,b=now.second;
		for (int i=0;i<list[b].size();i++)
		{
			int u=list[b][i];
			if (mark[b][u]==0)
			{
				if (ill.find(tp(pie(a,b),u))!=ill.end())
					continue;
				mark[b][u]=1;
				par[b][u]=a;
				Q.push(pie(b,u));
				if (u==n)
				{
					find(b,u);
					printf("%d\n",sol.size()-1);
					for (int i=0;i<sol.size();i++)
						printf("%d ",sol[i]);
					printf("\n");
					return 1;
				}
			}
		}
	}
	return 0;
}
int main()
{
	scanf("%d %d %d",&n,&m,&k);
	for (int i=0;i<m;i++)
	{
		int a,b;
		scanf("%d %d",&a,&b);
		list[a].push_back(b);
		list[b].push_back(a);
	}
	for (int i=0;i<k;i++)
	{
		int a,b,c;
		scanf("%d %d %d",&a,&b,&c);
		ill.insert(tp(pie(a,b),c));
	}
	if (!bfs(0,1))
	{
		printf("-1\n");
		return 0;
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <set>

using namespace std;

typedef pair <int, int> PII;

int n, m, K;
int a[40000], b[40000];
vector <int> e[3001];
vector <int> res;
set <PII> forbid;
map <pair <int, int>, int> mp;

int head, tail;
int Q[300000];
int pre[300000];
bool visited[300000];
void init() {
	head = tail = 0;
	memset(visited, 0, sizeof(visited));
}
void enQ(int x) {
	Q[tail++] = x;
}
int deQ() {
	return Q[head++];
}

bool gao() {
	init();
	for (vector <int>::const_iterator i = e[1].begin(); i != e[1].end(); i++) {
		pre[tail] = -1;
		enQ(*i);
		visited[*i] = true;
	}
	while (head != tail) {
		int cur = head;
		int top = deQ();
		int u = b[top];
		for (vector <int>::const_iterator i = e[u].begin(); i != e[u].end(); i++) {
			if (forbid.find(make_pair(top, *i)) == forbid.end()) {
				pre[tail] = cur;
				enQ(*i);
				visited[*i] = true;
				if (b[*i] == n) {
					for (int j = tail - 1; j != -1; j = pre[j]) {
						res.push_back(b[Q[j]]);
					}
					res.push_back(1);
					reverse(res.begin(), res.end());
					return true;
				}
			}
		}
	}
	return false;
}

int main() {
	scanf("%d%d%d", &n, &m, &K);
	for (int i = 0; i < m; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		a[i] = b[i + m] = x;
		b[i] = a[i + m] = y;
		mp[make_pair(x, y)] = i;
		mp[make_pair(y, x)] = i + m;
		e[x].push_back(i);
		e[y].push_back(i + m);
	}
	for (int i = 0; i < K; i++) {
		int x, y, z;
		scanf("%d%d%d", &x, &y, &z);
		if (mp.find(make_pair(x, y)) != mp.end() && mp.find(make_pair(y, z)) != mp.end()) {
			x = mp[make_pair(x, y)];
			y = mp[make_pair(y, z)];
			forbid.insert(make_pair(x, y));
		}
	}
	if (gao()) {
		printf("%u\n", res.size() - 1);
		for (vector <int>::const_iterator i = res.begin(); i != res.end(); i++) {
			printf("%d%c", *i, i + 1 == res.end() ? '\n' : ' ');
		}
	} else {
		puts("-1");
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <set>

using namespace std;

typedef pair <int, int> PII;

int n, m, K;
int a[40005], b[40005];
vector <int> e[3001];
vector <int> res;
set <PII> forbid;
map <pair <int, int>, int> mp;

int head, tail;
int Q[40005];
int pre[40005];
bool visited[40005];
void init() {
	head = tail = 0;
	memset(visited, 0, sizeof(visited));
}
void enQ(int x) {
	Q[tail++] = x;
}
int deQ() {
	return Q[head++];
}

bool gao() {
	init();
	for (vector <int>::const_iterator i = e[1].begin(); i != e[1].end(); i++) {
		pre[tail] = -1;
		enQ(*i);
		visited[*i] = true;
		if (b[*i] == n) {
			res.push_back(1);
			res.push_back(n);
			return true;
		}
	}
	while (head != tail) {
		int cur = head;
		int top = deQ();
		int u = b[top];
		for (vector <int>::const_iterator i = e[u].begin(); i != e[u].end(); i++) {
			if (!visited[*i] && forbid.find(make_pair(top, *i)) == forbid.end()) {
				pre[tail] = cur;
				enQ(*i);
				visited[*i] = true;
				if (b[*i] == n) {
					for (int j = tail - 1; j != -1; j = pre[j]) {
						res.push_back(b[Q[j]]);
					}
					res.push_back(1);
					reverse(res.begin(), res.end());
					return true;
				}
			}
		}
	}
	return false;
}

int main() {
	scanf("%d%d%d", &n, &m, &K);
	for (int i = 0; i < m; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		a[i] = b[i + m] = x;
		b[i] = a[i + m] = y;
		mp[make_pair(x, y)] = i;
		mp[make_pair(y, x)] = i + m;
		e[x].push_back(i);
		e[y].push_back(i + m);
	}
	for (int i = 0; i < K; i++) {
		int x, y, z;
		scanf("%d%d%d", &x, &y, &z);
		if (mp.find(make_pair(x, y)) != mp.end() && mp.find(make_pair(y, z)) != mp.end()) {
			x = mp[make_pair(x, y)];
			y = mp[make_pair(y, z)];
			forbid.insert(make_pair(x, y));
		}
	}
	if (gao()) {
		printf("%u\n", res.size() - 1);
		for (vector <int>::const_iterator i = res.begin(); i != res.end(); i++) {
			printf("%d%c", *i, i + 1 == res.end() ? '\n' : ' ');
		}
	} else {
		puts("-1");
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <set>

using namespace std;

typedef pair <int, int> PII;

int n, m, K;
int a[40000], b[40000];
vector <PII> e[3001];
vector <int> res;
set <PII> forbid;
map <pair <int, int>, int> mp;

int head, tail;
int Q[300000];
int pre[300000];
bool visited[300000];
void init() {
	head = tail = 0;
	memset(visited, 0, sizeof(visited));
}
void enQ(int x) {
	Q[tail++] = x;
}
int deQ() {
	return Q[head++];
}

bool gao() {
	init();
	for (vector <PII>::const_iterator i = e[1].begin(); i != e[1].end(); i++) {
		pre[tail] = -1;
		enQ(i->second);
		visited[i->second] = true;
	}
	while (head != tail) {
		int cur = head;
		int top = deQ();
		int u = b[top];
		for (vector <PII>::const_iterator i = e[u].begin(); i != e[u].end(); i++) {
			if (forbid.find(make_pair(top, i->second)) == forbid.end()) {
				pre[tail] = cur;
				enQ(i->second);
				visited[i->second] = true;
				if (b[i->second] == n) {
					for (int j = tail - 1; j != -1; j = pre[j]) {
						res.push_back(b[Q[j]]);
					}
					res.push_back(1);
					reverse(res.begin(), res.end());
					return true;
				}
			}
		}
	}
	return false;
}

int main() {
	scanf("%d%d%d", &n, &m, &K);
	for (int i = 0; i < m; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		a[i] = b[i + m] = x;
		b[i] = a[i + m] = y;
		mp[make_pair(x, y)] = i;
		mp[make_pair(y, x)] = i + m;
		e[x].push_back(make_pair(y, i));
		e[y].push_back(make_pair(x, i + m));
	}
	for (int i = 0; i < K; i++) {
		int x, y, z;
		scanf("%d%d%d", &x, &y, &z);
		if (mp.find(make_pair(x, y)) != mp.end() && mp.find(make_pair(y, z)) != mp.end()) {
			x = mp[make_pair(x, y)];
			y = mp[make_pair(y, z)];
			forbid.insert(make_pair(x, y));
		}
	}
	if (gao()) {
		printf("%u\n", res.size());
		for (vector <int>::const_iterator i = res.begin(); i != res.end(); i++) {
			printf("%d%c", *i, i + 1 == res.end() ? '\n' : ' ');
		}
	} else {
		puts("-1");
	}
	return 0;
}


/*
There are many faces of death
But none as horrific as the irrational slaying of innocent infants
The committing of infanticide

New born innocent victim
Killed by Mother's infliction
Psychotropic sickness
There will be no forgiveness

Severe mental psychosis
A state of non compos mentis

Blood that's frozen frigid
A heart of hardened ice
A breath of death to warm her
As she makes the sacrifice

Infanticide
Infanticide

Post Partum depression
The dying child's convulsion
Vicious act of madness
Emotional breakdown and sadness

Cold and callous
Mean and malice
Sad but true
Nothing you can do

Death desire that can't be tamed
Overflow her brain
For this death she's not to blame
You know that she's insane
Psychoactive chemicals affecting all perception
Termination elimination the removal of all conception

From the womb to the grave
How can we conceive
Trauma stricken mother
Sits crying in disbelief

Hormonal dysfunction
The innocent child's destruction
Born to die
Weeping mothers cry
Nothing but waste
Consequences faced

Cold and callous
Mean and malice
Sad but true
Nothing you can do

Demonic possession
Said to leave this message
Overpowering emotion
The mother and child's devotion

Blood that's frozen frigid
A heart of hardened ice
A breath of death to warm her
As she makes the sacrifice
*/

//#pragma comment(linker, "/STACK:16777216")
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>
#include <memory.h>
#include <ctime>

#define y0 sdkfaslhagaklsldk
#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash

#define eps 1e-11
//#define M_PI 3.141592653589793
#define bs 1000000009
#define bsize 256
#define right adsgasgadsg
#define free adsgasdg

using namespace std;

long dist[3050][3050];
set<long> bad[3050][3050];
long n,m,k,a,b,c;
pair<long, long> temp;
queue<pair<long, long> >qu;
vector<long> g[3050];
long par[3050][3050];
long bst,bp;
vector<long> ans;

int main(){
//freopen("capital.in","r",stdin);
//freopen("capital.out","w",stdout);
//freopen("C:/input.txt","r",stdin);
//freopen("C:/output.txt","w",stdout);
ios_base::sync_with_stdio(0);
//cin.tie(0);

cin>>n>>m>>k;
for (int i=1;i<=m;i++)
{
 cin>>a>>b;
 g[a].push_back(b);
 g[b].push_back(a);
}

for (int i=1;i<=k;i++)
{
 cin>>a>>b>>c;
 bad[a][b].insert(c);
}

qu.push(make_pair(1,1));

dist[1][1]=1;

while (qu.size())
{
 temp=qu.front();
 qu.pop();
 a=temp.first;
 b=temp.second;
 for (int i=0;i<g[b].size();i++)
 {
     long tv=g[b][i];
     if (bad[a][b].find(tv)!=bad[a][b].end())continue;
     if (dist[b][tv]!=0)continue;
     dist[b][tv]=dist[a][b]+1;
     par[b][tv]=a;
     qu.push(make_pair(b,tv));
 }
}

bst=1e9;
bp=1;
for (int i=1;i<=n;i++)
 if (dist[i][n]>0&&dist[i][n]<bst)
 {
  bst=dist[i][n];
  bp=i;
 }

if (bst>1e7)
{
 cout<<-1<<endl;
}
else
{
cout<<bst-1<<endl;
a=bp;
b=n;
ans.push_back(b);
while (a>1||b>1)
{
 long temp=a;
 a=par[a][b];
 b=temp;
 ans.push_back(temp);
}
reverse(ans.begin(),ans.end());
for (int i=0;i<ans.size();i++)
{
    if (i)cout<<" ";
    cout<<ans[i];
}
cout<<endl;
}

cin.get();cin.get();
return 0;}


/*
There are many faces of death
But none as horrific as the irrational slaying of innocent infants
The committing of infanticide

New born innocent victim
Killed by Mother's infliction
Psychotropic sickness
There will be no forgiveness

Severe mental psychosis
A state of non compos mentis

Blood that's frozen frigid
A heart of hardened ice
A breath of death to warm her
As she makes the sacrifice

Infanticide
Infanticide

Post Partum depression
The dying child's convulsion
Vicious act of madness
Emotional breakdown and sadness

Cold and callous
Mean and malice
Sad but true
Nothing you can do

Death desire that can't be tamed
Overflow her brain
For this death she's not to blame
You know that she's insane
Psychoactive chemicals affecting all perception
Termination elimination the removal of all conception

From the womb to the grave
How can we conceive
Trauma stricken mother
Sits crying in disbelief

Hormonal dysfunction
The innocent child's destruction
Born to die
Weeping mothers cry
Nothing but waste
Consequences faced

Cold and callous
Mean and malice
Sad but true
Nothing you can do

Demonic possession
Said to leave this message
Overpowering emotion
The mother and child's devotion

Blood that's frozen frigid
A heart of hardened ice
A breath of death to warm her
As she makes the sacrifice
*/

//#pragma comment(linker, "/STACK:16777216")
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>
#include <memory.h>
#include <ctime>

#define y0 sdkfaslhagaklsldk
#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash

#define eps 1e-11
//#define M_PI 3.141592653589793
#define bs 1000000009
#define bsize 256
#define right adsgasgadsg
#define free adsgasdg

using namespace std;

long dist[3050][3050];
set<long long> bad;

long n,m,k,a,b,c;
pair<long, long> temp;
queue<pair<long, long> >qu;
vector<long> g[3050];
long par[3050][3050];
long bst,bp;
vector<long> ans;

int main(){
//freopen("capital.in","r",stdin);
//freopen("capital.out","w",stdout);
//freopen("C:/input.txt","r",stdin);
//freopen("C:/output.txt","w",stdout);
ios_base::sync_with_stdio(0);
//cin.tie(0);

cin>>n>>m>>k;
for (int i=1;i<=m;i++)
{
 cin>>a>>b;
 g[a].push_back(b);
 g[b].push_back(a);
}

for (int i=1;i<=k;i++)
{
 cin>>a>>b>>c;
 bad.insert(1ll*a*10000000+b*3001+c);
}

qu.push(make_pair(1,1));

dist[1][1]=1;

while (qu.size())
{
 temp=qu.front();
 qu.pop();
 a=temp.first;
 b=temp.second;
 for (int i=0;i<g[b].size();i++)
 {
     long tv=g[b][i];
     if (bad.find(1ll*a*10000000+b*3001+tv)!=bad.end())continue;///[a][b].find(tv)!=bad[a][b].end())continue;
     if (dist[b][tv]!=0)continue;
     dist[b][tv]=dist[a][b]+1;
     par[b][tv]=a;
     qu.push(make_pair(b,tv));
 }
}

bst=1e9;
bp=1;
for (int i=1;i<=n;i++)
 if (dist[i][n]>0&&dist[i][n]<bst)
 {
  bst=dist[i][n];
  bp=i;
 }

if (bst>1e7)
{
 cout<<-1<<endl;
}
else
{
cout<<bst-1<<endl;
a=bp;
b=n;
ans.push_back(b);
while (a>1||b>1)
{
 long temp=a;
 a=par[a][b];
 b=temp;
 ans.push_back(temp);
}
reverse(ans.begin(),ans.end());
for (int i=0;i<ans.size();i++)
{
    if (i)cout<<" ";
    cout<<ans[i];
}
cout<<endl;
}

cin.get();cin.get();
return 0;}


#include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> pii;

const int INF = 1000000000;
const int MAXN = 3005, MAXE = 20005;
int n, m, k, dist[2 * MAXE], res = INF;
int mat[MAXN][MAXN] = {};
vector<int> adj[MAXN], adj2[2 * MAXE], rev[2 * MAXE];
vector<pii> ed;
set<int> tri[MAXN][MAXN];
queue<int> q;

int main(){
  cin >> n >> m >> k;
  for(int i = 0; i < m; i++){
    int a, b;
    cin >> a >> b;
    a--, b--;
    mat[a][b] = mat[b][a] = i + 1;
    ed.push_back(pii(a, b));
    dist[2 * i] = dist[2 * i + 1] = INF;
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      if(mat[i][j]) adj[i].push_back(mat[i][j] - 1);
    }
  }
  for(int i = 0; i < k; i++){
    int a, b, c;
    cin >> a >> b >> c;
    a--, b--, c--;
    tri[a][b].insert(c);
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j < adj[i].size(); j++){
      int u = 2 * adj[i][j] + (i == ed[adj[i][j]].first);
      int a = ed[u / 2].first ^ ed[u / 2].second ^ i;
      for(int k = 0; k < adj[i].size(); k++){
        int v = 2 * adj[i][k] + (i == ed[adj[i][k]].first);
        int b = ed[v / 2].first ^ ed[v / 2].second ^ i;
        if(tri[a][i].find(b) == tri[a][i].end()){
          adj2[u ^ 1].push_back(v);
          rev[v].push_back(u ^ 1);
        }
        if(tri[b][i].find(a) == tri[b][i].end()){
          adj2[v ^ 1].push_back(u);
          rev[u].push_back(v);
        }
      }
    }
  }
  for(int i = 0; i < adj[0].size(); i++){
    int v = 2 * adj[0][i] + (0 == ed[adj[0][i]].first);
    q.push(v);
    dist[v] = 1;
  }
  while(q.size()){
    int v = q.front();
    if(ed[v / 2].first == n - 1 || ed[v / 2].second == n - 1){
      cout << dist[v] << '\n';
      vector<int> lis;
      int c = n - 1, p = ed[v / 2].first ^ ed[v / 2].second ^ c;
      lis.push_back(c);
      while(dist[v] > 1){
        for(int i = 0; i < rev[v].size(); i++){
          if(dist[rev[v][i]] + 1 == dist[v]){
            v = rev[v][i];
            break;
          }
        }
        c = p;
        p = ed[v / 2].first ^ ed[v / 2].second ^ c;
        lis.push_back(c);
      }
      lis.push_back(0);
      for(int i = lis.size() - 1; i >= 0; i--) cout << lis[i] + 1 << ' ';
      cout << '\n';
      return 0;
    }
    q.pop();
    for(int i = 0; i < adj2[v].size(); i++){
      if(dist[adj2[v][i]] == INF){
        dist[adj2[v][i]] = dist[v] + 1;
        q.push(adj2[v][i]);
      }
    }
  }
  cout << "-1\n";
}


#include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> pii;
typedef pair<int,pii> pip;

const int INF = 1000000000;
const int MAXN = 3005, MAXE = 20005;
int n, m, k, dist[2 * MAXE], res = INF;
int mat[MAXN][MAXN] = {};
vector<int> adj[MAXN], adj2[2 * MAXE], rev[2 * MAXE];
vector<pii> ed;
set<pip> tri;
queue<int> q;

int main(){
  cin >> n >> m >> k;
  for(int i = 0; i < m; i++){
    int a, b;
    cin >> a >> b;
    a--, b--;
    mat[a][b] = mat[b][a] = i + 1;
    ed.push_back(pii(a, b));
    dist[2 * i] = dist[2 * i + 1] = INF;
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      if(mat[i][j]) adj[i].push_back(mat[i][j] - 1);
    }
  }
  for(int i = 0; i < k; i++){
    int a, b, c;
    cin >> a >> b >> c;
    a--, b--, c--;
    tri.insert(pip(a, pii(b, c)));
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j < adj[i].size(); j++){
      int u = 2 * adj[i][j] + (i == ed[adj[i][j]].first);
      int a = ed[u / 2].first ^ ed[u / 2].second ^ i;
      for(int k = 0; k < adj[i].size(); k++){
        int v = 2 * adj[i][k] + (i == ed[adj[i][k]].first);
        int b = ed[v / 2].first ^ ed[v / 2].second ^ i;
        if(tri.find(pip(a, pii(i, b))) == tri.end()){
          adj2[u ^ 1].push_back(v);
          rev[v].push_back(u ^ 1);
        }
        if(tri.find(pip(b, pii(i, a))) == tri.end()){
          adj2[v ^ 1].push_back(u);
          rev[u].push_back(v);
        }
      }
    }
  }
  for(int i = 0; i < adj[0].size(); i++){
    int v = 2 * adj[0][i] + (0 == ed[adj[0][i]].first);
    q.push(v);
    dist[v] = 1;
  }
  while(q.size()){
    int v = q.front();
    if(ed[v / 2].first == n - 1 || ed[v / 2].second == n - 1){
      cout << dist[v] << '\n';
      vector<int> lis;
      int c = n - 1, p = ed[v / 2].first ^ ed[v / 2].second ^ c;
      lis.push_back(c);
      while(dist[v] > 1){
        for(int i = 0; i < rev[v].size(); i++){
          if(dist[rev[v][i]] + 1 == dist[v]){
            v = rev[v][i];
            break;
          }
        }
        c = p;
        p = ed[v / 2].first ^ ed[v / 2].second ^ c;
        lis.push_back(c);
      }
      lis.push_back(0);
      for(int i = lis.size() - 1; i >= 0; i--) cout << lis[i] + 1 << ' ';
      cout << '\n';
      return 0;
    }
    q.pop();
    for(int i = 0; i < adj2[v].size(); i++){
      if(dist[adj2[v][i]] == INF){
        dist[adj2[v][i]] = dist[v] + 1;
        q.push(adj2[v][i]);
      }
    }
  }
  cout << "-1\n";
}


#include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> pii;
typedef pair<int,pii> pip;

const int INF = 1000000000;
const int MAXN = 3005, MAXE = 20005;
int n, m, k, dist[2 * MAXE], res = INF;
vector<int> adj[MAXN], adj2[2 * MAXE], rev[2 * MAXE];
vector<pii> ed;
set<pip> tri;
queue<int> q;

int main(){
  cin >> n >> m >> k;
  for(int i = 0; i < m; i++){
    int a, b;
    cin >> a >> b;
    a--, b--;
    adj[a].push_back(i);
    adj[b].push_back(i);
    ed.push_back(pii(a, b));
    dist[2 * i] = dist[2 * i + 1] = INF;
  }
  for(int i = 0; i < k; i++){
    int a, b, c;
    cin >> a >> b >> c;
    a--, b--, c--;
    tri.insert(pip(a, pii(b, c)));
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j < adj[i].size(); j++){
      int u = 2 * adj[i][j] + (i == ed[adj[i][j]].first);
      int a = ed[u / 2].first ^ ed[u / 2].second ^ i;
      for(int k = 0; k < adj[i].size(); k++){
        int v = 2 * adj[i][k] + (i == ed[adj[i][k]].first);
        int b = ed[v / 2].first ^ ed[v / 2].second ^ i;
        if(tri.find(pip(a, pii(i, b))) == tri.end()){
          adj2[u ^ 1].push_back(v);
          rev[v].push_back(u ^ 1);
        }
        if(tri.find(pip(b, pii(i, a))) == tri.end()){
          adj2[v ^ 1].push_back(u);
          rev[u].push_back(v);
        }
      }
    }
  }
  for(int i = 0; i < adj[0].size(); i++){
    int v = 2 * adj[0][i] + (0 == ed[adj[0][i]].first);
    q.push(v);
    dist[v] = 1;
  }
  while(q.size()){
    int v = q.front();
    if(ed[v / 2].first == n - 1 || ed[v / 2].second == n - 1){
      cout << dist[v] << '\n';
      vector<int> lis;
      int c = n - 1, p = ed[v / 2].first ^ ed[v / 2].second ^ c;
      lis.push_back(c);
      while(dist[v] > 1){
        for(int i = 0; i < rev[v].size(); i++){
          if(dist[rev[v][i]] + 1 == dist[v]){
            v = rev[v][i];
            break;
          }
        }
        c = p;
        p = ed[v / 2].first ^ ed[v / 2].second ^ c;
        lis.push_back(c);
      }
      lis.push_back(0);
      for(int i = lis.size() - 1; i >= 0; i--) cout << lis[i] + 1 << ' ';
      cout << '\n';
      return 0;
    }
    q.pop();
    for(int i = 0; i < adj2[v].size(); i++){
      if(dist[adj2[v][i]] == INF){
        dist[adj2[v][i]] = dist[v] + 1;
        q.push(adj2[v][i]);
      }
    }
  }
  cout << "-1\n";
}


#include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> pii;

const int INF = 1000000000;
const int MAXN = 3005, MAXE = 20005;
int n, m, k, dist[2 * MAXE], res = INF;
int mat[MAXN][MAXN] = {};
vector<int> adj[MAXN], adj2[2 * MAXE], rev[2 * MAXE];
vector<pii> ed;
set<pii> tri[MAXN];
queue<int> q;

int main(){
  cin >> n >> m >> k;
  for(int i = 0; i < m; i++){
    int a, b;
    cin >> a >> b;
    a--, b--;
    mat[a][b] = mat[b][a] = i + 1;
    ed.push_back(pii(a, b));
    dist[2 * i] = dist[2 * i + 1] = INF;
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      if(mat[i][j]) adj[i].push_back(mat[i][j] - 1);
    }
  }
  for(int i = 0; i < k; i++){
    int a, b, c;
    cin >> a >> b >> c;
    a--, b--, c--;
    tri[a].insert(pii(b, c));
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j < adj[i].size(); j++){
      int u = 2 * adj[i][j] + (i == ed[adj[i][j]].first);
      int a = ed[u / 2].first ^ ed[u / 2].second ^ i;
      for(int k = 0; k < adj[i].size(); k++){
        int v = 2 * adj[i][k] + (i == ed[adj[i][k]].first);
        int b = ed[v / 2].first ^ ed[v / 2].second ^ i;
        if(tri[a].find(pii(i, b)) == tri[a].end()){
          adj2[u ^ 1].push_back(v);
          rev[v].push_back(u ^ 1);
        }
        if(tri[b].find(pii(i, a)) == tri[b].end()){
          adj2[v ^ 1].push_back(u);
          rev[u].push_back(v);
        }
      }
    }
  }
  for(int i = 0; i < adj[0].size(); i++){
    int v = 2 * adj[0][i] + (0 == ed[adj[0][i]].first);
    q.push(v);
    dist[v] = 1;
  }
  while(q.size()){
    int v = q.front();
    if(ed[v / 2].first == n - 1 || ed[v / 2].second == n - 1){
      cout << dist[v] << '\n';
      vector<int> lis;
      int c = n - 1, p = ed[v / 2].first ^ ed[v / 2].second ^ c;
      lis.push_back(c);
      while(dist[v] > 1){
        for(int i = 0; i < rev[v].size(); i++){
          if(dist[rev[v][i]] + 1 == dist[v]){
            v = rev[v][i];
            break;
          }
        }
        c = p;
        p = ed[v / 2].first ^ ed[v / 2].second ^ c;
        lis.push_back(c);
      }
      lis.push_back(0);
      for(int i = lis.size() - 1; i >= 0; i--) cout << lis[i] + 1 << ' ';
      cout << '\n';
      return 0;
    }
    q.pop();
    for(int i = 0; i < adj2[v].size(); i++){
      if(dist[adj2[v][i]] == INF){
        dist[adj2[v][i]] = dist[v] + 1;
        q.push(adj2[v][i]);
      }
    }
  }
  cout << "-1\n";
}


#pragma comment(linker,"/STACK:100000000,100000000")

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <stack>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <iomanip>
#include <queue>
#include <map>
#include <functional>
#include <memory.h>
#include <list>
#include <ctime>
using namespace std;

const long long inf = 1e9+7;
const long long mod = 1e9+7;
const long double eps = 1e-9;
const long double pi = 2*acos(0.0);
const long double e = 2.71828;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<ll> vi;
typedef vector<pii> vii;
typedef vector<vector<ll> > tree;
typedef vector<vector<pair<ll,ll> > > graph;

#define cleen(c) memset((c),0,sizeof((c)))

map <pii,bool> h;
map <pii,int> dist;
map <pii,pii> path;

map <pii,set<int> > mm;

tree g;

pii last;

int bfs(int p,int v,int need)
{
    queue<pii> Q; Q.push(make_pair(p,v));
    while(!Q.empty())
    {
        int x = Q.front().first,y = Q.front().second;
        Q.pop();    h[make_pair(x,y)] = 1;
        if(y == need)
        {
            last = make_pair(x,y);
            return dist[make_pair(x,y)];
        }
        for(int i=0;i<g[y].size();i++)
        {
            int to = g[y][i];
                if(mm[make_pair(x,y)].count(to) != 0) continue;
                if(h[make_pair(y,to)]) continue;
            Q.push(make_pair(y,to));
            dist[make_pair(y,to)] = dist[make_pair(x,y)] + 1;
            path[make_pair(y,to)] = make_pair(x,y);
        }
    }
    return -1;
}

int main(void)
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt","rt",stdin);
        freopen("output.txt","wt",stdout);
    #endif
    int n,m,k;
        cin >> n >> m >> k; g.resize(n);
    for(int i=0;i<m;i++)
    {
        int x,y;cin >> x >> y;x--;y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    for(int i=0;i<k;i++)
    {
        int x,y,z; cin >> x >> y >> z;x--;y--;z--;
        mm[make_pair(x,y)].insert(z);
    }
    int rez = bfs(0,1,n-1);    cout << rez << endl;
    if(rez != -1)
    {
        vector<int>ans ;
        for(pii cur = last;cur != make_pair(0,1) ; cur = path[cur])
        {
            ans.push_back(cur.second);
        }
        for(int i=ans.size()-1;i>=0;i--)
        {
            cout << ans[i]+1 << " ";
        }
        cout << endl;
    }
    return 0;
}


#pragma comment(linker,"/STACK:100000000,100000000")

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <stack>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <iomanip>
#include <queue>
#include <map>
#include <functional>
#include <memory.h>
#include <list>
#include <ctime>
using namespace std;

const long long inf = 1e9+7;
const long long mod = 1e9+7;
const long double eps = 1e-9;
const long double pi = 2*acos(0.0);
const long double e = 2.71828;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<ll> vi;
typedef vector<pii> vii;
typedef vector<vector<ll> > tree;
typedef vector<vector<pair<ll,ll> > > graph;

#define cleen(c) memset((c),0,sizeof((c)))

map <pii,bool> h;
map <pii,int> dist;
map <pii,pii> path;

map <pii,set<int> > mm;

tree g;

pii last;

int bfs(int p,int v,int need)
{
    queue<pii> Q; Q.push(make_pair(p,v));
    while(!Q.empty())
    {
        int x = Q.front().first,y = Q.front().second;
        Q.pop();    h[make_pair(x,y)] = 1;
        if(y == need)
        {
            last = make_pair(x,y);
            return dist[make_pair(x,y)]-1;
        }
        for(int i=0;i<g[y].size();i++)
        {
            int to = g[y][i];
                if(mm[make_pair(x,y)].count(to) != 0) continue;
                if(h[make_pair(y,to)]) continue;
            Q.push(make_pair(y,to));
            dist[make_pair(y,to)] = dist[make_pair(x,y)] + 1;
            path[make_pair(y,to)] = make_pair(x,y);
        }
    }
    return -1;
}

int main(void)
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt","rt",stdin);
        freopen("output.txt","wt",stdout);
    #endif
    int n,m,k;
        cin >> n >> m >> k; g.resize(n);
    for(int i=0;i<m;i++)
    {
        int x,y;cin >> x >> y;x--;y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    for(int i=0;i<k;i++)
    {
        int x,y,z; cin >> x >> y >> z;x--;y--;z--;
        mm[make_pair(x,y)].insert(z);
    }
    int rez = bfs(0,1,n-1);    cout << rez << endl;
    if(rez != -1)
    {
        vector<int>ans ;
        for(pii cur = last;cur != make_pair(0,1) ; cur = path[cur])
        {
            ans.push_back(cur.second);
        }
        for(int i=ans.size()-1;i>=0;i--)
        {
            cout << ans[i]+1 << " ";
        }
        cout << endl;
    }
    return 0;
}


#pragma comment(linker,"/STACK:100000000,100000000")

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <stack>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <iomanip>
#include <queue>
#include <map>
#include <functional>
#include <memory.h>
#include <list>
#include <ctime>
using namespace std;

const long long inf = 1e9+7;
const long long mod = 1e9+7;
const long double eps = 1e-9;
const long double pi = 2*acos(0.0);
const long double e = 2.71828;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<ll> vi;
typedef vector<pii> vii;
typedef vector<vector<ll> > tree;
typedef vector<vector<pair<ll,ll> > > graph;

#define cleen(c) memset((c),0,sizeof((c)))

map <pii,bool> h;
map <pii,int> dist;
map <pii,pii> path;

map <pii,set<int> > mm;

tree g;

pii last;

int bfs(int p,int v,int need)
{
    queue<pii> Q; Q.push(make_pair(p,v)); dist[make_pair(p,v)] = 0;
    while(!Q.empty())
    {
        int x = Q.front().first,y = Q.front().second;
        Q.pop();    h[make_pair(x,y)] = 1;
        if(y == need)
        {
            last = make_pair(x,y);
            return dist[make_pair(x,y)];
        }
        for(int i=0;i<g[y].size();i++)
        {
            int to = g[y][i];
                if(mm[make_pair(x,y)].count(to) != 0) continue;
                if(h[make_pair(y,to)]) continue;
            Q.push(make_pair(y,to));h[make_pair(y,to)] = 1;
            dist[make_pair(y,to)] = dist[make_pair(x,y)] + 1;
            path[make_pair(y,to)] = make_pair(x,y);
        }
    }
    return -1;
}

int main(void)
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt","rt",stdin);
        freopen("output.txt","wt",stdout);
    #endif
    int n,m,k;
        cin >> n >> m >> k; g.resize(n+1);
    for(int i=0;i<m;i++)
    {
        int x,y;cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    for(int i=0;i<k;i++)
    {
        int x,y,z; cin >> x >> y >> z;
        mm[make_pair(x,y)].insert(z);
    }
    int rez = bfs(0,1,n);    cout << rez << endl;
    if(rez != -1)
    {
        vector<int>ans ;
        for(pii cur = last;cur != make_pair(0,1) ; cur = path[cur])
        {
            ans.push_back(cur.second);
        }
        ans.push_back(1);
        for(int i=ans.size()-1;i>=0;i--)
        {
            cout << ans[i] << " ";
        }
        cout << endl;
    }
    return 0;
}


#pragma comment(linker,"/STACK:100000000,100000000")

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <stack>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <iomanip>
#include <queue>
#include <map>
#include <functional>
#include <memory.h>
#include <list>
#include <ctime>
using namespace std;

const long long inf = 1e9+7;
const long long mod = 1e9+7;
const long double eps = 1e-9;
const long double pi = 2*acos(0.0);
const long double e = 2.71828;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<ll> vi;
typedef vector<pii> vii;
typedef vector<vector<ll> > tree;
typedef vector<vector<pair<ll,ll> > > graph;

#define cleen(c) memset((c),0,sizeof((c)))

map <pii,bool> h;
map <pii,int> dist;
map <pii,pii> path;

map <pii,set<int> > mm;

tree g;

pii last;

int bfs(int p,int v,int need)
{
    queue<pii> Q; Q.push(make_pair(p,v));
    while(!Q.empty())
    {
        int x = Q.front().first,y = Q.front().second;
        Q.pop();    h[make_pair(x,y)] = 1;
        if(y == need)
        {
            last = make_pair(x,y);
            return dist[make_pair(x,y)]+1;
        }
        for(int i=0;i<g[y].size();i++)
        {
            int to = g[y][i];
                if(mm[make_pair(x,y)].count(to) != 0) continue;
                if(h[make_pair(y,to)]) continue;
            Q.push(make_pair(y,to));
            dist[make_pair(y,to)] = dist[make_pair(x,y)] + 1;
            path[make_pair(y,to)] = make_pair(x,y);
        }
    }
    return -1;
}

int main(void)
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt","rt",stdin);
        freopen("output.txt","wt",stdout);
    #endif
    int n,m,k;
        cin >> n >> m >> k; g.resize(n);
    for(int i=0;i<m;i++)
    {
        int x,y;cin >> x >> y;x--;y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    for(int i=0;i<k;i++)
    {
        int x,y,z; cin >> x >> y >> z;x--;y--;z--;
        mm[make_pair(x,y)].insert(z);
    }
    int rez = bfs(0,1,n-1);    cout << rez << endl;
    if(rez != -1)
    {
        vector<int>ans ;
        for(pii cur = last;cur != make_pair(0,1) ; cur = path[cur])
        {
            ans.push_back(cur.second);
        }
        for(int i=ans.size()-1;i>=0;i--)
        {
            cout << ans[i]+1 << " ";
        }
        cout << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<LL, int> II;
struct Edge {
    int u, v;
    Edge() {};
    Edge(int u, int v): u(u), v(v) {};
    bool operator < (const Edge &E) const {
        return u < E.u || (u == E.u && v < E.v);
    }
};

const int N = (int) 3e3 + 10;
const int M = (int) 4e4 + 10;
int n, m, k, p[M], d[M];
vector<int> adj[N];
bitset<N> allow[M];
Edge E[M];

void Trace(int e) {
    stack<int> S;
    while (E[e].u != 1) {
        S.push(E[e].v);
        e = p[e];
    }
    S.push(E[e].v);
    S.push(1);

    printf("%d\n", (int) S.size() - 1);
    while (S.size()) {
        printf("%d ", S.top());
        S.pop();
    }
}

int main() {
    #ifdef LOCAL
        freopen("Data.inp", "r", stdin);
        freopen("Data.out", "w", stdout);
    #endif

    scanf("%d%d%d", &n, &m, &k);
    for (int i = 1; i <= m; ++i) {
        int u, v; scanf("%d%d", &u, &v);
        E[i + 0] = Edge(u, v); adj[u].push_back(i + 0);
        E[i + m] = Edge(v, u); adj[v].push_back(i + m);
    }
    m <<= 1;

    map<Edge, int> pos;
    for (int i = 1; i <= m; ++i) pos[E[i]] = i, allow[i].flip();
    for (int i = 1; i <= k; ++i) {
        int a, b, c; scanf("%d%d%d", &a, &b, &c);
        allow[pos[Edge(a, b)]].set(c, 0);
    }

    queue<int> Q; memset(d, -1, sizeof d);
    for (int i = 0; i < (int) adj[1].size(); ++i) {
        int x = adj[1][i];
        Q.push(x); d[x] = 1;
    }
    while (Q.size()) {
        int x = Q.front(); Q.pop();
        int u = E[x].v;
        if (u == n) {
            Trace(x);
            return 0;
        }
        for (int i = 0; i < (int) adj[u].size(); ++i) {
            int y = adj[u][i];
            int v = E[y].v;
            if (allow[x][v] && d[y] == -1) {
                d[y] = d[x] + 1;
                p[y] = x;
                Q.push(y);
            }
        }
    }

    puts("-1");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<LL, int> II;
struct Edge {
    int u, v;
    Edge() {};
    Edge(int u, int v): u(u), v(v) {};
    bool operator < (const Edge &E) const {
        return u < E.u || (u == E.u && v < E.v);
    }
};

const int N = (int) 3e3 + 10;
const int M = (int) 4e4 + 10;
int n, m, k, p[M], d[M];
vector<int> adj[N];
bitset<N> allow[M];
Edge E[M];

void Trace(int e) {
    stack<int> S;
    while (E[e].u != 1) {
        S.push(E[e].v);
        e = p[e];
    }
    S.push(E[e].v);
    S.push(1);

    printf("%d\n", (int) S.size() - 1);
    while (S.size()) {
        printf("%d ", S.top());
        S.pop();
    }
}

int main() {
    #ifdef LOCAL
        freopen("Data.inp", "r", stdin);
        freopen("Data.out", "w", stdout);
    #endif

    scanf("%d%d%d", &n, &m, &k);
    for (int i = 1; i <= m; ++i) {
        int u, v; scanf("%d%d", &u, &v);
        E[i + 0] = Edge(u, v); adj[u].push_back(i + 0);
        E[i + m] = Edge(v, u); adj[v].push_back(i + m);
    }
    m <<= 1;

    map<Edge, int> pos;
    for (int i = 1; i <= m; ++i) pos[E[i]] = i, allow[i].flip();
    for (int i = 1; i <= k; ++i) {
        int a, b, c; scanf("%d%d%d", &a, &b, &c);
        allow[pos[Edge(a, b)]].set(c, 0);
    }

    queue<int> Q; memset(d, -1, sizeof d);
    for (int i = 0; i < (int) adj[1].size(); ++i) {
        int x = adj[1][i];
        Q.push(x); d[x] = 1;
    }
    while (Q.size()) {
        int x = Q.front(); Q.pop();
        int u = E[x].v;
        for (int i = 0; i < (int) adj[u].size(); ++i) {
            int y = adj[u][i];
            int v = E[y].v;
            if (allow[x][v] && d[y] == -1) {
                d[y] = d[x] + 1;
                p[y] = x;
                Q.push(y);
            }
        }
    }

    for (int i = 1; i <= m; ++i) {
        if (E[i].v != n) continue;
        Trace(i);
        return 0;
    }
    puts("-1");
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <map>
#include <string.h>
#include <vector>
#include <set>
#include <stack>

const int N=3010;
const int inf=0x3f3f3f3f;

using namespace std;

#define pb push_back
#define sz(x) ((x).size())
#define f first
#define s second
#define pr pair<int,int>
#define mp make_pair

vector<int> vt[N];

struct data
{
	int a,b,c;
	data() {}
	data(int a,int b,int c) :a(a),b(b),c(c) {}
	bool operator < (const data &r) const
	{
		if(a!=r.a) return a<r.a;
		if(b!=r.b) return b<r.b;
		return c<r.c;
	}
};

set<data> st;

int n,m,k,dis[N][N];
bool vis[N][N];

void spfa(int s)
{
	memset(dis,0x3f,sizeof(dis));
	queue<pr > que;
	que.push(mp(s,0));
	dis[s][0]=0;
	vis[s][0]=1;
	while(que.size())
	{
		pr u=que.front();
		que.pop();
		vis[u.f][u.s]=0;
		for(int i=0;i<sz(vt[u.f]);i++)
		{
			int v=vt[u.f][i];
			if(st.count(data(u.s,u.f,v))) continue;
			if(dis[v][u.f]<=dis[u.f][u.s]+1) continue;
			dis[v][u.f]=dis[u.f][u.s]+1;
			if(vis[v][u.f]) continue;
			vis[v][u.f]=1;
			que.push(mp(v,u.f));
		}
	}
}

void dfs(int a,int b)
{
	cout<<a<<" ";
	if(a==n) {cout<<endl;return ;}
	for(int i=0;i<=n;i++)
		if(dis[a][b]==dis[b][i]+1 && (!st.count(data(i,b,a)))) {dfs(b,i);return ;}
}

int main()
{
	scanf("%d%d%d",&n,&m,&k);
	for(int i=0;i<m;i++)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		vt[a].pb(b);
		vt[b].pb(a);
	}
	for(int i=0;i<k;i++)
	{
		int a,b,c;
		scanf("%d%d%d",&c,&b,&a);
		st.insert(data(a,b,c));
	}
	spfa(n);
	int ret=inf,id=-1;
	for(int i=1;i<=n;i++)
		ret=min(ret,dis[1][i]);
	for(int i=1;i<=n;i++)
		if(dis[1][i]==ret) id=i;
	if(ret==inf)
	{
		cout<<-1<<endl;
		return 0;
	}
	cout<<ret<<endl;
	dfs(1,id);
	return 0;
}