请问各位大佬,为什么用了快读还是TLE,是否是方法出了问题

P1342 请柬

飘啊飘 @ 2020-05-21 11:52:22

#include<bits/stdc++.h>
using namespace std;
long long m,n,a,b,c,tot;
const long long u=1000005;
long long head[u],ver[u],net[u],edge[u],st[u],dist[u],head2[u],dist2[u],ans;
typedef pair <long long,long long> PII;
priority_queue <PII,vector<PII>,greater<PII> > q;

int read()
{
    int s=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        s=s*10+ch-'0';
        ch=getchar();
    }
    return s*f;
}

void write(long long x)
{
    if(x<0){
        putchar('-');
        x=-x;
    }
    if(x>9) 
        write(x/10);
    putchar(x%10+'0');
}

void add(long long a,long long b,long long c)
{
    net[++tot]=head[a];
    head[a]=tot;
    ver[tot]=b;
    edge[tot]=c;
}
void add2(long long a,long long b,long long c)
{
    net[++tot]=head2[a];
    head2[a]=tot;
    ver[tot]=b;
    edge[tot]=c;
}
void dijstla()
{
    memset(dist,0x3f,sizeof(dist));
    dist[1]=0;
    q.push({0,1});
    while(!q.empty())
    {
        PII temp=q.top();
        q.pop();
        long long dis=temp.first,v1=temp.second;
        if(st[v1]==1)
            continue;
        st[v1]=1;
        for(long long i=head[v1];i;i=net[i])
        {
            long long v=ver[i];
            if(dist[v]>dis+edge[i])
            {
                dist[v]=dis+edge[i];
                q.push({dist[v],v});
            }
        }
    }
    for(long long i=1;i<=n;++i)
        ans+=dist[i];
}
void dijstla2()
{
    memset(dist2,0x3f,sizeof(dist2));
    dist2[1]=0;
    q.push({0,1});
    while(!q.empty())
    {
        PII temp=q.top();
        q.pop();
        long long dis=temp.first,v1=temp.second;
        if(st[v1]==1)
            continue;
        st[v1]=1;
        for(long long i=head2[v1];i;i=net[i])
        {
            long long v=ver[i];
            if(dist2[v]>dis+edge[i])
            {
                dist2[v]=dis+edge[i];
                q.push({dist2[v],v});
            }
        }
    }
    for(long long i=1;i<=n;++i)
        ans+=dist2[i];
}

int main()
{
    n=read();
    m=read();
    for(long long i=1;i<=m;++i)
    {
        a=read();
        b=read();
        c=read();
        add(a,b,c);
        add2(b,a,c);
    }
    dijstla();
    memset(st,0,sizeof(st));
    dijstla2();
    write(ans);
    return 0;
}

by the_hidden_corner @ 2020-05-26 15:08:27

那题咋那么毒瘤啊..


by 飘啊飘 @ 2020-05-26 15:14:01

@明日世界 SP50题跟这个差不多,但我现在交不起


by the_hidden_corner @ 2020-05-26 15:20:49

@飘啊飘 为啥交不起?


by 飘啊飘 @ 2020-05-26 15:22:30

@明日世界 提交失败,全在waiting ,这是道spoj的题


by the_hidden_corner @ 2020-05-26 15:26:00

@飘啊飘 ...(交上个20遍的


by XeCtera @ 2020-05-26 18:22:04

@飘啊飘 数组越界不是一定导致RE
这个应该是因为越界修改了不应被修改的变量 然后T了
把net数组的定义放到最后应该就能收获RE了(?


上一页 |