# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
556250 | 600Mihnea | Reconstruction Project (JOI22_reconstruction) | C++17 | 5051 ms | 4748 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
bool home = 1;
using namespace std;
typedef long long ll;
int wglob;
struct Edge{
int a;
int b;
int w;
};
bool operator < (Edge a,Edge b) {
return abs(wglob-a.w)<abs(wglob-b.w);
}
const int N=500+7;
const int M=100000+7;
const int Q=1000000+7;
int n;
int m;
int q;
int t[N];
Edge edges[M];
int root(int a) {
if (t[a]==a) return a;
return t[a]=root(t[a]);
}
void join(int a,int b) {
t[root(a)]=root(b);
}
signed main() {
#ifdef ONLINE_JUDGE
home = 0;
#endif
home=0;
if (home) {
freopen("I_am_iron_man", "r", stdin);
}
else {
ios::sync_with_stdio(0); cin.tie(0);
}
cin>>n>>m;
for (int i=1;i<=m;i++) {
cin>>edges[i].a>>edges[i].b>>edges[i].w;
}
cin>>q;
for (int iq=1;iq<=q;iq++) {
int w;
cin>>w;
wglob=w;
sort(edges+1,edges+m+1);
for (int i=1;i<=n;i++) t[i]=i;
ll sol=0;
for (int i=1;i<=m;i++) {
int a=edges[i].a;
int b=edges[i].b;
int cost=abs(wglob-edges[i].w);
if (root(a)!=root(b)) {
join(a,b);
sol+=cost;
}
}
cout<<sol<<"\n";
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |