Submission #22815

# Submission time Handle Problem Language Result Execution time Memory
22815 2017-04-30T07:39:12 Z 버거킹 송죽SK점 우수고객(#1039, Namnamseo, khsoo01) Logistical Metropolis (KRIII5_LM) C++14
2 / 7
89 ms 4648 KB
#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;
}

Compilation message

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 time Memory Grader output
1 Correct 83 ms 4520 KB Output is correct
2 Correct 83 ms 4520 KB Output is correct
3 Correct 73 ms 4524 KB Output is correct
4 Correct 79 ms 4520 KB Output is correct
5 Correct 83 ms 4520 KB Output is correct
6 Correct 83 ms 4520 KB Output is correct
7 Correct 73 ms 4520 KB Output is correct
8 Correct 86 ms 4520 KB Output is correct
9 Correct 86 ms 4520 KB Output is correct
10 Correct 79 ms 4520 KB Output is correct
11 Correct 76 ms 4520 KB Output is correct
12 Correct 83 ms 4520 KB Output is correct
13 Correct 89 ms 4520 KB Output is correct
14 Correct 89 ms 4520 KB Output is correct
15 Correct 79 ms 4520 KB Output is correct
16 Correct 39 ms 4520 KB Output is correct
17 Correct 43 ms 4520 KB Output is correct
18 Correct 46 ms 4520 KB Output is correct
19 Correct 43 ms 4520 KB Output is correct
20 Correct 43 ms 4520 KB Output is correct
21 Correct 63 ms 4520 KB Output is correct
22 Correct 46 ms 4520 KB Output is correct
23 Correct 46 ms 4520 KB Output is correct
24 Correct 43 ms 4520 KB Output is correct
25 Correct 0 ms 4372 KB Output is correct
26 Correct 0 ms 4372 KB Output is correct
27 Correct 0 ms 4372 KB Output is correct
28 Correct 16 ms 4372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 4648 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -