답안 #1055742

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1055742 2024-08-13T04:44:55 Z 캐나다 선발고사 레전드(#11109) Treasure Hunt (CCO24_day1problem1) C++17
25 / 25
1129 ms 97944 KB
#include <bits/stdc++.h>
using namespace std;

int n,m;
typedef pair<int,int> P;
vector<P> adj[1000005];
int arr[1000005];
bool save[1000005];
priority_queue<P> pq;
priority_queue<P> er;

int main(void) {
    scanf("%d %d",&n,&m);
    vector<P> v;
    for(int i=1;i<=n;i++) {
        scanf("%d",&arr[i]);
        pq.push(P(arr[i],i));
    }
    for(int i=0;i<m;i++) {
        int u,v,w;
        scanf("%d %d %d",&u,&v,&w);
        adj[u].push_back(P(v,w));
        adj[v].push_back(P(u,w));
    }
    while (!pq.empty()) {
        while (!er.empty()&&er.top()==pq.top()) {
            er.pop();
            pq.pop();
        }
        int now=pq.top().second;
        pq.pop();
        save[now]=true;
        for(int i=0;i<adj[now].size();i++) {
            int nt=adj[now][i].first;
            if (!save[nt]) {
                er.push(P(arr[nt],nt));
                arr[nt]=max(arr[nt],arr[now]-adj[now][i].second);
                pq.push(P(arr[nt],nt));
            }
        }
                while (!er.empty()&&er.top()==pq.top()) {
            er.pop();
            pq.pop();
        }
    }
    for(int i=1;i<=n;i++) {
        printf("%d\n",arr[i]);
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:33:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |         for(int i=0;i<adj[now].size();i++) {
      |                     ~^~~~~~~~~~~~~~~~
Main.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     scanf("%d %d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~
Main.cpp:16:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |         scanf("%d",&arr[i]);
      |         ~~~~~^~~~~~~~~~~~~~
Main.cpp:21:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         scanf("%d %d %d",&u,&v,&w);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 26716 KB Output is correct
2 Correct 5 ms 26716 KB Output is correct
3 Correct 5 ms 26580 KB Output is correct
4 Correct 5 ms 26716 KB Output is correct
5 Correct 3 ms 26556 KB Output is correct
6 Correct 3 ms 26460 KB Output is correct
7 Correct 3 ms 26460 KB Output is correct
8 Correct 5 ms 26716 KB Output is correct
9 Correct 5 ms 26576 KB Output is correct
10 Correct 5 ms 26716 KB Output is correct
11 Correct 4 ms 26716 KB Output is correct
12 Correct 5 ms 26716 KB Output is correct
13 Correct 4 ms 26460 KB Output is correct
14 Correct 3 ms 26460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1008 ms 90780 KB Output is correct
2 Correct 997 ms 90908 KB Output is correct
3 Correct 965 ms 91008 KB Output is correct
4 Correct 931 ms 90980 KB Output is correct
5 Correct 912 ms 97944 KB Output is correct
6 Correct 978 ms 97428 KB Output is correct
7 Correct 899 ms 87056 KB Output is correct
8 Correct 946 ms 86920 KB Output is correct
9 Correct 871 ms 84784 KB Output is correct
10 Correct 903 ms 84540 KB Output is correct
11 Correct 815 ms 80788 KB Output is correct
12 Correct 881 ms 80928 KB Output is correct
13 Correct 790 ms 77736 KB Output is correct
14 Correct 776 ms 78420 KB Output is correct
15 Correct 499 ms 66596 KB Output is correct
16 Correct 515 ms 66700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1060 ms 96324 KB Output is correct
2 Correct 1087 ms 96416 KB Output is correct
3 Correct 1067 ms 96160 KB Output is correct
4 Correct 1037 ms 96580 KB Output is correct
5 Correct 4 ms 26456 KB Output is correct
6 Correct 3 ms 26584 KB Output is correct
7 Correct 1040 ms 91172 KB Output is correct
8 Correct 973 ms 91168 KB Output is correct
9 Correct 922 ms 91168 KB Output is correct
10 Correct 954 ms 91172 KB Output is correct
11 Correct 4 ms 26456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 26716 KB Output is correct
2 Correct 5 ms 26716 KB Output is correct
3 Correct 5 ms 26580 KB Output is correct
4 Correct 5 ms 26716 KB Output is correct
5 Correct 3 ms 26556 KB Output is correct
6 Correct 3 ms 26460 KB Output is correct
7 Correct 3 ms 26460 KB Output is correct
8 Correct 5 ms 26716 KB Output is correct
9 Correct 5 ms 26576 KB Output is correct
10 Correct 5 ms 26716 KB Output is correct
11 Correct 4 ms 26716 KB Output is correct
12 Correct 5 ms 26716 KB Output is correct
13 Correct 4 ms 26460 KB Output is correct
14 Correct 3 ms 26460 KB Output is correct
15 Correct 1008 ms 90780 KB Output is correct
16 Correct 997 ms 90908 KB Output is correct
17 Correct 965 ms 91008 KB Output is correct
18 Correct 931 ms 90980 KB Output is correct
19 Correct 912 ms 97944 KB Output is correct
20 Correct 978 ms 97428 KB Output is correct
21 Correct 899 ms 87056 KB Output is correct
22 Correct 946 ms 86920 KB Output is correct
23 Correct 871 ms 84784 KB Output is correct
24 Correct 903 ms 84540 KB Output is correct
25 Correct 815 ms 80788 KB Output is correct
26 Correct 881 ms 80928 KB Output is correct
27 Correct 790 ms 77736 KB Output is correct
28 Correct 776 ms 78420 KB Output is correct
29 Correct 499 ms 66596 KB Output is correct
30 Correct 515 ms 66700 KB Output is correct
31 Correct 1060 ms 96324 KB Output is correct
32 Correct 1087 ms 96416 KB Output is correct
33 Correct 1067 ms 96160 KB Output is correct
34 Correct 1037 ms 96580 KB Output is correct
35 Correct 4 ms 26456 KB Output is correct
36 Correct 3 ms 26584 KB Output is correct
37 Correct 1040 ms 91172 KB Output is correct
38 Correct 973 ms 91168 KB Output is correct
39 Correct 922 ms 91168 KB Output is correct
40 Correct 954 ms 91172 KB Output is correct
41 Correct 4 ms 26456 KB Output is correct
42 Correct 1129 ms 97892 KB Output is correct
43 Correct 1073 ms 96416 KB Output is correct
44 Correct 943 ms 90880 KB Output is correct
45 Correct 969 ms 90916 KB Output is correct
46 Correct 952 ms 90980 KB Output is correct
47 Correct 1047 ms 94532 KB Output is correct
48 Correct 959 ms 89384 KB Output is correct
49 Correct 971 ms 84768 KB Output is correct
50 Correct 964 ms 86812 KB Output is correct
51 Correct 518 ms 66596 KB Output is correct
52 Correct 555 ms 67628 KB Output is correct
53 Correct 405 ms 65308 KB Output is correct
54 Correct 400 ms 65956 KB Output is correct
55 Correct 973 ms 90972 KB Output is correct
56 Correct 950 ms 90988 KB Output is correct
57 Correct 414 ms 75552 KB Output is correct