Contest Duration: ~ (local time) (90 minutes) Back to Home

Submission #242710

Source Code Expand

Copy
```#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <climits>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF (LLONG_MAX/2)
#define EPS 1e-10

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

ll N, M;
ll c,a,b,r;
ll G[100005][100005];
ll mincost[100020];
bool used[100005];

ll prim(){
rep(i, N){
mincost[i] = INF;
used[i] = false;
}

mincost[0] = 0;
ll res = 0;

while(true){
int v = -1;
rep(u, N)
if(!used[u] && (v == -1 || mincost[u] < mincost[v])) v = u;

if(v == -1) break;
used[v] = true;
res += mincost[v];

rep(u, N){
mincost[u] = min(mincost[u], G[v][u]);
}
}
return res;

}

int main(){
scanf("%lld%lld", &N, &M);
rep(i, N+1) rep(j, N+1) G[i][j] = INF;
rep(i, N){
scanf("%lld", &c);
G[N][i] = G[i][N] = c;
}
rep(i, M){
scanf("%lld%lld%lld", &a, &b, &r); a--; b--;
G[a][b] = G[b][a] = r;
}
N++;
printf("%lld\n", prim());
return 0;
}
```

#### Submission Info

Submission Time 2014-09-28 02:08:38+0900 C - 高橋君と国家 raven38 C++ (G++ 4.6.4) 0 1598 Byte CE

#### Compile Error

```./Main.cpp: In function ‘int main()’:
./Main.cpp:69:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
./Main.cpp:72:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
./Main.cpp:76:38: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
/tmp/cccIN9gA.o: In function `prim()':
Main.cpp:(.text+0x3): relocation truncated to fit: R_X86_64_PC32 against symbol `N' defined in .bss section in /tmp/cccIN9gA.o
/tmp/cccIN9gA.o: In function `main':
Main.cpp:(.text.startup+0x9): relocation truncated to fit: R_X86_64_32 against symbol `M' defined in .bss section in /tmp/cccIN9gA.o
Main.cpp:(.text.startup+0xe): relocation truncated to fit: R_X86_64_32 against symbol `N' defined in .bss section in /tmp/cccIN9gA.o
Main.cpp:(.text.startup+0x1f): relocation truncated to fit: R_X86_64_...```