QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#617619#9434. Italian Cuisinezzpcd#RE 0ms0kbC++204.3kb2024-10-06 16:25:592024-10-06 16:26:02

Judging History

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

  • [2024-10-06 16:26:02]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-10-06 16:25:59]
  • 提交

answer

#include<bits/stdc++.h>
#define P make_pair
#define N 500010
using namespace std;
int n,vis[N],m,K;
struct edge
{
    int v,pre,c,l;
}e[N<<1];
int fir[N],tot=1;
void adde(int u,int v,int c,int l)
{
    e[++tot]={v,fir[u],c,l};fir[u]=tot;
    e[++tot]={u,fir[v],c,l};fir[v]=tot;
    return ;
}
struct node
{
    int now;
    long long dis;
    int id;
    friend bool operator <(const node &i,const node &j)
    {
        if(i.now==j.now)
        {
            return i.dis>j.dis;
        }
        else 
        {
            return i.now>j.now;
        }
    }
}dat[N];
priority_queue<node> q;
struct opt
{
    int a,b;
}op[N];
vector<pair<int,int>> vec[N];
vector<pair<int,int>> bz[N][20];
int getpos(int c,int ll,int val)
{
    int l=0,r=vec[c].size()-1;
    while(l<r)
    {
        int mid=l+r>>1;
        if(vec[c][mid].first>ll) r=mid;
        else l=mid+1;
    }
    if(r>=vec[c].size()||vec[c][r].first<=ll) return K+1;
    int now=l;
    for(int j=19;j>=0;--j)
    {
        if(bz[c][j][now].second<val)
        {
            now=bz[c][j][now].first;
        }
    }
    ++now;
    if(now>=vec[c].size()||bz[c][0][now].second<val) return K+1;
    return now;
}
void dij()
{

    while(!q.empty()) q.pop();
    q.push({1,0ll,1});
    fill(vis,vis+n+5,0);
    while(!q.empty())
    {
        auto [now,dis,u] = q.top();
        q.pop();
        cerr << u <<" ::: " << now <<" " << dis <<"??\n";
        if(vis[u]) continue;
        vis[u]=true;
        for(int i=fir[u];i;i=e[i].pre)
        {
            int v=e[i].v;
            if(e[i].c==op[now].a)
            {
                if(dis+e[i].l<=op[now].b)
                {
                    node tmp={now,dis+e[i].l,v};
                    if(dat[v]<tmp)
                    {
                        dat[v]=tmp;
                        q.push(dat[v]);
                    }
                }
                else 
                {
                    int p=getpos(e[i].c,now,e[i].l);
                    cout<<e[i].c<<" "<<now<<" "<<e[i].l<<"  "<<p<<endl;
                    if(p==K+1) continue;
                    node tmp={p,e[i].l,v};
                    if(dat[v]<tmp)
                    {
                        dat[v]=tmp;
                        q.push(dat[v]);
                    }
                }
            }
            else 
            {
                int p=getpos(e[i].c,now,e[i].l);
                cout<<e[i].c<<" "<<now<<" "<<e[i].l<<"  "<<p<<endl;
                if(p==K+1) continue;
                node tmp={p,e[i].l,v};
                if(dat[v]<tmp)
                {
                    dat[v]=tmp;
                    q.push(dat[v]);
                }
            }
        }
    }
    return ;
}
void _()
{
    cin>>n>>m>>K;
    tot=1;
    for(int i=1;i<=n;++i) fir[i]=0,dat[i]={(int)2e9,(long long)2e18,i};
    for(int i=1;i<=m;++i)
    {
        int u,v,c,l;
        cin>>u>>v>>c>>l;
        adde(u,v,c,l);
        vec[i].clear();
    }
    for(int i=1;i<=K;++i)
    {
        cin>>op[i].a>>op[i].b;
        vec[op[i].a].push_back({i,op[i].b});
    }
    // cerr << "???\n";
    for(int i=1;i<=m;++i)
    {
        for(int j=0;j<20;++j)
        {
            bz[i][j].clear();
            for(int t=0;t<=vec[i].size();++t) bz[i][j].push_back(P(0,0));
            for(int p=0;p<=vec[i].size();++p)
            {
                if(j==0)
                {
                    if(p==vec[i].size()) bz[i][j][p]=P(p,0);
                    else bz[i][j][p]=P(p+1,vec[i][p].second);
                }
                else
                {
                    bz[i][j][p]=P(bz[i][j-1][bz[i][j-1][p].first].first,max(bz[i][j-1][p].second,bz[i][j-1][bz[i][j-1][p].first].second));
                }
            }
        }
    }
    dij();
    for(int i=1;i<=n;++i) cout<<vis[i];
    cout<<'\n';
    return ;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int T;
    cin>>T;
    while(T--) _();
    return 0;
}
/*
2
5 6 4
1 2 1 30
2 3 1 50
2 5 5 50
3 4 6 10
2 4 5 30
2 5 1 40
1 70
6 100
5 40
1 30
1 ::: 1 0??
2 ::: 1 30??
5 1 30  5
5 1 50  5
1 1 50  5
1 ::: 1 60??
5 ::: 1 70??
1 1 40  5
5 1 50  5
3 1 1
2 3 1 10
1 100
11001
1 ::: 1 0??
100*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

3
5
1 1 1
0 0
1 0
5 0
3 3
0 5
6
2 4 1
2 0
4 0
6 3
4 6
2 6
0 3
4
3 3 1
3 0
6 3
3 6
0 3

output:

10000
2 1 0  4
6 1 2  4
6 1 2  4


result: