Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

欧拉通路+并查集+字典树……求大神告诉我map怎么水过去。。。Trie 节点 250000*10*2。。。ORZ 16ms 的大神。

Posted by dongshimou at 2014-07-07 13:24:49 on Problem 2513
一直节点开 250000*2.
给跪了好几次CE。然后回头一想,单词每个10个字符,X 10就AC了。。。


#include<cstdio>
#include<cstring>
#include<string>
#include<queue>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<iostream>
#include<list>
#include<set>
#include<cmath>
#define INF 0x7fffffff
#define eps 1e-6
using namespace std;
int n;
int io[510001];
int fa[510001];
int father(int x)
{
    if(x!=fa[x])
        fa[x]=father(fa[x]);
    return fa[x];
}
struct Trie
{
    int word[510000][26];
    int sz,cot;
    int ex[510000*10];
    Trie()
    {
        sz=1;//节点
        cot=1;//单词数
        memset(word,0,sizeof(word));
        memset(ex,0,sizeof(ex));
    }
    int insert(char *s)
    {
        int u=0,c,len=strlen(s);
        for(int i=0; i<len; i++)
        {
            c=s[i]-'a';
            if(!word[u][c])
            {
                word[u][c]=sz++;
            }
            u=word[u][c];
        }
        if(ex[u]==0)ex[u]=cot++;
        return ex[u];
    }
}wo;
int main()
{
    char a[11],b[11];
    int u,v;
    for(int i=1; i<510000; i++)
    {
        fa[i]=i;
        io[i]=0;
    }
    while(scanf("%s%s",a,b)!=EOF)
    {
        u=wo.insert(a);
        v=wo.insert(b);
        //printf("%d %d\n",u,v);
        io[v]++,io[u]++;
        u=father(u),v=father(v);
        if(u==v)continue;
        fa[v]=u;
    }
    n=wo.cot;
    bool flag=1;
    int block=0;
    int odd=0;
    for(int i=1; i<n; i++)
    {
        if(io[i]&1)odd++;
        if(father(i)==i)block++;
        if(block>1||odd>2)
        {
            flag=0;
            break;
        }
    }
    if(odd==1)flag=0;
    if(flag)puts("Possible");
    else puts("Impossible");
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator