Submission #596851

# Submission time Handle Problem Language Result Execution time Memory
596851 2022-07-15T07:37:53 Z 조영욱(#8449) Reconstruction Project (JOI22_reconstruction) C++17
7 / 100
5000 ms 3156 KB
#include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> P;
typedef pair<int,P> iP;
iP edge[100000];
iP arr[100000];

int p[500];

int find(int a) {
    return p[a]<0?a:p[a]=find(p[a]);
}

void merge(int a,int b) {
    a=find(a);
    b=find(b);
    if (a==b) {
        return;
    }
    p[b]=a;
}

int main(void) {
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i=0;i<m;i++){
        int u,v,w;
        scanf("%d %d %d",&u,&v,&w);
        u--;
        v--;
        edge[i]=iP(w,P(u,v));
    }
    int q;
    scanf("%d",&q);
    for(int i=0;i<q;i++) {
        int x;
        scanf("%d",&x);
        for(int j=0;j<m;j++) {
            arr[j]=edge[j];
            arr[j].first=abs(edge[j].first-x);
        }
        sort(arr,arr+m);
        memset(p,-1,sizeof(p));
        long long ret=0;
        for(int j=0;j<m;j++) {
            if (find(arr[j].second.first)!=find(arr[j].second.second)) {
                merge(arr[j].second.first,arr[j].second.second);
                ret+=arr[j].first;
            }
        }
        printf("%lld\n",ret);
    }
}

Compilation message

reconstruction.cpp: In function 'int main()':
reconstruction.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |     scanf("%d %d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~
reconstruction.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         scanf("%d %d %d",&u,&v,&w);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
reconstruction.cpp:35:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |     scanf("%d",&q);
      |     ~~~~~^~~~~~~~~
reconstruction.cpp:38:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         scanf("%d",&x);
      |         ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 244 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 244 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 129 ms 3020 KB Output is correct
21 Correct 129 ms 3020 KB Output is correct
22 Correct 115 ms 3056 KB Output is correct
23 Correct 124 ms 3008 KB Output is correct
24 Correct 110 ms 3060 KB Output is correct
25 Correct 116 ms 3020 KB Output is correct
26 Correct 117 ms 3024 KB Output is correct
27 Correct 122 ms 3052 KB Output is correct
28 Correct 135 ms 3052 KB Output is correct
29 Correct 148 ms 2996 KB Output is correct
30 Correct 121 ms 3020 KB Output is correct
31 Correct 123 ms 3036 KB Output is correct
32 Correct 111 ms 3156 KB Output is correct
33 Correct 108 ms 3064 KB Output is correct
34 Correct 134 ms 3048 KB Output is correct
35 Correct 124 ms 3064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Execution timed out 5026 ms 2736 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 244 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Execution timed out 5038 ms 1768 KB Time limit exceeded
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 244 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 129 ms 3020 KB Output is correct
21 Correct 129 ms 3020 KB Output is correct
22 Correct 115 ms 3056 KB Output is correct
23 Correct 124 ms 3008 KB Output is correct
24 Correct 110 ms 3060 KB Output is correct
25 Correct 116 ms 3020 KB Output is correct
26 Correct 117 ms 3024 KB Output is correct
27 Correct 122 ms 3052 KB Output is correct
28 Correct 135 ms 3052 KB Output is correct
29 Correct 148 ms 2996 KB Output is correct
30 Correct 121 ms 3020 KB Output is correct
31 Correct 123 ms 3036 KB Output is correct
32 Correct 111 ms 3156 KB Output is correct
33 Correct 108 ms 3064 KB Output is correct
34 Correct 134 ms 3048 KB Output is correct
35 Correct 124 ms 3064 KB Output is correct
36 Execution timed out 5002 ms 3076 KB Time limit exceeded
37 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 244 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 129 ms 3020 KB Output is correct
21 Correct 129 ms 3020 KB Output is correct
22 Correct 115 ms 3056 KB Output is correct
23 Correct 124 ms 3008 KB Output is correct
24 Correct 110 ms 3060 KB Output is correct
25 Correct 116 ms 3020 KB Output is correct
26 Correct 117 ms 3024 KB Output is correct
27 Correct 122 ms 3052 KB Output is correct
28 Correct 135 ms 3052 KB Output is correct
29 Correct 148 ms 2996 KB Output is correct
30 Correct 121 ms 3020 KB Output is correct
31 Correct 123 ms 3036 KB Output is correct
32 Correct 111 ms 3156 KB Output is correct
33 Correct 108 ms 3064 KB Output is correct
34 Correct 134 ms 3048 KB Output is correct
35 Correct 124 ms 3064 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Execution timed out 5026 ms 2736 KB Time limit exceeded
40 Halted 0 ms 0 KB -