제출 #544206

#제출 시각아이디문제언어결과실행 시간메모리
544206Cookie197Commuter Pass (JOI18_commuter_pass)C++17
31 / 100
286 ms28808 KiB
// Cookie197 
// the people who invented competitive programming must be ******* crazy
// why am i still here suffering while i can do something else more valuable?
// WHY???
//#pragma GCC optimize("O4,unroll-loops,no-stack-protector")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<string>
#include<iomanip>
#include<math.h>
#include<unordered_map>
#include<numeric>
#include<random>
using namespace std;
#define Why_does_competitive_programming_even_exist ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define pii pair<ll,ll>
#define pdd pair<double ,double>
#define mp make_pair
//#define mod 998244353
#define mod 1000000007
#define endl "\n"
#define inf (ll)5e18
#define out(x) cout << #x << " = " << x <<endl;
#define out2(a,b) cout<< #a << "[" << b << "]" << " = " << a[b] << endl;
#define outp(x) cout << #x << " first = " << x.first << "  second = " << x.second << endl

#define mt(a,b,c) mp(a,mp(b,c))
int n,m,S,T,U,V;
vector<pair<int,pii> > adj[100005]; // node, dist, id
ll dist[100005];
int discount[200005];

int vis[100005];
void dfs(int node){
    vis[node] = true;
    for (pair<int,pii> p:adj[node]){
        int u = p.first;
        ll wei = p.second.first;
        int id = p.second.second;
        if (dist[node] - wei == dist[u]) {
            discount[id] = true;
            if (!vis[u]) dfs(u);
        }
    }
}
signed main(){
    Why_does_competitive_programming_even_exist;
    cin>>n>>m>>S>>T>>U>>V;
    for (int i=1;i<=m;i++){
        int a,b; ll c; cin>>a>>b>>c;
        c *= 1000000;
        adj[a].push_back(mt(b,c,i));
        adj[b].push_back(mt(a,c,i));
    }

    for (int i=1;i<=n;i++) dist[i] = -1;
    priority_queue<pii,vector<pii>, greater<pii> > pq;
    pq.push(mp(0,S));
    while(pq.size()){
        int node = pq.top().second;
        ll d = pq.top().first;
        pq.pop();
        if (dist[node] != -1) continue;
        dist[node] = d;
        for (pair<int,pii> p:adj[node]){
            int u = p.first;
            ll wei = p.second.first;
            int id = p.second.second;
            pq.push(mp(wei+d, u));
        }
    }

    //for (int i=1;i<=n;i++) out2(dist,i);
    //return 0;

    dfs(T);

    for (int i=1;i<=n;i++) dist[i] = -1;
    pq.push(mp(0,U));
    while(pq.size()){
        int node = pq.top().second;
        ll d = pq.top().first;
        pq.pop();
        if (dist[node] != -1) continue;
        dist[node] = d;
        for (pair<int,pii> p:adj[node]){
            int u = p.first;
            ll wei = p.second.first;
            int id = p.second.second;
            if (discount[id]) wei = 1;
            if (dist[u] != -1) continue;
            pq.push(mp(wei+d, u));
        }
    }
    
    cout<<dist[V]/1000000<<endl;
}

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

commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:76:17: warning: unused variable 'id' [-Wunused-variable]
   76 |             int id = p.second.second;
      |                 ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...