poj 2513 Colored Sticks
来源:互联网 发布:淘宝客服能在家里做吗 编辑:程序博客网 时间:2024/06/04 18:56
poj.org/problem?id=2513
欧拉路径裸体 唯一需要注意的是给每个颜色一个序号 这个可以使用哈希 但是我使用的是前缀树
#include <math.h>#include <vector>#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>using namespace std;const int MAX = 500010;const int INF = 0x3f3f3f3f;int cnt;int deg[MAX],father[MAX];struct trie{ bool Isword; int next[26];}node[MAX];struct edge{ int v,next;}E[MAX];void Init(){ cnt = 1; for(int i=0; i<MAX; i++){ memset(node[i].next, -1, sizeof(node[i].next)); node[i].Isword = false; father[i] = i; }}int Find(int x){ if(x != father[x]) father[x] = Find(father[x]); return father[x];}int Insert(char *s){ int p = 0, n = strlen(s); for(int i=0; i<n; i++){ if(node[p].next[s[i]-'a'] == -1) node[p].next[s[i]-'a'] = cnt++; p = node[p].next[s[i]-'a']; } node[p].Isword = true; return p;}int main(){ char s1[15],s2[15]; Init(); memset(deg, 0, sizeof(deg)); while(scanf("%s%s",s1,s2) != EOF){ int u = Insert(s1), v = Insert(s2); deg[u]++, deg[v]++; father[Find(u)] = Find(v); } int num = 0; for(int i=0; i<MAX; i++){ if(!deg[i]) continue; if(father[i] == i) num++; } if(num > 1) puts("Impossible"); else{ int tmp = 0; for(int i=0; i<MAX; i++){ if(!deg[i]) continue; if(deg[i] & 1) tmp++; } if(!tmp || tmp == 2) puts("Possible"); else puts("Impossible"); } return 0;}
0 0
- POJ 2513 Colored Sticks
- poj 2513 Colored Sticks
- POJ 2513 Colored Sticks
- poj 2513 colored sticks
- Poj 2513 Colored Sticks
- POJ 2513 Colored Sticks
- POJ 2513 Colored Sticks
- POJ 2513 Colored Sticks
- poj 2513 Colored Sticks
- poj 2513 Colored Sticks
- POJ 2513 Colored Sticks
- POJ 2513 Colored Sticks
- Poj 2513 Colored Sticks
- poj 2513 Colored Sticks
- POJ 2513 Colored Sticks
- POJ 2513 Colored Sticks
- poj 2513 Colored Sticks
- POJ 2513 Colored Sticks
- app-framework学习--panel传值
- 使用 UI Automation 实现自动化测试--4.1
- linus教你写链表
- EBS 博客
- CSS3+HTML5表单
- poj 2513 Colored Sticks
- 用python写的多线程网页爬虫
- tar、tar.gz、tar.bz2的区别与用法
- MATLAB学习笔记(二):符号计算(创建符号对象)
- Socket通信基础——基于TCP的用户登录
- POJ 3624 01背包
- centos mysql安装
- Lexicographically minimum string rotation
- JavaScript系列二:变量、数组、流程控制、函数以及事件响应