답안 #152324

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
152324 2019-09-07T14:48:26 Z JovanK26 시간이 돈 (balkan11_timeismoney) C++14
40 / 100
7 ms 632 KB
#include <bits/stdc++.h>

using namespace std;
int prt[201];
int sz[201];
struct edge
{
    int a;
    int b;
    int t;
    int c;
};
bool cmp(edge i,edge j)
{
    return i.t<j.t;
}
void init()
{
    for(int i=0;i<201;i++)
    {
        prt[i]=i;
        sz[i]=1;
    }
}
int findd(int x)
{
    while(x!=prt[x])
    {
        prt[x]=prt[prt[x]];
        x=prt[x];
    }
    return x;
}
void unionn(int x,int y)
{
    x=findd(x);
    y=findd(y);
    if(sz[x]<sz[y])swap(x,y);
    prt[y]=x;
    sz[x]+=sz[y];
}
long long rez=0;
vector<pair<int,int> >mst;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,m;
    cin >> n >> m;
    vector<edge> edg(m);
    int a,b,t,c;
    for(int i=0;i<m;i++)
    {
        cin >> a >> b >> t >> c;
        edge temp;
        temp.a=a;
        temp.b=b;
        temp.t=t;
        temp.c=c;
        edg[i]=temp;
    }
    sort(edg.begin(),edg.end(),cmp);
    init();
    for(int i=0;i<m;i++)
    {
        if(findd(edg[i].a)!=findd(edg[i].b))
        {
            rez+=edg[i].t;
            mst.push_back(make_pair(edg[i].a,edg[i].b));
            unionn(edg[i].a,edg[i].b);
        }
    }
    cout << rez<<' '<<rez<<'\n';
    for(int i=0;i<mst.size();i++)
    {
        cout << mst[i].first << ' '<<mst[i].second<<'\n';
    }
    return 0;
}

Compilation message

timeismoney.cpp: In function 'int main()':
timeismoney.cpp:75:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<mst.size();i++)
                 ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 296 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 428 KB Output is correct
8 Correct 6 ms 632 KB Output is correct
9 Incorrect 2 ms 376 KB Output isn't correct
10 Incorrect 2 ms 376 KB Output isn't correct
11 Incorrect 2 ms 376 KB Output isn't correct
12 Incorrect 2 ms 376 KB Output isn't correct
13 Incorrect 2 ms 376 KB Output isn't correct
14 Incorrect 2 ms 376 KB Output isn't correct
15 Incorrect 3 ms 420 KB Output isn't correct
16 Incorrect 3 ms 376 KB Output isn't correct
17 Incorrect 3 ms 380 KB Output isn't correct
18 Incorrect 3 ms 376 KB Output isn't correct
19 Incorrect 7 ms 632 KB Output isn't correct
20 Incorrect 7 ms 632 KB Output isn't correct