Submission #58745

# Submission time Handle Problem Language Result Execution time Memory
58745 2018-07-19T07:03:24 Z leejseo None (JOI16_ho_t3) C++
26 / 100
2500 ms 29852 KB
#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

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 time Memory Grader output
1 Correct 6 ms 2680 KB Output is correct
2 Correct 5 ms 2792 KB Output is correct
3 Correct 6 ms 3032 KB Output is correct
4 Correct 5 ms 3032 KB Output is correct
5 Correct 7 ms 3032 KB Output is correct
6 Correct 6 ms 3032 KB Output is correct
7 Correct 5 ms 3032 KB Output is correct
8 Correct 6 ms 3032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2680 KB Output is correct
2 Correct 5 ms 2792 KB Output is correct
3 Correct 6 ms 3032 KB Output is correct
4 Correct 5 ms 3032 KB Output is correct
5 Correct 7 ms 3032 KB Output is correct
6 Correct 6 ms 3032 KB Output is correct
7 Correct 5 ms 3032 KB Output is correct
8 Correct 6 ms 3032 KB Output is correct
9 Correct 2070 ms 13496 KB Output is correct
10 Correct 2242 ms 15988 KB Output is correct
11 Correct 1250 ms 17144 KB Output is correct
12 Correct 920 ms 19704 KB Output is correct
13 Correct 1197 ms 22008 KB Output is correct
14 Correct 1018 ms 24048 KB Output is correct
15 Correct 545 ms 24048 KB Output is correct
16 Correct 706 ms 24476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2517 ms 29852 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2680 KB Output is correct
2 Correct 5 ms 2792 KB Output is correct
3 Correct 6 ms 3032 KB Output is correct
4 Correct 5 ms 3032 KB Output is correct
5 Correct 7 ms 3032 KB Output is correct
6 Correct 6 ms 3032 KB Output is correct
7 Correct 5 ms 3032 KB Output is correct
8 Correct 6 ms 3032 KB Output is correct
9 Correct 2070 ms 13496 KB Output is correct
10 Correct 2242 ms 15988 KB Output is correct
11 Correct 1250 ms 17144 KB Output is correct
12 Correct 920 ms 19704 KB Output is correct
13 Correct 1197 ms 22008 KB Output is correct
14 Correct 1018 ms 24048 KB Output is correct
15 Correct 545 ms 24048 KB Output is correct
16 Correct 706 ms 24476 KB Output is correct
17 Execution timed out 2517 ms 29852 KB Time limit exceeded
18 Halted 0 ms 0 KB -