Submission #1636264


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v)) os<<*i<<(i==end(v)-1?"":" "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
    is>>p.first>>p.second; return is; }
template <class T> bool chmax(T &a,const T &b) {if(a<b) {a=b;return 1;} return 0;}
template <class T> bool chmin(T &a,const T &b) {if(b<a) {a=b;return 1;} return 0;}
template <class T> using heap = priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int N,M,R,T;
    cin>>N>>M>>R>>T;
    vector<vector<pii>> g(N);
    REP(i,M) {
        int a,b,c;
        cin>>a>>b>>c;
        a--,b--;
        g[a].push_back({b,c});
        g[b].push_back({a,c});
    }
    int ans=0;
    REP(i,N) {
        vector<int> dist(N,INF);
        dist[i]=0;
        heap<pii> hp;
        hp.push({0,i});
        while(!hp.empty()) {
            int v=hp.top().second; hp.pop();
            FORE(x,g[v]) {
                int to=x.first;
                int cost=x.second;
                if(dist[to]>dist[v]+cost) {
                    dist[to]=dist[v]+cost;
                    hp.push({dist[to],to});
                }
            }
        }
        vector<pii> a(N);
        REP(j,N) a[j]={dist[j],j};
        
        sort(ALL(a));
        sort(ALL(dist));

        REP(j,N) {
            if(i==a[j].second) continue;
            int idx=distance(begin(dist),upper_bound(ALL(dist),dist[j]*R/T));
            int t=(N-idx);
            if(idx<=j) t--;
            ans+=t;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Submission Info

Submission Time
Task C - ウサギとカメ
User algon
Language C++14 (GCC 5.4.1)
Score 100
Code Size 2776 Byte
Status AC
Exec Time 1570 ms
Memory 512 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 2
AC × 18
Set Name Test Cases
Sample subtask0_sample-01.txt, subtask0_sample-02.txt
All subtask0_sample-01.txt, subtask0_sample-02.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt
Case Name Status Exec Time Memory
subtask0_sample-01.txt AC 1 ms 256 KB
subtask0_sample-02.txt AC 1 ms 256 KB
subtask1_01.txt AC 1 ms 256 KB
subtask1_02.txt AC 1 ms 256 KB
subtask1_03.txt AC 1 ms 256 KB
subtask1_04.txt AC 1 ms 256 KB
subtask1_05.txt AC 9 ms 256 KB
subtask1_06.txt AC 11 ms 256 KB
subtask1_07.txt AC 35 ms 384 KB
subtask1_08.txt AC 46 ms 384 KB
subtask1_09.txt AC 442 ms 512 KB
subtask1_10.txt AC 447 ms 384 KB
subtask1_11.txt AC 178 ms 384 KB
subtask1_12.txt AC 1468 ms 512 KB
subtask1_13.txt AC 1470 ms 512 KB
subtask1_14.txt AC 1566 ms 512 KB
subtask1_15.txt AC 1032 ms 512 KB
subtask1_16.txt AC 1570 ms 512 KB