제출 #1179985

#제출 시각아이디문제언어결과실행 시간메모리
1179985hainam2k9Construction Project 2 (JOI24_ho_t2)C++20
100 / 100
345 ms24908 KiB
#include <bits/stdc++.h>
#define tt cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0)
#define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define db long double
#define sz(a) ((int)(a).size())
#define pb emplace_back
#define pf emplace_front
#define pob pop_back
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define ins emplace
#define mp make_pair
using namespace std;
const int MOD = 1e9+7, MAXN = 2e5+5;
const string NAME = "";
int n,m,s,t,l,bit[MAXN<<1];
ll k,distS[MAXN],distT[MAXN],rs=0;
vector<pair<int,int>> adj[MAXN];
vector<ll> v;
void dijkstra(int start, ll dist[]){
    priority_queue<pair<ll,int>, vector<pair<ll,int>>, greater<pair<ll,int>>> pq;
    dist[start]=0, pq.ins(0,start);
    while(!pq.empty()){
        pair<ll,int> top = pq.top();
        pq.pop();
        if(top.fi>dist[top.se]) continue;
        for(pair<int,int>& p : adj[top.se])
            if(dist[p.fi]>top.fi+p.se) dist[p.fi]=top.fi+p.se, pq.ins(dist[p.fi],p.fi);
    }
}
void update(int pos, int val){
    while(pos<=n<<1) bit[pos]+=val, pos+=pos&-pos;
}
int getsum(int pos){
    int rs=0;
    while(pos>0) rs+=bit[pos], pos-=pos&-pos;
    return rs;
}
int main()
{
    tt;
    if(fopen((NAME + ".INP").c_str(), "r")) fo;
    cin >> n >> m;
    cin >> s >> t >> l >> k;
    for(int i = 1; i<=m; ++i){
        int x,y,z;
        cin >> x >> y >> z;
        adj[x].pb(y,z), adj[y].pb(x,z);
    }
    memset(distS,0x3f,sizeof(distS));
    memset(distT,0x3f,sizeof(distT));
    dijkstra(s,distS);
    dijkstra(t,distT);
    if(distS[t]<=k) return cout << 1ll*n*(n-1)/2, 0;
    for(int i = 1; i<=n; ++i)
        v.pb(l+distS[i]), v.pb(k-distT[i]);
    sort(v.begin(),v.end());
    v.resize(unique(v.begin(),v.end())-v.begin());
    update(lb(v.begin(),v.end(),l+distS[1])-v.begin(),1);
    for(int i = 2; i<=n; ++i)
        rs+=getsum(lb(v.begin(),v.end(),k-distT[i])-v.begin()), update(lb(v.begin(),v.end(),l+distS[i])-v.begin(),1);
    memset(bit,0,sizeof(bit));
    update(lb(v.begin(),v.end(),l+distS[n])-v.begin(),1);
    for(int i = n-1; i>0; --i)
        rs+=getsum(lb(v.begin(),v.end(),k-distT[i])-v.begin()), update(lb(v.begin(),v.end(),l+distS[i])-v.begin(),1);
    cout << rs;
}

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'int main()':
Main.cpp:3:19: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:48:45: note: in expansion of macro 'fo'
   48 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
Main.cpp:3:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |                                                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:48:45: note: in expansion of macro 'fo'
   48 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...