# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
58745 | leejseo | 철도 요금 (JOI16_ho_t3) | C++98 | 2517 ms | 29852 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |