Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <vector>
- #include<algorithm>
- #include<string>
- #include<math.h>
- #pragma comment(linker, "/STACK:66777216")
- using namespace std;
- #define ll unsigned _int64
- vector<ll>u;
- vector<pair<string, vector<string>>>p;
- ll n;
- bool dfs(string s, vector<string>v, ll j) {
- u[j] = 1;
- for (string s1 : v) {
- if (s1 == s)return(1);
- ll i = 0;
- for (i; i < n; i++) {
- if (p[i].first == s1) break;
- }
- if (!u[i])dfs(s1, p[i].second, i);
- else return(0);
- }
- }
- int main() {
- ios_base::sync_with_stdio(false);
- // #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- // #endif
- cin >> n;
- u.resize(n);
- for (ll i = 0; i < n; i++) {
- ll c;
- string s;
- cin >> s >> c;
- vector<string>cc(c, "");
- p.emplace_back(make_pair(s, cc));
- for (ll j = 0; j < c; j++) {
- cin >> p[i].second[j];
- }
- cin >> s;
- }
- ll i = 0;
- for (pair<string, vector<string>> a : p) {
- cout << a.first << ':' << ' ';
- if (dfs(a.first, a.second, i)) {
- ll f = 1;
- for (ll o : u) {
- if (!o) {
- cout << "NO" << endl;
- f = 0;
- break;
- }
- }
- if (f)cout << "YES" << endl;
- }
- else cout << "NO" << endl;
- i++;
- u.assign(n, 0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement