提出 #8043070


ソースコード 拡げる

#include <bits/stdc++.h>
 
#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<int>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>
 
using namespace std;
 
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
 
int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*(power((a*a)%mod,n/2)%mod))%mod;
    return power((a*a)%mod,n/2)%mod;
}
const int inf = (int) 1e18;
 
int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
}
vector<pii>adj[305];
bool mark[305];
int n,m,d[305],fl[305],L,ans[305][305];

void dijkstra(int v){

    fill(d,d + 305, inf);
    fill(fl,fl + 305, 0);
    d[v] = 0;
    fl[v] = L;
    priority_queue<pair<pii,int>,vector<pair<pii,int> >, less<pair<pii,int> > > pq;
    pq.push({{0,-L}, v});
    while(!pq.empty()){
        int u = pq.top().se,nott = pq.top().f.f,fll = pq.top().f.se;
        pq.pop();
        for(auto &p : adj[u]) 
            if(fl[u] >= p.se){
                if(d[p.f] > d[u]){
                    d[p.f] = d[u];
                    fl[p.f] = fl[u]-p.se;
                    pq.push({{d[p.f],-fl[p.f]},p.f});
                }
            }
            else {
                if(d[p.f] > d[u]+1){
                    d[p.f] = d[u]+1;
                    fl[p.f] = L-p.se;
                    pq.push({{d[p.f],-fl[p.f]},p.f});
                }   
            }
    }
}

signed main()
{
    showoff;
    cin >> n >> m >> L;
    FOR(i,1,m+1){
        int u,v,w;
        cin >> u >> v >> w;
        adj[u].pb({v,w});
        adj[v].pb({u,w});
    }
    FOR(i,1,n+1){
        dijkstra(i);
        FOR(j,1,n+1)ans[i][j] = d[j];
    }
    int q;
    cin >> q;
    while(q--){
        int x,y;
        cin >> x >> y;
        if(ans[x][y] != inf)cout << ans[x][y] << "\n";
        else cout << "-1\n";
    }
    return 0;

}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ....s

提出情報

提出日時
問題 E - Travel by Car
ユーザ MonsterInMe
言語 C++14 (GCC 5.4.1)
得点 0
コード長 2575 Byte
結果 WA
実行時間 175 ms
メモリ 3712 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 0 / 500
結果
AC × 3
AC × 33
WA × 17
セット名 テストケース
Sample 00-sample-00, 00-sample-01, 00-sample-02
All 00-sample-00, 00-sample-01, 00-sample-02, 01-handmade-03, 01-handmade-04, 01-handmade-05, 01-handmade-06, 01-handmade-07, 02-random-08, 02-random-09, 02-random-10, 02-random-11, 02-random-12, 02-random-13, 02-random-14, 02-random-15, 02-random-16, 02-random-17, 02-random-18, 02-random-19, 02-random-20, 02-random-21, 02-random-22, 02-random-23, 02-random-24, 02-random-25, 02-random-26, 02-random-27, 02-random-28, 02-random-29, 02-random-30, 02-random-31, 02-random-32, 02-random-33, 02-random-34, 02-random-35, 02-random-36, 02-random-37, 02-random-38, 02-random-39, 02-random-40, 02-random-41, 02-random-42, 02-random-43, 02-random-44, 02-random-45, 02-random-46, 02-random-47, 02-random-48, 02-random-49
ケース名 結果 実行時間 メモリ
00-sample-00 AC 1 ms 256 KiB
00-sample-01 AC 1 ms 256 KiB
00-sample-02 AC 1 ms 256 KiB
01-handmade-03 AC 16 ms 1280 KiB
01-handmade-04 AC 69 ms 3712 KiB
01-handmade-05 WA 106 ms 3584 KiB
01-handmade-06 AC 21 ms 1280 KiB
01-handmade-07 AC 21 ms 1280 KiB
02-random-08 AC 2 ms 384 KiB
02-random-09 WA 5 ms 640 KiB
02-random-10 AC 26 ms 1280 KiB
02-random-11 AC 4 ms 512 KiB
02-random-12 WA 13 ms 640 KiB
02-random-13 WA 13 ms 640 KiB
02-random-14 AC 47 ms 2176 KiB
02-random-15 WA 26 ms 1280 KiB
02-random-16 WA 64 ms 896 KiB
02-random-17 AC 72 ms 1024 KiB
02-random-18 AC 4 ms 512 KiB
02-random-19 AC 1 ms 384 KiB
02-random-20 AC 24 ms 1280 KiB
02-random-21 WA 27 ms 640 KiB
02-random-22 AC 1 ms 256 KiB
02-random-23 AC 18 ms 1408 KiB
02-random-24 AC 103 ms 3456 KiB
02-random-25 AC 26 ms 1280 KiB
02-random-26 AC 2 ms 384 KiB
02-random-27 WA 58 ms 896 KiB
02-random-28 AC 46 ms 1792 KiB
02-random-29 AC 25 ms 1664 KiB
02-random-30 WA 26 ms 1280 KiB
02-random-31 WA 5 ms 512 KiB
02-random-32 AC 29 ms 768 KiB
02-random-33 WA 35 ms 1664 KiB
02-random-34 AC 29 ms 1408 KiB
02-random-35 AC 25 ms 1280 KiB
02-random-36 WA 37 ms 768 KiB
02-random-37 WA 68 ms 896 KiB
02-random-38 AC 1 ms 256 KiB
02-random-39 WA 2 ms 384 KiB
02-random-40 AC 26 ms 1280 KiB
02-random-41 AC 175 ms 1152 KiB
02-random-42 WA 14 ms 640 KiB
02-random-43 AC 88 ms 2304 KiB
02-random-44 AC 1 ms 384 KiB
02-random-45 WA 25 ms 1280 KiB
02-random-46 WA 7 ms 512 KiB
02-random-47 AC 63 ms 1024 KiB
02-random-48 AC 1 ms 256 KiB
02-random-49 AC 8 ms 768 KiB