답안 #603449

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
603449 2022-07-24T07:01:58 Z 박상훈(#8426) 동기화 (JOI13_synchronization) C++17
0 / 100
74 ms 8332 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
int A[100100], B[100100], on[100100], dp[100100], ans;
vector<pair<int, int>> adj[100100];

void dijkstra(int s){
    priority_queue<pair<int, int>> pq;
    pq.emplace(1e9, s);
    dp[s] = 1e9;
    ans = 0;
    while(!pq.empty()){
        auto [t, v] = pq.top(); pq.pop();
        for (auto &[w, z]:adj[v]) if (z<t){
            if (dp[w] < z){
                dp[w] = z;
                pq.emplace(dp[w], w);
            }
        }

        ans++;
    }
}

int main(){
    int n, m, q;
    scanf("%d %d %d", &n, &m, &q);
    for (int i=1;i<=n-1;i++){
        scanf("%d %d", A+i, B+i);
    }

    for (int i=1;i<=m;i++){
        int x;
        scanf("%d", &x);
        if (!on[x]){
            adj[A[x]].emplace_back(B[x], i);
            adj[B[x]].emplace_back(A[x], i);

            //printf(" %d %d %d\n", A[x], B[x], i);
        }
        on[x] ^= 1;
    }

    int s;
    scanf("%d", &s);
    dijkstra(s);
    printf("%d\n", ans);
    return 0;
}

Compilation message

synchronization.cpp: In function 'int main()':
synchronization.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     scanf("%d %d %d", &n, &m, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
synchronization.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |         scanf("%d %d", A+i, B+i);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~
synchronization.cpp:35:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |         scanf("%d", &x);
      |         ~~~~~^~~~~~~~~~
synchronization.cpp:46:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |     scanf("%d", &s);
      |     ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 51 ms 8116 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 74 ms 8332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -