제출 #1257541

#제출 시각아이디문제언어결과실행 시간메모리
1257541lftroqConstruction Project 2 (JOI24_ho_t2)C++20
100 / 100
216 ms23336 KiB
#include<bits/stdc++.h>
#define endl '\n'
#define fi first
#define se second
using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> llll;
typedef pair<ld,ld> ldld;

const int N=2e5+5;

int n,m,s,t,L;
ll k;
vector<pii> graph[N];
ll d[2][N];

void dijkstra(int u,int k)
{
    for(int i=1;i<=n;i++) d[k][i]=1e16;
    d[k][u]=0;
    priority_queue<llll,vector<llll>,greater<llll>> pq;
    pq.push({d[k][u],u});
    while((int)pq.size())
    {
        ll temp=pq.top().fi;
        int u=pq.top().se;
        pq.pop();
        if(d[k][u]!=temp) continue;
        for(int i=0;i<(int)graph[u].size();i++)
        {
            int v=graph[u][i].fi,w=graph[u][i].se;
            if(d[k][v]>d[k][u]+w)
            {
                d[k][v]=d[k][u]+w;
                pq.push({d[k][v],v});
            }
        }
    }
}

void solve()
{
    cin >> n >> m >> s >> t >> L >> k;
    for(int i=1;i<=m;i++)
    {
        int u,v,w;
        cin >> u >> v >> w;
        graph[u].push_back({v,w});
        graph[v].push_back({u,w});
    }
    dijkstra(s,0);
    if(d[0][t]<=k)
    {
        cout << n*(n-1ll)/2 << endl;
        return;
    }
    dijkstra(t,1);
    vector<ll> v;
    for(int i=1;i<=n;i++) v.push_back(d[1][i]);
    sort(v.begin(),v.end());
    ll ans=0;
    for(int i=1;i<=n;i++)
    {
        int l=1,r=n,liem=0;
        while(l<=r)
        {
            int mid=(l+r)>>1;
            if(d[0][i]+L+v[mid-1]<=k)
            {
                //cout << ":::" << mid-1 << ' ' << v[mid-1] << ' ' << d[0][i] << ' ' << l << endl;
                liem=mid;
                l=mid+1;
            }
            else r=mid-1;
        }
        //cout << i << ": " << d[0][i] << ' ' << d[1][i] << "   " << liem << endl;
        ans+=liem;
        //cout << d[0][i]+d[1][i]+L << ' ' << k << endl;
    }
    cout << ans << endl;
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    if(fopen("test.inp","r"))
    {
        freopen("test.inp","r",stdin);
        freopen("test.out","w",stdout);
    }
    int t=1;
    //cin >> t;
    while(t--)
    solve();
    return 0;
}

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

Main.cpp: In function 'int main()':
Main.cpp:90:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |         freopen("test.inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:91:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |         freopen("test.out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...