QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#92054#4380. Travel planToboTL 0ms0kbC++204.0kb2023-03-30 09:55:472023-03-30 09:55:50

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-30 09:55:50]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2023-03-30 09:55:47]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=998244353;
const int maxn=2e5+5;
const int maxv=1e5+5;
int n,m,L;
struct edge
{
    int u,v,w;
}e[maxn];
int pr[maxv],cnt,mu[maxn];
bool vis[maxv];
vector <int> fac[maxv],q[maxn];
void init()
{
    mu[1]=1;
    for(int i=2;i<maxv;i++)
    {
        if(!vis[i]) pr[++cnt]=i,mu[i]=-1;
        for(int j=1;j<=cnt && 1ll*i*pr[j]<maxv;j++)
        {
            vis[i*pr[j]]=1;
            if(i%pr[j]==0){mu[i*pr[j]]=0; break;}
            else mu[i*pr[j]]=-mu[i];
        }
    }
    for(int i=1;i<maxv;i++)
        for(int j=i;j<maxv;j+=i)
            fac[j].push_back(i);
}
ll ans[maxn];
vector <int> G[maxn],GG[maxn<<1];
int dfn[maxn],low[maxn],dfstime;
int tot,st[maxn],top;
ll d[maxn];
void tarjan(int u,int fa)
{
    dfn[u]=low[u]=++dfstime;
    d[u]=0; st[++top]=u;
    for(int to:G[u])
    {
        if(!dfn[to])
        {
            tarjan(to,u);
            low[u]=min(low[u],low[to]);
            d[u]+=d[to];
            if(low[to]==dfn[u]) // bridge edge
            {
                ++tot;
                GG[tot].clear();
                int v=st[top];
                while(v!=to)
                {
                    GG[tot].push_back(v);
                    GG[v].push_back(tot);
                    top--; v=st[top];
                }
                top--; GG[tot].push_back(to);
                GG[to].push_back(tot);
                GG[tot].push_back(u);
                GG[u].push_back(tot);
            }
        }
        else
        {
            low[u]=min(low[u],dfn[to]);
            if(to!=fa) d[u]++,d[to]--;
        }
    }
}
ll f[maxn<<1];
void add(ll &x,ll y)
{
    x=(x+y)%mod;
}
void calc(int u,int fa,int id)
{
    for(int to:GG[u])
    {
        if(to==fa) continue;
        calc(to,u,id);
    }
    if(u<=n)
    {
        f[u]=1;
        for(int to:GG[u])
        {
            if(to==fa) continue;
            add(ans[id],f[u]*f[to]%mod);
            add(f[u],f[to]);
        }
    }
    else if(GG[u].size()==2)
    {
        f[u]=0;
        for(int to:GG[u])
        {
            if(to==fa) continue;
            add(f[u],f[to]);
        }
    }
    else
    {
        f[u]=0;
        for(int to:GG[u])
        {
            if(to==fa) continue;
            add(ans[id],f[u]*f[to]%mod);
            add(f[u],2ll*f[to]%mod);
        }
    }
}
int main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    int T; scanf("%d",&T);
    init();
    while(T--)
    {
        scanf("%d%d%d",&n,&m,&L);
        int x,y,z;
        for(int i=1;i<=L;i++) ans[i]=0,q[i].clear();
        for(int i=1;i<=m;i++)
        {
            scanf("%d%d%d",&e[i].u,&e[i].v,&e[i].w);
            for(int j:fac[e[i].w]) q[j].push_back(i);
        }
        vector <int> p;
        for(int i=1;i<=L;i++)
        {
            p.clear();
            for(int id:q[i])
            {
                int u=e[id].u,v=e[id].v;
                G[u].clear(); G[v].clear();
                GG[u].clear(); GG[v].clear();
                dfn[u]=dfn[v]=0; p.push_back(u); p.push_back(v);
            }    
            for(int id:q[i])
            {
                int u=e[id].u,v=e[id].v;
                G[u].push_back(v); G[v].push_back(u);
            }
            tot=n; dfstime=top=0;
            for(int u:p)
                if(!dfn[u]) tarjan(u,0),calc(u,0,i);
            // printf("[%d]:%d %lld\n",i,tot,ans[i]);
            // for(int j=1;j<=tot;j++)
            // {
            //     printf("%d: ",j);
            //     for(int k:GG[j]) printf("%d ",k);
            //     printf("\n");
            // }
        }
        for(int i=1;i<=L;i++) 
        {
            for(int j=2;i*j<=L;j++)
                ans[i]+=1ll*mu[j]*ans[i*j];
            ans[i]=(ans[i]%mod+mod)%mod;
        }
        ll res=0;
        for(int i=1;i<=L;i++) res^=ans[i];
        printf("%lld\n",res);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

405
3 3 6
1 2 6
2 3 4
3 1 5
5 4 10
1 2 10
1 3 1
2 4 8
4 5 9
100000 133392 100000
1 2 38759
1 3 63879
3 4 70473
1 5 79849
1 6 70562
5 7 83128
3 8 89713
4 9 6190
4 10 44171
7 11 99719
5 12 18707
1 13 33509
3 14 96110
11 15 84651
4 16 17844
3 17 64945
5 18 82684
9 19 94007
16 20 54506
11 21 10076
4 22 ...

output:


result: