Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <utility>
- using namespace std;
- const long long SIZE=1005;
- long long table[SIZE];
- int main(){
- ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
- long long d, f, i, p, mx=0, cur, j; cin >> d >> f;
- vector<pair<string, long long>> files(d+5);
- vector<bool> used(f+5, false);
- string filename, ans;
- for(i=1; i<=d; ++i){
- cin >> filename >> p;
- files[i]={filename, p};
- }
- for(i=1; i<=f; ++i){
- cin >> p;
- table[i]=p;
- }
- for(i=1; i<=d; ++i){
- cur=0;
- used=vector<bool>(f+5, false);
- for(j=files[i].second; j!=-1; j=table[j], ++cur){
- if(used[j]){
- cout << files[i].first << " CYCLE";
- return 0;
- }
- if(!j){
- cout << files[i].first << " BAD";
- return 0;
- }
- used[j]=true;
- }
- if(cur>mx){
- mx=cur;
- ans=files[i].first;
- }
- }
- cout << ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement