답안 #152325

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
152325 2019-09-07T14:53:31 Z JovanK26 시간이 돈 (balkan11_timeismoney) C++14
45 / 100
9 ms 504 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];
}
int rez1=0;
int rez2=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))
        {
            rez1+=edg[i].t;
            rez2+=edg[i].c;
            mst.push_back(make_pair(edg[i].a,edg[i].b));
            unionn(edg[i].a,edg[i].b);
        }
    }
    cout << rez1<<' '<<rez2<<'\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:77: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 376 KB Output is correct
2 Correct 2 ms 256 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 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 6 ms 504 KB Output is correct
9 Correct 2 ms 308 KB Output is 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 2 ms 376 KB Output isn't correct
16 Incorrect 6 ms 376 KB Output isn't correct
17 Incorrect 9 ms 504 KB Output isn't correct
18 Incorrect 3 ms 376 KB Output isn't correct
19 Incorrect 7 ms 504 KB Output isn't correct
20 Incorrect 7 ms 504 KB Output isn't correct