Submission #137089

#TimeUsernameProblemLanguageResultExecution timeMemory
137089ksmzzang2003철도 요금 (JOI16_ho_t3)C++14
100 / 100
261 ms24184 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...