# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
137079 | 2019-07-27T04:31:42 Z | arnold518 | 철도 요금 (JOI16_ho_t3) | C++14 | 269 ms | 21496 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 1e5; const int MAXM = 2e5; const int INF = 987654321; struct Edge { int u, v; }; int N, M, Q, query[MAXM+10]; vector<int> adj[MAXN+10]; vector<pii> adj2[MAXN+10]; Edge edge[MAXM+10]; pii dist[MAXN+10]; int dp[MAXN+10], ans[MAXM+10]; int main() { int i, j; scanf("%d%d%d", &N, &M, &Q); for(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]={u, v}; } for(i=1; i<=Q; i++) { int t; scanf("%d", &t); query[t]=i; } for(i=1; i<=N; i++) dist[i]={-1, i}; queue<int> BQ; dist[1].first=0; BQ.push(1); while(!BQ.empty()) { int now=BQ.front(); BQ.pop(); for(int nxt : adj[now]) { if(dist[nxt].first!=-1) continue; dist[nxt].first=dist[now].first+1; BQ.push(nxt); } } for(i=1; i<=M; i++) { Edge &now=edge[i]; int t=INF; if(query[i]!=0) t=query[i]; if(dist[now.u].first+1==dist[now.v].first) adj2[now.v].push_back({now.u, t}); else if(dist[now.v].first+1==dist[now.u].first) adj2[now.u].push_back({now.v, t}); } sort(dist+1, dist+N+1); dp[1]=INF; for(i=2; i<=N; i++) { int now=dist[i].second; for(pii nxt : adj2[now]) dp[now]=max(dp[now], min(dp[nxt.first], nxt.second)); if(dp[now]!=INF) ans[dp[now]]++; //printf("%d %d\n", now, dp[now]); } for(i=1; i<=Q; i++) ans[i]+=ans[i-1]; for(i=1; i<=Q; i++) printf("%d\n", ans[i]); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 5112 KB | Output is correct |
2 | Correct | 7 ms | 5240 KB | Output is correct |
3 | Correct | 7 ms | 5240 KB | Output is correct |
4 | Correct | 6 ms | 4984 KB | Output is correct |
5 | Correct | 7 ms | 5116 KB | Output is correct |
6 | Correct | 8 ms | 4984 KB | Output is correct |
7 | Correct | 7 ms | 4984 KB | Output is correct |
8 | Correct | 8 ms | 5140 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 5112 KB | Output is correct |
2 | Correct | 7 ms | 5240 KB | Output is correct |
3 | Correct | 7 ms | 5240 KB | Output is correct |
4 | Correct | 6 ms | 4984 KB | Output is correct |
5 | Correct | 7 ms | 5116 KB | Output is correct |
6 | Correct | 8 ms | 4984 KB | Output is correct |
7 | Correct | 7 ms | 4984 KB | Output is correct |
8 | Correct | 8 ms | 5140 KB | Output is correct |
9 | Correct | 250 ms | 17244 KB | Output is correct |
10 | Correct | 221 ms | 17272 KB | Output is correct |
11 | Correct | 152 ms | 17528 KB | Output is correct |
12 | Correct | 223 ms | 17528 KB | Output is correct |
13 | Correct | 173 ms | 17396 KB | Output is correct |
14 | Correct | 269 ms | 17144 KB | Output is correct |
15 | Correct | 141 ms | 14968 KB | Output is correct |
16 | Correct | 97 ms | 14584 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 250 ms | 15964 KB | Output is correct |
2 | Correct | 169 ms | 17596 KB | Output is correct |
3 | Correct | 116 ms | 16752 KB | Output is correct |
4 | Correct | 150 ms | 17736 KB | Output is correct |
5 | Correct | 147 ms | 17272 KB | Output is correct |
6 | Correct | 155 ms | 17240 KB | Output is correct |
7 | Correct | 131 ms | 14712 KB | Output is correct |
8 | Correct | 100 ms | 14684 KB | Output is correct |
9 | Correct | 79 ms | 13424 KB | Output is correct |
10 | Correct | 60 ms | 13168 KB | Output is correct |
11 | Correct | 184 ms | 18936 KB | Output is correct |
12 | Correct | 172 ms | 18296 KB | Output is correct |
13 | Correct | 194 ms | 18160 KB | Output is correct |
14 | Correct | 198 ms | 18996 KB | Output is correct |
15 | Correct | 203 ms | 18168 KB | Output is correct |
16 | Correct | 173 ms | 17876 KB | Output is correct |
17 | Correct | 199 ms | 18648 KB | Output is correct |
18 | Correct | 155 ms | 16376 KB | Output is correct |
19 | Correct | 230 ms | 21496 KB | Output is correct |
20 | Correct | 194 ms | 18524 KB | Output is correct |
21 | Correct | 134 ms | 15536 KB | Output is correct |
22 | Correct | 129 ms | 15412 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 5112 KB | Output is correct |
2 | Correct | 7 ms | 5240 KB | Output is correct |
3 | Correct | 7 ms | 5240 KB | Output is correct |
4 | Correct | 6 ms | 4984 KB | Output is correct |
5 | Correct | 7 ms | 5116 KB | Output is correct |
6 | Correct | 8 ms | 4984 KB | Output is correct |
7 | Correct | 7 ms | 4984 KB | Output is correct |
8 | Correct | 8 ms | 5140 KB | Output is correct |
9 | Correct | 250 ms | 17244 KB | Output is correct |
10 | Correct | 221 ms | 17272 KB | Output is correct |
11 | Correct | 152 ms | 17528 KB | Output is correct |
12 | Correct | 223 ms | 17528 KB | Output is correct |
13 | Correct | 173 ms | 17396 KB | Output is correct |
14 | Correct | 269 ms | 17144 KB | Output is correct |
15 | Correct | 141 ms | 14968 KB | Output is correct |
16 | Correct | 97 ms | 14584 KB | Output is correct |
17 | Correct | 250 ms | 15964 KB | Output is correct |
18 | Correct | 169 ms | 17596 KB | Output is correct |
19 | Correct | 116 ms | 16752 KB | Output is correct |
20 | Correct | 150 ms | 17736 KB | Output is correct |
21 | Correct | 147 ms | 17272 KB | Output is correct |
22 | Correct | 155 ms | 17240 KB | Output is correct |
23 | Correct | 131 ms | 14712 KB | Output is correct |
24 | Correct | 100 ms | 14684 KB | Output is correct |
25 | Correct | 79 ms | 13424 KB | Output is correct |
26 | Correct | 60 ms | 13168 KB | Output is correct |
27 | Correct | 184 ms | 18936 KB | Output is correct |
28 | Correct | 172 ms | 18296 KB | Output is correct |
29 | Correct | 194 ms | 18160 KB | Output is correct |
30 | Correct | 198 ms | 18996 KB | Output is correct |
31 | Correct | 203 ms | 18168 KB | Output is correct |
32 | Correct | 173 ms | 17876 KB | Output is correct |
33 | Correct | 199 ms | 18648 KB | Output is correct |
34 | Correct | 155 ms | 16376 KB | Output is correct |
35 | Correct | 230 ms | 21496 KB | Output is correct |
36 | Correct | 194 ms | 18524 KB | Output is correct |
37 | Correct | 134 ms | 15536 KB | Output is correct |
38 | Correct | 129 ms | 15412 KB | Output is correct |
39 | Correct | 235 ms | 21240 KB | Output is correct |
40 | Correct | 245 ms | 21316 KB | Output is correct |
41 | Correct | 198 ms | 18412 KB | Output is correct |
42 | Correct | 239 ms | 21444 KB | Output is correct |
43 | Correct | 222 ms | 21240 KB | Output is correct |
44 | Correct | 222 ms | 20940 KB | Output is correct |
45 | Correct | 216 ms | 20968 KB | Output is correct |
46 | Correct | 133 ms | 16760 KB | Output is correct |
47 | Correct | 128 ms | 16504 KB | Output is correct |
48 | Correct | 131 ms | 16404 KB | Output is correct |
49 | Correct | 106 ms | 14804 KB | Output is correct |
50 | Correct | 95 ms | 14824 KB | Output is correct |
51 | Correct | 105 ms | 15600 KB | Output is correct |
52 | Correct | 99 ms | 15604 KB | Output is correct |
53 | Correct | 115 ms | 14832 KB | Output is correct |
54 | Correct | 112 ms | 14704 KB | Output is correct |