标签:
input | output |
---|---|
5 6 1 3 1 4 3 5 5 2 4 2 1 2 1 3 4 5 2 |
YES |
5 6 1 3 1 4 3 5 5 2 4 2 1 2 1 2 4 5 3 |
NO |
#include <iostream> #include <cstring> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <time.h> #include <string> #include <map> #include <stack> #include <vector> #include <set> #include <queue> #define inf 10000000 #define mod 10000 typedef long long ll; using namespace std; const int N=1005; const int M=100005; int power(int a,int b,int c){int ans=1;while(b){if(b%2==1){ans=(ans*a)%c;b--;}b/=2;a=a*a%c;}return ans;} int in[N],vis[N],w[N][N]; int n,m,k; vector<int>vec[N]; int main() { int a,b; bool flag=true; scanf("%d%d",&n,&m); while(m--){ scanf("%d%d",&a,&b); if(!w[a][b]){ w[a][b]=1; vec[a].push_back(b); } } for(int i=1;i<=n;i++){ scanf("%d",&in[i]); } for(int i=1;i<=n;i++){ int cnt=0; for(int j=i+1;j<=n;j++){ if(w[in[i]][in[j]])cnt++; } if(cnt!=vec[in[i]].size())flag=false; } if(flag)printf("YES\n"); else printf("NO\n"); return 0; }
URAL(timus) 1280 Topological Sorting(模拟)
标签:
原文地址:http://www.cnblogs.com/jianrenfang/p/5856205.html