제출 #1366614

#제출 시각아이디문제언어결과실행 시간메모리
1366614trandkhoaEvacuation plan (IZhO18_plan)C++20
0 / 100
39 ms9640 KiB
/**
 *     Author: Tran Dang Khoa
**/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define FOR(i,l,r) for (int i = (l), _r = (r); i <= _r; i++)
#define FORN(i,r,l) for (int i = (r), _l = (l); i >= _l; i--)
#define MASK(x) (1LL << (x))
#define BIT(x,i) (((x) >> (i)) & 1)
#define sz(x) (int)x.size()
#define all(v) (v).begin(),(v).end()
#define allVector(v, n) (v).begin() + 1, (v).begin() + (n) + 1
#define segleft (id << 1)
#define segright (id << 1 | 1)
#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define lb lower_bound
#define ub upper_bound
const int MOD = 1e9+7;

void iofile(string s) {
    freopen((s + ".inp").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}

struct infoQuery {
    int a,b;
};

struct infoMid {
    int mid, a, b, id;
};

const int INF = LLONG_MAX;
const int N = 2e5+5;
vector<pair<int,int>> edge[N];
vector<int> dist, npp;
int n,m,k,q;

vector<int> dijkstra() {
    vector<int> dist(n+5, INF);
    priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> q;

    for(int u : npp) {
        q.push({0, u});
        dist[u] = 0;
    }

    while(!q.empty()) {
        auto[du, u] = q.top(); q.pop();
        if (du != dist[u]) continue;

        for(auto[v,w] : edge[u]) {
            if (dist[v] > dist[u] + w) {
                dist[v] = dist[u] + w;
                q.push({dist[v], v});
            }
        }
    }
    return dist;
}

void trandkhoa() {
    cin >> n >> m;
    FOR(i, 1, m) {
        int u,v,w; cin >> u >> v >> w;
        edge[u].pb({v,w});
        edge[v].pb({u,w});
    }

    cin >> k;
    FOR(i, 1, k) {
        int x; cin >> x;
        npp.pb(x);
    }

	dist = dijkstra();

    cin >> q;
    FOR(i, 1, q) {
        int x,y; cin >> x >> y;
        cout << min(dist[x], dist[y]);
    }
}

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    //iofile("");
    int test = 1;
    //cin >> test;
    while(test--) trandkhoa();

    return (0 ^ 0);
}

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

plan.cpp:39:17: warning: overflow in conversion from 'long long int' to 'int' changes value from '9223372036854775807' to '-1' [-Woverflow]
   39 | const int INF = LLONG_MAX;
      |                 ^~~~~~~~~
plan.cpp: In function 'void iofile(std::string)':
plan.cpp:27:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     freopen((s + ".inp").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
plan.cpp:28:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…