codeforces 510c Fox And Names 拓扑排序
来源:互联网 发布:无印良品水乳 知乎 编辑:程序博客网 时间:2024/05/17 08:23
#include <cstdio>#include <cstring>#include <iostream>#include <queue>using namespace std;int t;int ma[30][30];char a[105][105];void tpusort(){int d[30];queue<int> que;queue<int> ans;int dd = 0;for(int i = 0;i < 26;i++){int cc = 0;for(int j = 0;j < 26;j++){cc += ma[j][i];}d[i] = cc;if(cc == 0){que.push(i);}}while(!que.empty()){int tm = que.front();que.pop();ans.push(tm);for(int i = 0;i < 26;i++){if(ma[tm][i] == 1){ma[tm][i] = 0;d[i]--;if(d[i] == 0){que.push(i);}}}}if(ans.size() == 26){while(!ans.empty()){int tm = ans.front();ans.pop();putchar(tm+'a');}printf("\n");}else{printf("Impossible\n");}}int main(){scanf("%d",&t);memset(ma,0,sizeof(ma));for(int i = 0;i < t;i++){scanf("%s",a[i]);}int flag = 1;for(int i = 0;i < t;i++){for(int j = 0;j < i;j++){for(int k = 0;a[j][k];k++){if(a[i][k] == '\0'){flag = 0;break;}if(a[i][k] != a[j][k]){ma[a[j][k]-'a'][a[i][k]-'a'] = 1;break;}}}}if(flag){tpusort();}else{printf("Impossible\n");}return 0;}
0 0
- codeforces 510C Fox And Names 拓扑排序
- Codeforces 510C - Fox And Names (拓扑排序)
- Codeforces 510C Fox And Names 拓扑排序
- codeforces 510c Fox And Names 拓扑排序
- [CodeForces 510C]Fox And Names[字典序][拓扑排序]
- Codeforces 510C Fox And Names 拓扑排序
- [CodeForces] 510 C Fox And Names [拓扑排序]
- 拓扑排序 CodeForces - 510C Fox And Names
- Codeforces 510C Fox And Names【拓扑排序】
- codeforces 510C Fox And Names 拓扑
- [拓扑] Codeforces #510C. Fox And Names
- 拓扑排序 Fox And Names : CodeForces
- 【CodeForces】510C - Fox And Names(拓扑 & STL)
- Codeforces 510C Fox And Names 拓扑序+判环
- CF 510C(Fox And Names-拓扑排序)
- 510C Fox And Names(拓扑排序)
- CF 510C Fox And Names(拓扑排序)
- CF 510C Fox And Names【拓扑排序】
- java 小项目:简单扑克牌游戏
- win7平台下QT软件的打包与发布 (利用NSIS脚本制作安装包)
- Magento迁移服务器
- C#.ToString()格式大全
- weka实战005:基于HashSet实现的apriori关联规则算法
- codeforces 510c Fox And Names 拓扑排序
- Dubbo与Zookeeper、SpringMVC整合和使用(负载均衡、容错)
- 《C#高级编程》【第五章】泛型 -- 学习笔记
- UIImage类中的常用拉伸方法
- STL Vector整理
- 重新认识史蒂夫·乔布斯
- Swift流程控制
- 【Trie】【cogs647】有道搜索框
- 线程同步 资源锁定(一)