Submission #137089

# Submission time Handle Problem Language Result Execution time Memory
137089 2019-07-27T05:07:03 Z ksmzzang2003 None (JOI16_ho_t3) C++14
100 / 100
261 ms 24184 KB
#include <bits/stdc++.h>
#define maxn 200009
using namespace std;
typedef pair <int,int> pii;
int N,M,Q,query[maxn],ans[maxn],dp[maxn];
vector <int> adj[maxn];
vector <pii> adj2[maxn];
pii edge[maxn],dist[maxn];
int main() {
    scanf("%d%d%d",&N,&M,&Q);
    for(int i=1; i<=M; i++) {
        int u,v;
        scanf("%d%d",&u,&v);
        adj[u].push_back(v);
        adj[v].push_back(u);
        edge[i] = pii(u,v);
    }
    for(int i=1; i<=Q; i++) {
        int x;
        scanf("%d",&x) ;
        query[x] = i;
    }
    for(int i=1; i<=N; i++)
        dist[i] = pii(-1,i);
    queue <int> q;
    dist[1] .first=0 ;
    q.push(1);
    while(!q.empty()) {
        int x = q.front(); q.pop();
        for(int next:adj[x]){
            if(dist[next].first!=-1) continue;
            dist[next]. first = dist[x].first +1;
            q.push(next);
        }
    }
    for(int i=1;i<=M;i++){
        pii now = edge[i];
        int t = 1987654321;
        if(query[i]) t=query[i] ;
        if(dist[now.first].first+1 == dist[now.second].first) adj2[now.second].push_back(pii(now.first,t));
        else if(dist[now.second].first+1 == dist[now.first].first) adj2[now.first].push_back(pii(now.second,t));
    }
    sort(dist+1,dist+1+N);
    dp[1] = 1987654321;
    for(int i=2;i<=N;i++){
        int now = dist[i].second;
        for(pii next:adj2[now]) dp[now] = max(dp[now],min(dp[next.first],next.second));
        if(dp[now]<987654321) ans[dp[now]]++;
    }
    for(int i=1;i<=Q;i++) ans[i]+=ans[i-1],printf("%d\n",ans[i]);
}

Compilation message

2016_ho_t3.cpp: In function 'int main()':
2016_ho_t3.cpp:10: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:13: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:20:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&x) ;
         ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 14 ms 9720 KB Output is correct
2 Correct 10 ms 9720 KB Output is correct
3 Correct 11 ms 9848 KB Output is correct
4 Correct 10 ms 9724 KB Output is correct
5 Correct 11 ms 9720 KB Output is correct
6 Correct 11 ms 9720 KB Output is correct
7 Correct 10 ms 9720 KB Output is correct
8 Correct 10 ms 9720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 9720 KB Output is correct
2 Correct 10 ms 9720 KB Output is correct
3 Correct 11 ms 9848 KB Output is correct
4 Correct 10 ms 9724 KB Output is correct
5 Correct 11 ms 9720 KB Output is correct
6 Correct 11 ms 9720 KB Output is correct
7 Correct 10 ms 9720 KB Output is correct
8 Correct 10 ms 9720 KB Output is correct
9 Correct 156 ms 19688 KB Output is correct
10 Correct 184 ms 21240 KB Output is correct
11 Correct 158 ms 21368 KB Output is correct
12 Correct 147 ms 21240 KB Output is correct
13 Correct 152 ms 21188 KB Output is correct
14 Correct 180 ms 21048 KB Output is correct
15 Correct 108 ms 19704 KB Output is correct
16 Correct 90 ms 19292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 186 ms 20140 KB Output is correct
2 Correct 175 ms 21444 KB Output is correct
3 Correct 120 ms 21056 KB Output is correct
4 Correct 150 ms 21648 KB Output is correct
5 Correct 144 ms 21064 KB Output is correct
6 Correct 150 ms 21112 KB Output is correct
7 Correct 96 ms 19320 KB Output is correct
8 Correct 97 ms 19364 KB Output is correct
9 Correct 71 ms 18032 KB Output is correct
10 Correct 63 ms 17900 KB Output is correct
11 Correct 180 ms 22392 KB Output is correct
12 Correct 200 ms 22164 KB Output is correct
13 Correct 181 ms 21972 KB Output is correct
14 Correct 232 ms 22552 KB Output is correct
15 Correct 197 ms 21800 KB Output is correct
16 Correct 193 ms 21680 KB Output is correct
17 Correct 200 ms 22008 KB Output is correct
18 Correct 183 ms 20856 KB Output is correct
19 Correct 237 ms 24184 KB Output is correct
20 Correct 209 ms 21880 KB Output is correct
21 Correct 136 ms 20304 KB Output is correct
22 Correct 131 ms 20216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 9720 KB Output is correct
2 Correct 10 ms 9720 KB Output is correct
3 Correct 11 ms 9848 KB Output is correct
4 Correct 10 ms 9724 KB Output is correct
5 Correct 11 ms 9720 KB Output is correct
6 Correct 11 ms 9720 KB Output is correct
7 Correct 10 ms 9720 KB Output is correct
8 Correct 10 ms 9720 KB Output is correct
9 Correct 156 ms 19688 KB Output is correct
10 Correct 184 ms 21240 KB Output is correct
11 Correct 158 ms 21368 KB Output is correct
12 Correct 147 ms 21240 KB Output is correct
13 Correct 152 ms 21188 KB Output is correct
14 Correct 180 ms 21048 KB Output is correct
15 Correct 108 ms 19704 KB Output is correct
16 Correct 90 ms 19292 KB Output is correct
17 Correct 186 ms 20140 KB Output is correct
18 Correct 175 ms 21444 KB Output is correct
19 Correct 120 ms 21056 KB Output is correct
20 Correct 150 ms 21648 KB Output is correct
21 Correct 144 ms 21064 KB Output is correct
22 Correct 150 ms 21112 KB Output is correct
23 Correct 96 ms 19320 KB Output is correct
24 Correct 97 ms 19364 KB Output is correct
25 Correct 71 ms 18032 KB Output is correct
26 Correct 63 ms 17900 KB Output is correct
27 Correct 180 ms 22392 KB Output is correct
28 Correct 200 ms 22164 KB Output is correct
29 Correct 181 ms 21972 KB Output is correct
30 Correct 232 ms 22552 KB Output is correct
31 Correct 197 ms 21800 KB Output is correct
32 Correct 193 ms 21680 KB Output is correct
33 Correct 200 ms 22008 KB Output is correct
34 Correct 183 ms 20856 KB Output is correct
35 Correct 237 ms 24184 KB Output is correct
36 Correct 209 ms 21880 KB Output is correct
37 Correct 136 ms 20304 KB Output is correct
38 Correct 131 ms 20216 KB Output is correct
39 Correct 261 ms 23768 KB Output is correct
40 Correct 252 ms 23716 KB Output is correct
41 Correct 174 ms 22000 KB Output is correct
42 Correct 241 ms 23928 KB Output is correct
43 Correct 209 ms 23800 KB Output is correct
44 Correct 226 ms 23544 KB Output is correct
45 Correct 221 ms 23672 KB Output is correct
46 Correct 130 ms 20984 KB Output is correct
47 Correct 124 ms 20828 KB Output is correct
48 Correct 131 ms 20856 KB Output is correct
49 Correct 104 ms 19696 KB Output is correct
50 Correct 93 ms 19460 KB Output is correct
51 Correct 106 ms 20336 KB Output is correct
52 Correct 103 ms 20208 KB Output is correct
53 Correct 104 ms 19468 KB Output is correct
54 Correct 93 ms 19412 KB Output is correct