답안 #34921

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
34921 2017-11-17T05:00:09 Z leejseo 주유소 (KOI16_gas) C++11
42 / 100
129 ms 65536 KB
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

#define maxint 9E18
#define all(v) v.begin(), v.end()
#define MAXV 2500
#define MAXE 4000

int V, E;
int oil[MAXV];

struct Edge{
    int to;
    long long weight;
    Edge (int t_, long long w_) {to = t_; weight = w_;}
};

struct Node{
    int u;
    long long dist;
    Node (int u_, long long d_) {u = u_; dist = d_;}
    bool operator < (const Node &a) const {return dist > a.dist;}
};

vector<Edge> adj[MAXV];
long long dist[MAXV];
void dijkstra(int start, vector<Edge> *adj_list){
    priority_queue<Node> Q;
    for (int i=0; i<V; i++){
        dist[i] = maxint;
    }
    dist[start] = 0;
    Q.push(Node(start, 0));
    while (!Q.empty()){
        int u = Q.top().u;
        long long dist_u = Q.top().dist;
        Q.pop();
        if (dist[u] < dist_u) {
            continue;
        }
        for (int i=0; i<adj_list[u].size(); i++){
            int v = adj_list[u][i].to;
            long long dist_v = dist_u + adj_list[u][i].weight;
            if (dist_v < dist[v]){
                dist[v] = dist_v;
                Q.push(Node(v, dist_v));
            }
        }
    }
}

long long solve(){
    vector<Edge> cost_graph[V];
    for (int i=0; i<V; i++){
        dijkstra(i, adj);
        for (int j=0; j<V; j++){
            if (j == i || dist[j] == maxint){
                continue;
            }
            long long cost = dist[j] * oil[i];
            cost_graph[i].push_back(Edge(j, cost));
        }
    }
    dijkstra(0, cost_graph);
    return dist[V-1];
}

int main(){
    scanf("%d %d", &V, &E);
    for (int i=0; i<V; i++){
        scanf("%d", &oil[i]);
    }
    for (int i=0; i<E; i++){
        int fr, to, weight;

        scanf("%d %d %d", &fr, &to, &weight);
        fr--; to--;
        adj[fr].push_back(Edge(to, weight));
        adj[to].push_back(Edge(fr, weight));
    }
    long long r = solve();
    printf("%lld\n", r);
    return 0;
}

Compilation message

gas.cpp: In function 'void dijkstra(int, std::vector<Edge>*)':
gas.cpp:45:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i=0; i<adj_list[u].size(); i++){
                        ^
gas.cpp: In function 'int main()':
gas.cpp:73:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &V, &E);
                           ^
gas.cpp:75:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &oil[i]);
                             ^
gas.cpp:80:45: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d", &fr, &to, &weight);
                                             ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1260 KB Output is correct
2 Correct 0 ms 1260 KB Output is correct
3 Correct 0 ms 1260 KB Output is correct
4 Correct 0 ms 1260 KB Output is correct
5 Correct 0 ms 1260 KB Output is correct
6 Correct 0 ms 1260 KB Output is correct
7 Correct 0 ms 1260 KB Output is correct
8 Correct 0 ms 1260 KB Output is correct
9 Correct 0 ms 1260 KB Output is correct
10 Correct 0 ms 1260 KB Output is correct
11 Correct 0 ms 1260 KB Output is correct
12 Correct 0 ms 1260 KB Output is correct
13 Correct 0 ms 1260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Memory limit exceeded 129 ms 65536 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Memory limit exceeded 116 ms 65536 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1260 KB Output is correct
2 Correct 0 ms 1260 KB Output is correct
3 Correct 0 ms 1260 KB Output is correct
4 Correct 0 ms 1260 KB Output is correct
5 Correct 0 ms 1260 KB Output is correct
6 Correct 0 ms 1260 KB Output is correct
7 Correct 0 ms 1260 KB Output is correct
8 Correct 0 ms 1260 KB Output is correct
9 Correct 0 ms 1260 KB Output is correct
10 Correct 0 ms 1260 KB Output is correct
11 Correct 0 ms 1260 KB Output is correct
12 Correct 0 ms 1260 KB Output is correct
13 Correct 0 ms 1260 KB Output is correct
14 Correct 16 ms 5500 KB Output is correct
15 Correct 29 ms 5328 KB Output is correct
16 Correct 23 ms 5336 KB Output is correct
17 Correct 56 ms 5580 KB Output is correct
18 Correct 53 ms 5588 KB Output is correct
19 Correct 29 ms 5380 KB Output is correct
20 Correct 29 ms 5380 KB Output is correct
21 Correct 33 ms 5196 KB Output is correct
22 Correct 26 ms 5380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1260 KB Output is correct
2 Correct 0 ms 1260 KB Output is correct
3 Correct 0 ms 1260 KB Output is correct
4 Correct 0 ms 1260 KB Output is correct
5 Correct 0 ms 1260 KB Output is correct
6 Correct 0 ms 1260 KB Output is correct
7 Correct 0 ms 1260 KB Output is correct
8 Correct 0 ms 1260 KB Output is correct
9 Correct 0 ms 1260 KB Output is correct
10 Correct 0 ms 1260 KB Output is correct
11 Correct 0 ms 1260 KB Output is correct
12 Correct 0 ms 1260 KB Output is correct
13 Correct 0 ms 1260 KB Output is correct
14 Memory limit exceeded 129 ms 65536 KB Memory limit exceeded
15 Halted 0 ms 0 KB -