提交时间:2024-10-22 15:46:23
运行 ID: 33798
//60 #include <bits/stdc++.h> using namespace std; int n,m; vector <int> e[4003]; vector <char> w[4003]; int u,v; char c; int main () { cin >> n >> m; if (n == m) { int cnt = 0; for (int i = 1;i <= m;i++) { cin >> u >> v >> c; if (c == '(') { cnt++; } } if (cnt * 2 == m) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; } for (int i = 1;i <= m;i++) { cin >> u >> v >> c; e[u].push_back(v); w[u].push_back(c); } int x = -1,y = -1; for (int i = 1;i <= n;i++) { int sz = e[u].size(); for(int j = 0;j < sz;j++) { if (e[u][j] == u && w[u][j] == '(') { x = u; } if (e[u][j] == u && w[u][j] == ')') { y = u; } } } if (x == -1 || y == -1) { cout << "No" << endl; } else { cout << "Yes" << endl; } return 0; }