답안 #1096469

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1096469 2024-10-04T14:06:20 Z phong 철도 요금 (JOI16_ho_t3) C++17
100 / 100
289 ms 61304 KB
#include<bits/stdc++.h>
#define ll long long
const int nmax = 3e5 + 2, M = 3e5;
const ll oo = 1e9 + 5, base = 3001;
const int lg = 18,mod = 998244353;
#define pii pair<int, int>
#define fi first
#define se second
#define endl "\n"
#define debug(a, n) for(int i = 1; i <= n; ++i) cout << a[i] << ' '; cout << "\n";
using namespace std;

int n, m, q;
vector<int> adj[nmax], one[nmax];
map<int, int>flag[nmax];
pii a[nmax]; int dp[nmax];

void Init(){
    for(int i = 1; i <= n; ++i) dp[i] = oo;
    dp[1] = 0;
    priority_queue<pii, vector<pii>, greater<pii>> q;
    q.push({0, 1});
    while(q.size()){
        pii tmp = q.top();q.pop();
        int u = tmp.se;
        if(tmp.fi!= dp[u]) continue;
        for(auto v : adj[u]){
            if(dp[v] > dp[u] + 1){
                dp[v] = dp[u] + 1;
                q.push({dp[v], v});
            }
        }
    }
    for(int u = 1; u <= n; ++u){
        for(auto v : adj[u]){
            if(dp[v] == dp[u] + 1){
                one[u].push_back(v);
//                cout << u << ' ' << v << endl;
            }
        }
    }
}
void Init_2(){
    for(int i = 1; i <= n; ++i) dp[i] = oo;
    dp[1] = 0;
     priority_queue<pii, vector<pii>, greater<pii>> q;

    q.push({0, 1});
    while(q.size()){
        pii tmp = q.top();q.pop();
        int u = tmp.se;
        if(tmp.fi!= dp[u]) continue;
        for(auto v : one[u]){
            int cost =max(dp[u], flag[u][v]);
            if(dp[v] > cost){
                dp[v] = cost;
                q.push({dp[v], v});
            }
        }

    }
}
int b[nmax];

main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
//    freopen("code.inp", "r", stdin);
//    freopen("code.out", "w", stdout);
    cin >> n >> m >> q;
    for(int i = 1; i <= m; ++i){
        cin >> a[i].fi >> a[i].se;
        adj[a[i].fi].push_back(a[i].se);
        adj[a[i].se].push_back(a[i].fi);
    }
    Init();
    for(int e = 1,x; e<= q; ++e){
        cin >> x;
        flag[a[x].fi][a[x].se] = q - e + 1;
        flag[a[x].se][a[x].fi] = q - e + 1;
        b[e] = x;
    }

    Init_2();
    for(int i = 1; i <= n; ++i) dp[i] = q - dp[i] + 1;
//    debug(dp, n);
    sort(dp + 1, dp + 1 + n);
    for(int e = 1; e <= q; ++e){
        int it = upper_bound(dp + 1, dp + 1 + n, e) - dp - 1;
        cout << it <<endl;
    }
}
/*
số lượng dp
*/

Compilation message

2016_ho_t3.cpp:65:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   65 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 28504 KB Output is correct
2 Correct 13 ms 28664 KB Output is correct
3 Correct 13 ms 28764 KB Output is correct
4 Correct 13 ms 28676 KB Output is correct
5 Correct 14 ms 28508 KB Output is correct
6 Correct 13 ms 28504 KB Output is correct
7 Correct 13 ms 28472 KB Output is correct
8 Correct 12 ms 28508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 28504 KB Output is correct
2 Correct 13 ms 28664 KB Output is correct
3 Correct 13 ms 28764 KB Output is correct
4 Correct 13 ms 28676 KB Output is correct
5 Correct 14 ms 28508 KB Output is correct
6 Correct 13 ms 28504 KB Output is correct
7 Correct 13 ms 28472 KB Output is correct
8 Correct 12 ms 28508 KB Output is correct
9 Correct 118 ms 45632 KB Output is correct
10 Correct 110 ms 45708 KB Output is correct
11 Correct 88 ms 45904 KB Output is correct
12 Correct 89 ms 45904 KB Output is correct
13 Correct 83 ms 45904 KB Output is correct
14 Correct 89 ms 46164 KB Output is correct
15 Correct 60 ms 42264 KB Output is correct
16 Correct 52 ms 41808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 109 ms 43232 KB Output is correct
2 Correct 114 ms 45684 KB Output is correct
3 Correct 120 ms 46136 KB Output is correct
4 Correct 85 ms 45952 KB Output is correct
5 Correct 73 ms 46160 KB Output is correct
6 Correct 72 ms 46160 KB Output is correct
7 Correct 47 ms 41940 KB Output is correct
8 Correct 46 ms 41808 KB Output is correct
9 Correct 62 ms 38280 KB Output is correct
10 Correct 69 ms 38172 KB Output is correct
11 Correct 135 ms 51920 KB Output is correct
12 Correct 121 ms 49356 KB Output is correct
13 Correct 113 ms 49100 KB Output is correct
14 Correct 142 ms 50764 KB Output is correct
15 Correct 159 ms 51660 KB Output is correct
16 Correct 144 ms 50940 KB Output is correct
17 Correct 131 ms 54608 KB Output is correct
18 Correct 103 ms 47952 KB Output is correct
19 Correct 210 ms 61304 KB Output is correct
20 Correct 130 ms 54616 KB Output is correct
21 Correct 83 ms 44840 KB Output is correct
22 Correct 80 ms 44624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 28504 KB Output is correct
2 Correct 13 ms 28664 KB Output is correct
3 Correct 13 ms 28764 KB Output is correct
4 Correct 13 ms 28676 KB Output is correct
5 Correct 14 ms 28508 KB Output is correct
6 Correct 13 ms 28504 KB Output is correct
7 Correct 13 ms 28472 KB Output is correct
8 Correct 12 ms 28508 KB Output is correct
9 Correct 118 ms 45632 KB Output is correct
10 Correct 110 ms 45708 KB Output is correct
11 Correct 88 ms 45904 KB Output is correct
12 Correct 89 ms 45904 KB Output is correct
13 Correct 83 ms 45904 KB Output is correct
14 Correct 89 ms 46164 KB Output is correct
15 Correct 60 ms 42264 KB Output is correct
16 Correct 52 ms 41808 KB Output is correct
17 Correct 109 ms 43232 KB Output is correct
18 Correct 114 ms 45684 KB Output is correct
19 Correct 120 ms 46136 KB Output is correct
20 Correct 85 ms 45952 KB Output is correct
21 Correct 73 ms 46160 KB Output is correct
22 Correct 72 ms 46160 KB Output is correct
23 Correct 47 ms 41940 KB Output is correct
24 Correct 46 ms 41808 KB Output is correct
25 Correct 62 ms 38280 KB Output is correct
26 Correct 69 ms 38172 KB Output is correct
27 Correct 135 ms 51920 KB Output is correct
28 Correct 121 ms 49356 KB Output is correct
29 Correct 113 ms 49100 KB Output is correct
30 Correct 142 ms 50764 KB Output is correct
31 Correct 159 ms 51660 KB Output is correct
32 Correct 144 ms 50940 KB Output is correct
33 Correct 131 ms 54608 KB Output is correct
34 Correct 103 ms 47952 KB Output is correct
35 Correct 210 ms 61304 KB Output is correct
36 Correct 130 ms 54616 KB Output is correct
37 Correct 83 ms 44840 KB Output is correct
38 Correct 80 ms 44624 KB Output is correct
39 Correct 289 ms 60940 KB Output is correct
40 Correct 240 ms 60792 KB Output is correct
41 Correct 152 ms 52824 KB Output is correct
42 Correct 191 ms 60920 KB Output is correct
43 Correct 154 ms 60924 KB Output is correct
44 Correct 142 ms 60752 KB Output is correct
45 Correct 135 ms 60844 KB Output is correct
46 Correct 94 ms 49124 KB Output is correct
47 Correct 79 ms 48184 KB Output is correct
48 Correct 84 ms 48028 KB Output is correct
49 Correct 122 ms 43608 KB Output is correct
50 Correct 136 ms 44244 KB Output is correct
51 Correct 143 ms 44600 KB Output is correct
52 Correct 160 ms 45452 KB Output is correct
53 Correct 129 ms 43120 KB Output is correct
54 Correct 135 ms 44168 KB Output is correct