QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#563625#9260. Raiffeisenbank LogisticsPhantomThreshold#WA 0ms3756kbC++202.5kb2024-09-14 14:26:472024-09-14 14:26:47

Judging History

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

  • [2024-09-14 14:26:47]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3756kb
  • [2024-09-14 14:26:47]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;

const int maxn = 1510000;

int n,m;
int tot;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int Tcase; cin>>Tcase;
    while(Tcase--)
    {
        vector< vector< pair<int,int> > >E;
        vector< vector<int> >V;
        vector< tuple<int,int,int> >ei;

        cin>>n>>m;
        V.resize(n+5);
        for(int i=1;i<=m;i++)
        {
            int x,y,t; cin>>x>>y>>t;
            ei.emplace_back(x,y,t);
            V[x].push_back(t),V[y].push_back(t);
            V[x].push_back(t+1),V[y].push_back(t+1);
        }
        
        tot=0;
        map< pair<int,int>,int>mp;
        for(int i=1;i<=n;i++)
        {
            sort(V[i].begin(),V[i].end());
            for(auto t:V[i])
            {
                auto temp= make_pair(i,t);
                if(mp.count(temp)==0) 
                {
                    mp[temp]=++tot;
            //        cerr<<i<<' '<<t<<' '<<tot<<endl;
                }
            }
        }
        E.resize(tot+5);
        for(int i=1;i<=n;i++)
        {
            int las=-1;
            for(auto t:V[i])
            {
                if(las!=-1 && las!=t)
                {
                    int u= mp[make_pair(i,las)], v=mp[make_pair(i,t)];
                    E[u].emplace_back(0,v);
                }
                las=t;
            }
        }
        for(auto [x,y,t]:ei)
        {
            E[ mp[make_pair(x,t)] ].emplace_back(0, mp[make_pair(y,t+1)] );
            E[ mp[make_pair(y,t)] ].emplace_back(1, mp[make_pair(x,t+1)] );
        }
        
        const int inf = 1e9;
        vector<int>dis(tot+5);
        for(int i=1;i<=tot;i++) dis[i]=inf;
        deque< pair<int,int> >q;
        dis[1]=0; q.push_back( make_pair(1,0) );
        while(!q.empty())
        {
            const auto [x,dx]=q.front(); q.pop_front();
            if(dx!=dis[x]) continue;
            for(auto [c,y]:E[x])
            {
                if(dis[y]>dx+c)
                {
                    dis[y]=dx+c;
                    if( c==0 ) q.push_front( make_pair(y,dis[y]) );
                    else q.push_back( make_pair(y,dis[y]) );
                }
            }
        }
        int ans=inf;
        for(auto t:V[n])
        {
            int u= mp[make_pair(n,t)];
            ans=min(ans,dis[u]);
        }
        if(ans==inf) ans=-1;
        cout<<ans<<'\n';
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3600kb

input:

1
4 3
2 1 1
2 3 2
4 3 3

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3756kb

input:

2
4 3
2 1 1
2 3 2
4 3 2
8 9
1 2 5
2 3 10
4 3 15
4 5 20
5 8 25
1 6 2
6 5 30
7 6 3
8 7 4

output:

-1
1

result:

ok 2 number(s): "-1 1"

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3616kb

input:

8
2 1
1 2 1
2 1
2 1 1
2 1
1 1 1
2 1
2 2 1
2 1
1 2 1000000000
2 1
2 1 1000000000
2 1
1 1 1000000000
2 1
2 2 1000000000

output:

0
1
-1
0
0
1
-1
0

result:

wrong answer 4th numbers differ - expected: '-1', found: '0'