SPOJ PT07Y

来源:互联网 发布:ntfs for mac 未安装 编辑:程序博客网 时间:2024/06/05 21:15
// http://www.spoj.com/problems/PT07Y/#include <iostream>using namespace std;int findroot(int* points, int p) {while (points[p] != p) p = points[p];return p;}int main() {int V, E;cin >> V >> E;int *points = new int[V+1];for (int i = 1; i <= V; i++) {points[i] = i;}bool YES = true;for (int i = 0; i < E; i++) {int u, v;cin >> u >> v;if (!YES) continue;int rootu = findroot(points, u);int rootv = findroot(points, v);if (rootu != rootv) {points[v] = u;continue;}else {YES = false;}}if (YES) {cout << "YES" << endl;}else {cout << "NO" << endl;}return 0;}

0 0
原创粉丝点击