답안 #417712

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
417712 2021-06-04T07:44:10 Z 조영욱(#7641) Rooted MST (innopolis2021_final_E) C++17
10 / 100
4000 ms 23692 KB
#include <bits/stdc++.h>
using namespace std;

int n,m;
int arr[300001];
typedef pair<int,int> P;
typedef pair<int,P> iP;

int p[300001];

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;
}

long long mst(vector<iP> edge) {
    for(int i=1;i<=n;i++) {
        edge.push_back(iP(arr[i],P(0,i)));
    }
    sort(edge.begin(),edge.end());
    for(int i=0;i<=n;i++) {
        p[i]=-1;
    }
    long long ret=0;
    for(int i=0;i<edge.size();i++) {
        int u=edge[i].second.first;
        int v=edge[i].second.second;
        int w=edge[i].first;
        if (find(u)!=find(v)) {
            merge(u,v);
            ret+=w;
        }
    }
    return ret;
}

int main(void) {
    vector<iP> edge;
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++) {
        scanf("%d",arr+i);
    }
    for(int i=0;i<m;i++) {
        int u,v,w;
        scanf("%d %d %d",&u,&v,&w);
        edge.push_back(iP(w,P(u,v)));
    }
    int q;
    scanf("%d",&q);
    for(int i=0;i<q;i++) {
        int ind,w;
        scanf("%d %d",&ind,&w);
        arr[ind]=w;
        printf("%lld\n",mst(edge));
    }
}

Compilation message

Main.cpp: In function 'long long int mst(std::vector<std::pair<int, std::pair<int, int> > >)':
Main.cpp:33:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     for(int i=0;i<edge.size();i++) {
      |                 ~^~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:47:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |     scanf("%d %d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~
Main.cpp:49:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |         scanf("%d",arr+i);
      |         ~~~~~^~~~~~~~~~~~
Main.cpp:53:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |         scanf("%d %d %d",&u,&v,&w);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
Main.cpp:57:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |     scanf("%d",&q);
      |     ~~~~~^~~~~~~~~
Main.cpp:60:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |         scanf("%d %d",&ind,&w);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 2 ms 204 KB Output is correct
4 Correct 176 ms 360 KB Output is correct
5 Correct 772 ms 564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4054 ms 16692 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4078 ms 10928 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4072 ms 12364 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4072 ms 12364 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4091 ms 23692 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 2 ms 204 KB Output is correct
4 Correct 176 ms 360 KB Output is correct
5 Correct 772 ms 564 KB Output is correct
6 Execution timed out 4091 ms 6344 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 2 ms 204 KB Output is correct
4 Correct 176 ms 360 KB Output is correct
5 Correct 772 ms 564 KB Output is correct
6 Execution timed out 4054 ms 16692 KB Time limit exceeded
7 Halted 0 ms 0 KB -