QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#585427#9260. Raiffeisenbank Logisticsucup-team3474#WA 5ms3860kbC++201.4kb2024-09-23 20:47:412024-09-23 20:47:41

Judging History

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

  • [2024-09-23 20:47:41]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:3860kb
  • [2024-09-23 20:47:41]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1919810,mod=998244353;
typedef long long ll;
typedef pair<ll,ll> PII;
ll n,m,k;
ll a[N],b[N];
char s[N];

typedef struct{
    int to,val,w;
}Node;

vector<Node> e[N];
int q[N];

map<PII,ll> mp;


void __(){
    cin>>n>>m;
    for(int i=1;i<=n;i++) e[i].clear();
    mp.clear();
    deque<PII> q;
    for(int i=1;i<=m;i++){
        int u,v,w;
        scanf("%d%d%d",&u,&v,&w);
        e[u].push_back({v,w,0});
        e[v].push_back({u,w,1});
    }
    mp[{1,-1}]=0;
    q.push_back({1,-1});
    while(q.size()){
        PII t=q.front();
        // cout<<t.first<<" "<<t.second<<" "<<mp[t]<<endl;
        q.pop_front();
        for(auto [to,val,w]:e[t.first]){
            if(val<=t.second) continue;
            if(w==0){
                PII tt={to,val};
                if(mp.count(tt)) continue;
                mp[tt]=mp[t];
                q.push_front(tt);
            }else{
                PII tt={to,val};
                if(mp.count(tt)) continue;
                mp[tt]=mp[t]+1;
                q.push_back(tt);
            }
        }
    }
    ll ans=1e18;
    for(auto [u,v]:mp){
        if(u.first==n) ans=min(v,ans);
    }
    if(ans>1e10) puts("-1");
    else printf("%lld\n",ans);

}


int main(){
    int _;
    cin>>_;
    while(_--){
        __();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 2ms
memory: 3800kb

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: 0
Accepted
time: 2ms
memory: 3860kb

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
-1
0
1
-1
-1

result:

ok 8 numbers

Test #4:

score: 0
Accepted
time: 2ms
memory: 3744kb

input:

1
2 1
1 2 1

output:

0

result:

ok 1 number(s): "0"

Test #5:

score: -100
Wrong Answer
time: 5ms
memory: 3796kb

input:

1000
10 10
1 2 1
2 4 1
6 1 1
3 8 1
7 2 1
3 2 1
1 4 1
2 6 1
9 4 1
10 7 1
10 10
4 7 1
10 2 1
8 2 1
9 1 1
1 9 1
4 4 1
10 2 1
4 7 1
8 2 1
9 9 1
10 10
7 5 1
2 2 1
8 7 1
10 9 1
2 7 1
4 6 1
4 1 1
1 2 1
3 8 1
2 1 1
10 10
6 10 1
4 7 1
10 9 1
4 8 1
1 1 1
1 1 1
1 7 1
2 1 1
6 9 1
3 10 1
10 10
6 1 1
9 8 1
8 8 1
...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
0
-1
-1
-1
1
-1
-1
-1
-1
-1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
0
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
0
-1
-1
-1
0
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
0
-1
-1
-1
-1
-1
-1
0
1
-1
-1
-1
-1
-1
-1
0
-1
-1
-1
-1
-1
1
-1
-1
0
-1
1
-1
-1
-...

result:

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