제출 #1010051

#제출 시각아이디문제언어결과실행 시간메모리
1010051SG2AlokCommuter Pass (JOI18_commuter_pass)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define hitaf ios_base::sync_with_stdio(false); cin.tie(NULL);
#define fi first
#define se second

const ll MOD = 998244353;
const ll INF = 1e18;

// dp[i][0] = par -> child, dp[i][1] = child -> par

int n, m, s, t, u, V;
ll dp[100005][2];
vector<pair<int, int>> adj[100005];
vector<int> p[100005], child[100005]
vector<ll> distV, distU, dist;
bool vis[100005];

vector<ll> dijkstra(ll start){
    vector<ll> dist(n + 2, INF);
    priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;
    pq.push({0, start});
    dist[start] = 0;
    while(!pq.empty()){
        auto now = pq.top();
        pq.pop();
        
        if(dist[now.se] < now.fi) continue;
        for(auto v: adj[now.se]){
            if(dist[v.fi] < now.fi + v.se) continue;
            dist[v.fi] = now.fi + v.se;
            pq.push({dist[v.fi], v.fi});
        }
    }
        
    return dist;    
}

ll dfs1(ll u){
    if(dp[u][0] != INF / 2) return dp[u][0];
    
    dp[u][0] = distV[u];
    for(auto v: p[u]){
        dp[u][0] = min(dp[u][0], dfs1(v));
    }
    
    return dp[u][0];
}

ll dfs2(ll u){
    if(dp[u][1] != INF / 2) return dp[u][1];
    
    dp[u][1] = distV[u];
    for(auto v: child[u]){
        dp[u][1] = min(dp[u][1], dfs2(v));
    }
    
    return dp[u][1];
}

int main(){
    hitaf
    cin >> n >> m;
    cin >> s >> t;
    cin >> u >> V;
    
    for(int i = 1; i <= m; i++){
        int x, y, w;
        cin >> x >> y >> w;
        adj[x].push_back({y, w});
        adj[y].push_back({x,w});
    }
        
    dist = dijkstra(s);
    distU = dijkstra(u);
    distV = dijkstra(V);
        
    queue<int> q;
    q.push(t);
    while(!q.empty()){
        ll now = q.front();
        q.pop();
        for(auto v: adj[now]){
            if(dist[v.fi] + v.se == dist[now]){
                p[now].push_back(v.fi);
                child[v.fi].push_back(now);
                if(vis[v.fi]) continue;
                vis[v.fi] = true;
                q.push(v.fi);
            }
        }
    }
    
    for(int i = 1; i <= n; i++) dp[i][1] = dp[i][0] = INF / 2;
    
    ll ans = distU[V];
    
    for(int i = 1; i <= n; i++){
        if(!p[i].empty() || !child[i].empty()){
            ans = min(ans, distU[i] + min(dfs1(i), dfs2(i)));
        }
    }
    
    for(auto x: child[7]) cout << x << " ";
    cout << endl;
    cout << ans << endl;
}
    

/*
    7 1 2 9 0
*/

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

commuter_pass.cpp:18:1: error: expected initializer before 'vector'
   18 | vector<ll> distV, distU, dist;
      | ^~~~~~
commuter_pass.cpp: In function 'll dfs1(ll)':
commuter_pass.cpp:44:16: error: 'distV' was not declared in this scope
   44 |     dp[u][0] = distV[u];
      |                ^~~~~
commuter_pass.cpp: In function 'll dfs2(ll)':
commuter_pass.cpp:55:16: error: 'distV' was not declared in this scope
   55 |     dp[u][1] = distV[u];
      |                ^~~~~
commuter_pass.cpp:56:17: error: 'child' was not declared in this scope
   56 |     for(auto v: child[u]){
      |                 ^~~~~
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:76:5: error: 'dist' was not declared in this scope
   76 |     dist = dijkstra(s);
      |     ^~~~
commuter_pass.cpp:77:5: error: 'distU' was not declared in this scope
   77 |     distU = dijkstra(u);
      |     ^~~~~
commuter_pass.cpp:78:5: error: 'distV' was not declared in this scope
   78 |     distV = dijkstra(V);
      |     ^~~~~
commuter_pass.cpp:88:17: error: 'child' was not declared in this scope
   88 |                 child[v.fi].push_back(now);
      |                 ^~~~~
commuter_pass.cpp:101:30: error: 'child' was not declared in this scope
  101 |         if(!p[i].empty() || !child[i].empty()){
      |                              ^~~~~
commuter_pass.cpp:106:17: error: 'child' was not declared in this scope
  106 |     for(auto x: child[7]) cout << x << " ";
      |                 ^~~~~