# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
137089 | ksmzzang2003 | 철도 요금 (JOI16_ho_t3) | C++14 | 261 ms | 24184 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>
#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)
# | 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... |