Submission #58745

#TimeUsernameProblemLanguageResultExecution timeMemory
58745leejseo철도 요금 (JOI16_ho_t3)C++98
26 / 100
2517 ms29852 KiB
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 100000;
const int INF  = (int) 2e9;
typedef struct Edge{
    int s, t, w;
    Edge(int s_, int t_, int w_){ s = s_, t= t_, w = w_; }
} Edge;

typedef struct Node{
    int i, d;
    Node (int i_, int d_){i = i_, d = d_;}
    bool operator < (const Node &N) const{
        if (d != N.d) return d > N.d;
        return i < N.i;
    }
} Node;

vector<Edge> E;
vector<int> adj[MAXN+1];
int N, M, Q, dist[MAXN+1], pre[MAXN+1];
priority_queue<Node> que;

void dijkstra(){
    dist[1] = 0;
    que.push(Node(1, 0));
    while (!que.empty()){
        Node N = que.top();
        que.pop();
        int i = N.i, d = N.d;
        if (d > dist[i]) continue;
        dist[i] = d;
        for (auto &h : adj[i]){
            Edge e = E[h];
            int j = e.t, weight = e.w;
            if (j == i) j = e.s;
            int dist_j = dist[i] + weight;
            if (dist[j] > dist_j){
                dist[j] = dist_j;
                que.push(Node(j, dist_j));
            }
        }
    }
}

void init(){
    for (int i=1; i<=N; i++){
        dist[i] = INF;
    }
}

void input(){
    scanf("%d%d%d", &N, &M, &Q);
    E.push_back(Edge(0, 0, 0));
    for (int i=1; i<=M; i++){
        int u, v;
        scanf("%d%d", &u, &v);
        E.push_back(Edge(u, v, 1));
        adj[u].push_back(i);
        adj[v].push_back(i);
    }
}

int main(void){
    input();
    init();
    dijkstra();
    for (int i=1; i<=N; i++) pre[i] = dist[i];
    while (Q--){
        int num;
        scanf("%d",&num);
        init();
        E[num].w = 2;
        dijkstra();
        int ans = 0;
        for (int i=1; i<=N; i++){
            if (dist[i] != pre[i]) ans++;
        }
        printf("%d\n", ans);
    }
}

Compilation message (stderr)

2016_ho_t3.cpp: In function 'void input()':
2016_ho_t3.cpp:54:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d", &N, &M, &Q);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
2016_ho_t3.cpp:58:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &u, &v);
         ~~~~~^~~~~~~~~~~~~~~~
2016_ho_t3.cpp: In function 'int main()':
2016_ho_t3.cpp:72:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&num);
         ~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...