# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
31759 | simotion | 시간이 돈 (balkan11_timeismoney) | C++14 | 6 ms | 2488 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define CNT 202
#define fi first
#define se second
using namespace std;
struct pd {
int p1,p2,t,c;
pd() {}
pd(int p1,int p2,int t,int c):p1(p1),p2(p2),t(t),c(c) {}
bool operator< (pd o) const {
return (t*c)<(o.t*o.c);
}
};
int n,m;
int t1,t2,t3,t4,lines;
int height[CNT],root[CNT];
int t_sum,c_sum;
vector<pd > kr;
vector<int> ans;
int find(int p) {
if(root[p]==p) return p;
else return root[p]=find(root[p]);
}
void uni(int a,int b) {
a=find(a),b=find(b);
if(height[a]>height[b]) swap(a,b);
if(height[a]==height[b]) height[b]++;
root[a]=b;
}
int main() {
scanf("%d %d",&n,&m);
for(int i=0;i<n;i++)
height[i]=1,root[i]=i;
for(int i=0;i<m;i++) {
scanf("%d %d %d %d",&t1,&t2,&t3,&t4);
kr.push_back(pd(t1,t2,t3,t4));
}
sort(kr.begin(),kr.end());
for(int i=0;lines<n-1;i++) {
auto now=kr[i];
if(find(now.p1)!=find(now.p2)) {
uni(now.p1,now.p2);
lines++;
ans.push_back(i);
t_sum+=now.t,c_sum+=now.c;
}
}
printf("%d %d\n",t_sum,c_sum);
for(auto i=ans.begin();i!=ans.end();i++)
printf("%d %d\n",kr[*i].p1,kr[*i].p2);
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |