Submission #417893

# Submission time Handle Problem Language Result Execution time Memory
417893 2021-06-04T13:13:56 Z 반딧불(#7603) Rooted MST (innopolis2021_final_E) C++17
10 / 100
4000 ms 34596 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

struct Edge{
    int x, y; ll z;
    Edge(){}
    Edge(int x, int y, ll z): x(x), y(y), z(z){}

    bool operator<(const Edge &r)const{
        return z > r.z;
    }
};

struct DisjointSet{
    int n;
    int par[300002];

    void init(int _n){
        n = _n;
        for(int i=0; i<=n; i++) par[i] = i;
    }

    int find(int x){
        if(x == par[x]) return x;
        return par[x] = find(par[x]);
    }

    void merge(int x, int y){
        x = find(x), y = find(y);
        par[x] = y;
    }
};

int n, m, q;
ll arr[300002];
Edge link[300002];

void printMST(){
    priority_queue<Edge> pq;
    for(int i=1; i<=m; i++) pq.push(link[i]);
    for(int i=1; i<=n; i++){
        pq.push(Edge(0, i, arr[i]));
    }

    DisjointSet dsu;
    dsu.init(n);

    ll ans = 0;
    while(!pq.empty()){
        Edge tmp = pq.top(); pq.pop();
        int x = tmp.x, y = tmp.y;
        if(dsu.find(x) == dsu.find(y)) continue;
        dsu.merge(x, y);
        ans += tmp.z;
    }
    printf("%lld\n", ans);
}

int main(){
    scanf("%d %d", &n, &m);
    for(int i=1; i<=n; i++){
        scanf("%lld", &arr[i]);
    }
    for(int i=1; i<=m; i++){
        scanf("%d %d %lld", &link[i].x, &link[i].y, &link[i].z);
    }

    scanf("%d", &q);
    while(q--){
        int i; ll w;
        scanf("%d %lld", &i, &w);
        arr[i] = w;

        printMST();
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:63:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:65:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |         scanf("%lld", &arr[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:68:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |         scanf("%d %d %lld", &link[i].x, &link[i].y, &link[i].z);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:71:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |     scanf("%d", &q);
      |     ~~~~~^~~~~~~~~~
Main.cpp:74:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |         scanf("%d %lld", &i, &w);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1484 KB Output is correct
2 Correct 2 ms 1356 KB Output is correct
3 Correct 3 ms 1484 KB Output is correct
4 Correct 218 ms 1560 KB Output is correct
5 Correct 996 ms 1744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 4049 ms 34596 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4059 ms 19408 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4062 ms 17024 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4062 ms 17024 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4066 ms 34536 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1484 KB Output is correct
2 Correct 2 ms 1356 KB Output is correct
3 Correct 3 ms 1484 KB Output is correct
4 Correct 218 ms 1560 KB Output is correct
5 Correct 996 ms 1744 KB Output is correct
6 Execution timed out 4083 ms 9492 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1484 KB Output is correct
2 Correct 2 ms 1356 KB Output is correct
3 Correct 3 ms 1484 KB Output is correct
4 Correct 218 ms 1560 KB Output is correct
5 Correct 996 ms 1744 KB Output is correct
6 Execution timed out 4049 ms 34596 KB Time limit exceeded
7 Halted 0 ms 0 KB -