제출 #22815

#제출 시각아이디문제언어결과실행 시간메모리
22815버거킹 송죽SK점 우수고객 (#40)Logistical Metropolis (KRIII5_LM)C++14
2 / 7
89 ms4648 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define x first
#define y second

int n, m;

vector<pp> edge[100010];

vector<pair<int,pp>> E;

int par[1010];
int R(int x){ return (par[x]==x)?x:(par[x]=R(par[x])); }
bool unite(int a, int b){
	a=R(a); b=R(b);
	if(a==b) return 0;
	par[a]=b; return 1;
}

int main()
{
	read(n, m);
	n=min(n, 1000);
	m=min(m, 3000);
	for(;m--;){
		int x, y, c;
		read(x, y, c);
		E.emplace_back(c, pp{x, y});
		edge[x].emplace_back(y, c);
		edge[y].emplace_back(x, c);
	}
	sort(all(E));
	for(int i=1; i<=n; ++i){
		for(int j=1; j<=n; ++j) par[j]=j;
		int ans=0;
		for(auto tmp:edge[i]){
			int j,k; tie(j,k)=tmp;
			unite(i, j);
			ans += k;
		}
		for(auto tmp:E){
			int c=tmp.x, x=tmp.y.x, y=tmp.y.y;
			if(unite(x, y)) ans+=c;
		}
		printf("%d\n", ans);
	}
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

LM.cpp: In function 'void read(int&)':
LM.cpp:6:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 void read(int& x){ scanf("%d",&x); }
                                  ^
LM.cpp: In function 'void read(ll&)':
LM.cpp:7:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 void read(ll& x){ scanf("%lld",&x); }
                                   ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...