[BestCoder] Round #25 1001 - Harry and Magical Computer | HDU 5154
2015-01-03 23:23
411 查看
题目给了中文描述,所以不再多说。
裸拓扑排序,直接用队列维护入度为零的结点,判断是否能完全删除M条边即可。
裸拓扑排序,直接用队列维护入度为零的结点,判断是否能完全删除M条边即可。
#include <stdio.h> #include <map> #include <queue> #include <vector> using namespace std; int main() { int cnt, n, m, a, b, v[1000]; while(~scanf("%d %d", &n, &m)) { cnt = 0; vector<int> vv[101]; map<int, int> mm; queue<int> qq; for(int i = 0; i < m; i++) { scanf("%d %d", &a, &b); vv[a].push_back(b); mm[b]++; } for(int i = 1; i <= n; i++) { if(!mm[i] && vv[i].size()) { qq.push(i); } } while(!qq.empty()) { int k = qq.front(); qq.pop(); for(int i = 0; i < vv[k].size(); i++) { mm[vv[k][i]]--; if(!mm[vv[k][i]]) { qq.push(vv[k][i]); } ++cnt; } } if(cnt == m) { printf("YES\n"); } else { printf("NO\n"); } } return 0; }
相关文章推荐
- hdu 5154 Harry and Magical Computer(BestCoder Round #25)
- [BestCoder Round #25 1003]Harry and Christmas tree
- hdu 5154 Harry and Magical Computer 拓扑排序
- HDU 5154 Harry and Magical Computer (BFS)
- HDU 5154 Harry and Magical Computer(找环)
- HDU 5154 Harry and Magical Computer (拓扑排序)
- hdu 5154 Harry and Magical Computer
- hdu 5154 Harry and Magical Computer
- [BestCoder Round #25 1002]Harry And Magic Box 解题报告
- Harry and Magical Computer (HDU 5154)
- hdu 5154 Harry and Magical Computer
- hdu 5154 -- Harry and Magical Computer
- 【CUGBACM15级BC第25场 A】hdu 5154 Harry and Magical Computer
- HDU 5154 Harry and Magical Computer 拓扑排序
- 拓扑序列 之 hdu 5154 Harry and Magical Computer
- HDU 5154 Harry and Magical Computer bfs
- HDU 5154 Harry and Magical Computer 有向图判环
- hdu 5154 Harry and Magical Computer(拓扑排序)
- HDU 5154 Harry and Magical Computer (拓扑排序)
- hdu_5154 Harry and Magical Computer