답안 #287463

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
287463 2020-08-31T17:11:31 Z Namnamseo 철도 요금 (JOI16_ho_t3) C++17
100 / 100
469 ms 50508 KB
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef pair<int,int> pp;
priority_queue<pp> pq;

int n,m,q;

struct ES{
    int f,t;
    bool dead;
} ee[300010];

vector<int> edge    [300010];
vector<int> parent  [300010];
vector<int> child   [300010];
vector<int> child_ei[300010];

int  dijk[300010];
bool dead[300010];
int boolman;
int alive_pars[300010];

void dodijk(){
    int i;
    for(i=2;i<=n;++i) dijk[i]=1e9;
    pq.push(pp(0,1));
    int me;
    while(pq.size()){
        pp cur=pq.top(); pq.pop();
        if(dijk[me=cur.second]!=-cur.first) continue;
        int sz=edge[me].size(), nxt;
        for(i=0;i<sz;++i){
            ES& tmp=ee[edge[me][i]];
            nxt=tmp.f+tmp.t-me;
            
            if(dijk[nxt] > dijk[me]+1){
                dijk[nxt]=dijk[me]+1;
                pq.push(pp(-dijk[nxt],nxt));
                {
                    vector<int>().swap(parent[nxt]); // make empty
                    parent[nxt].clear();
                }
                parent[nxt].push_back(me);
                ++alive_pars[nxt];
                
                child [me].push_back(nxt);
                child_ei[me].push_back(edge[me][i]);
            } else if(dijk[nxt]==dijk[me]+1){
                parent[nxt].push_back(me);
                ++alive_pars[nxt];
                
                child [me].push_back(nxt);
                child_ei[me].push_back(edge[me][i]);
            }
        }
    }
}

void work(int x){
    if(alive_pars[x]==0 && !dead[x]){
        ++boolman;
        dead[x]=true;
        int i,sz=child[x].size(),nxt;
        for(i=0;i<sz;++i){
            nxt=child[x][i];
            if(!ee[child_ei[x][i]].dead){
                --alive_pars[nxt];
                work(nxt);
            }
        }
    }
}

int main()
{
    scanf("%d%d%d",&n,&m,&q);
    int i;
    for(i=1;i<=m;++i){
        int a,b;
        scanf("%d%d",&a,&b);
        ee[i].f=a; ee[i].t=b;
        ee[i].dead=false;
        edge[a].push_back(i);
        edge[b].push_back(i);
    }
    dodijk();
    
    for(;q--;){
        scanf("%d",&i);
        ee[i].dead=true;
        int a=ee[i].f, b=ee[i].t;
        if(dijk[a]>dijk[b]) swap(a,b);
        if(dijk[a]+1 == dijk[b]){
            if(!dead[a]){
                --alive_pars[b];
            }
            work(b);
        }
        printf("%d\n",boolman);
    }
    return 0;
}

Compilation message

2016_ho_t3.cpp: In function 'int main()':
2016_ho_t3.cpp:79:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   79 |     scanf("%d%d%d",&n,&m,&q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
2016_ho_t3.cpp:83:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   83 |         scanf("%d%d",&a,&b);
      |         ~~~~~^~~~~~~~~~~~~~
2016_ho_t3.cpp:92:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   92 |         scanf("%d",&i);
      |         ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 28544 KB Output is correct
2 Correct 20 ms 28544 KB Output is correct
3 Correct 21 ms 28664 KB Output is correct
4 Correct 19 ms 28544 KB Output is correct
5 Correct 20 ms 28544 KB Output is correct
6 Correct 20 ms 28544 KB Output is correct
7 Correct 20 ms 28544 KB Output is correct
8 Correct 19 ms 28544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 28544 KB Output is correct
2 Correct 20 ms 28544 KB Output is correct
3 Correct 21 ms 28664 KB Output is correct
4 Correct 19 ms 28544 KB Output is correct
5 Correct 20 ms 28544 KB Output is correct
6 Correct 20 ms 28544 KB Output is correct
7 Correct 20 ms 28544 KB Output is correct
8 Correct 19 ms 28544 KB Output is correct
9 Correct 270 ms 45424 KB Output is correct
10 Correct 259 ms 45424 KB Output is correct
11 Correct 212 ms 45196 KB Output is correct
12 Correct 211 ms 45432 KB Output is correct
13 Correct 193 ms 45560 KB Output is correct
14 Correct 186 ms 46328 KB Output is correct
15 Correct 132 ms 47992 KB Output is correct
16 Correct 127 ms 44152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 269 ms 45592 KB Output is correct
2 Correct 289 ms 45476 KB Output is correct
3 Correct 181 ms 41140 KB Output is correct
4 Correct 199 ms 45308 KB Output is correct
5 Correct 221 ms 46380 KB Output is correct
6 Correct 216 ms 46372 KB Output is correct
7 Correct 122 ms 44152 KB Output is correct
8 Correct 144 ms 44180 KB Output is correct
9 Correct 108 ms 38016 KB Output is correct
10 Correct 103 ms 38124 KB Output is correct
11 Correct 321 ms 45988 KB Output is correct
12 Correct 292 ms 45304 KB Output is correct
13 Correct 299 ms 45052 KB Output is correct
14 Correct 317 ms 46284 KB Output is correct
15 Correct 335 ms 46712 KB Output is correct
16 Correct 337 ms 46572 KB Output is correct
17 Correct 317 ms 50444 KB Output is correct
18 Correct 274 ms 50124 KB Output is correct
19 Correct 469 ms 48540 KB Output is correct
20 Correct 346 ms 50508 KB Output is correct
21 Correct 250 ms 47224 KB Output is correct
22 Correct 248 ms 46968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 28544 KB Output is correct
2 Correct 20 ms 28544 KB Output is correct
3 Correct 21 ms 28664 KB Output is correct
4 Correct 19 ms 28544 KB Output is correct
5 Correct 20 ms 28544 KB Output is correct
6 Correct 20 ms 28544 KB Output is correct
7 Correct 20 ms 28544 KB Output is correct
8 Correct 19 ms 28544 KB Output is correct
9 Correct 270 ms 45424 KB Output is correct
10 Correct 259 ms 45424 KB Output is correct
11 Correct 212 ms 45196 KB Output is correct
12 Correct 211 ms 45432 KB Output is correct
13 Correct 193 ms 45560 KB Output is correct
14 Correct 186 ms 46328 KB Output is correct
15 Correct 132 ms 47992 KB Output is correct
16 Correct 127 ms 44152 KB Output is correct
17 Correct 269 ms 45592 KB Output is correct
18 Correct 289 ms 45476 KB Output is correct
19 Correct 181 ms 41140 KB Output is correct
20 Correct 199 ms 45308 KB Output is correct
21 Correct 221 ms 46380 KB Output is correct
22 Correct 216 ms 46372 KB Output is correct
23 Correct 122 ms 44152 KB Output is correct
24 Correct 144 ms 44180 KB Output is correct
25 Correct 108 ms 38016 KB Output is correct
26 Correct 103 ms 38124 KB Output is correct
27 Correct 321 ms 45988 KB Output is correct
28 Correct 292 ms 45304 KB Output is correct
29 Correct 299 ms 45052 KB Output is correct
30 Correct 317 ms 46284 KB Output is correct
31 Correct 335 ms 46712 KB Output is correct
32 Correct 337 ms 46572 KB Output is correct
33 Correct 317 ms 50444 KB Output is correct
34 Correct 274 ms 50124 KB Output is correct
35 Correct 469 ms 48540 KB Output is correct
36 Correct 346 ms 50508 KB Output is correct
37 Correct 250 ms 47224 KB Output is correct
38 Correct 248 ms 46968 KB Output is correct
39 Correct 453 ms 47872 KB Output is correct
40 Correct 456 ms 47856 KB Output is correct
41 Correct 244 ms 42348 KB Output is correct
42 Correct 335 ms 48020 KB Output is correct
43 Correct 344 ms 47892 KB Output is correct
44 Correct 334 ms 48888 KB Output is correct
45 Correct 304 ms 48888 KB Output is correct
46 Correct 184 ms 48120 KB Output is correct
47 Correct 166 ms 45492 KB Output is correct
48 Correct 167 ms 45456 KB Output is correct
49 Correct 146 ms 38960 KB Output is correct
50 Correct 142 ms 39208 KB Output is correct
51 Correct 185 ms 39940 KB Output is correct
52 Correct 184 ms 39972 KB Output is correct
53 Correct 151 ms 38712 KB Output is correct
54 Correct 197 ms 39128 KB Output is correct