ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1280. Topological Sorting

AC IN 0.234 SEC
Posted by abid1729 25 Jun 2019 19:21
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long m,i,n,a[100005][2],k,b[1005];
    cin>>n>>m;
    for(i=0;i<m;i++){
        cin>>a[i][0]>>a[i][1];
    }
    for(i=0;i<n;i++){
        cin>>k;
        b[k]=i;
    }
        for(i=0;i<m;i++){
                if(b[a[i][0]]>b[a[i][1]]){
                    cout<<"NO";
                    return 0;
                }
        }
        cout<<"YES";
}