poj 2513 很多RE,很多WA
来源:互联网 发布:vim python 语法高亮 编辑:程序博客网 时间:2024/04/29 12:33
很多的错误,狂交了几十遍,哈哈~
最后总结如下:
RE:数组越界
WA:字母拼错
建trie树之后再加一个并查集,用来查询图是否连通以及很方便的记录每个点的度数
View Code
//runtime error 的原因:初始化的时候从1到MAX赋值,数组越界,牢记啊!!!
//WA原因: Impossible拼错。。囧!
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
using namespace std;
const int MAX = 500010;
class trie{
public:
bool flag;
int id;
trie* child[27];
trie()
{
flag=false;
id=0;
memset(child,0,sizeof(child));
}
}root;
int color=0;
int degree[MAX];
int p[MAX];
int find(int x){return p[x]==x?x:p[x]=find(p[x]);}
void unio(int a,int b)
{
int x=find(a);
int y=find(b);
if(x!=y)
p[x]=y;
}
int insert(char *s)
{
class trie *cur=&root;
int len=strlen(s);
for(int i=0;i<len;i++)
{
int id=s[i]-'a';
if(!cur->child[id])
cur->child[id]=new trie;
cur=cur->child[id];
}
if(cur->flag) return cur->id;
else
{
cur->flag=true;
cur->id=++color;
return cur->id;
}
}
int main()
{
int i,j;
char s1[11],s2[11];
for(i=1;i<=500000;i++)
{
p[i]=i;
degree[i]=0;
}
while(scanf("%s%s",s1,s2)!=EOF)
{
i=insert(s1);
j=insert(s2);
degree[i]++;
degree[j]++;
unio(i,j);
}
int r=find(1);
int num=0;
for(j=1;j<=color;j++)
{
if(degree[j]%2==1) num++;
if(num>2)
{
printf("Impossible\n");
return 0;
}
if(find(j)!=r)
{
printf("Impossible\n");
return 0;
}
}
if(num==1) printf("Impossible\n");
else printf("Possible\n");
return 0;
}
- poj 2513 很多RE,很多WA
- [转]POJ WA/RE指南
- hdu3535AreYouBusy (分组背包,WA了很多次)
- hdu 4891---水题 但是WA了很多次
- 很多错误,很多疲惫
- poj 3686(费用流+拆很多点)
- POJ 1011 Sticks DFS+很多剪枝 *
- 两个很多
- 很多信
- 感想很多!
- 很多时候,
- 科目很多!
- 很多日本鬼子
- 马甲很多
- 很多许可证
- poj 1845 Sumdiv (很多数论知识 ,很经典 )
- poj 1050 To the Max(DP)做法很多
- 发现系统有很多很多东西不明白
- poj 1787 多重背包记录路径
- poj 2248 Addition Chains dfs
- 常用Shell命令之一
- zstu 1052 水题。。模拟
- poj 1962 带权并查集
- poj 2513 很多RE,很多WA
- AC小结
- hdu 1251 字典树水题(还是没hold住,又刷题了,哎~)
- 最小生成树 终极版本
- hdu 1879 简单最小生成树
- hdu 3371 最小生成树(有重边)
- hdu 1247 字典树
- hdu 2486 字典树
- poj 2481加强版 zstu 3113 树状数组 排序、离散化