Submission #77526


Source Code Expand

#include <vector>
#include <algorithm>
#include "grader.h"

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define fi first
#define se second
#define mp make_pair
#define pb push_back

typedef pair<int, int> P;
typedef long long ll;

vector<P> g[100010];

struct unionfind{
    int par[100010], rank[100010];

    void init(){
	rep(i, 100000){
	    par[i] = i;
	    rank[i] = 0;
	}
    }

    inline int find(int x){
	if(par[x] == x) return x;
	return par[x] = find(par[x]);
    }

    inline void unite(int x, int y){
	x = find(x), y = find(y);
	if(x == y) return ;
	if(rank[x] < rank[y]) par[x] = y;
	else {
	    par[y] = x;
	    rank[x] += (rank[x] == rank[y]);
	}
    }

    inline bool same(int a, int b){ return find(a) == find(b); }
}uf;

struct edge{
    int f, t, c;
    edge(int f, int t, int c) : f(f), t(t), c(c){}
    edge(){}
};

bool cmp(edge a, edge b){
    return a.c < b.c;
}

vector<edge> eg;

void construct(int n, int m, int e[][3]){
    rep(i, m) g[e[i][1]].pb(mp(e[i][0], e[i][2]));
    rep(i, n - 1){
	int v = i + 1;
	rep(j, g[v].size()){
	    eg.pb(edge(i, g[v][i].fi, g[v][i].se));
	}
	sort(edge.begin(), edge.end());
	uf.init();
	int sz = v + 1;
	ll ans = 0;
	rep(j, edge.size()){
	    edge crt = edge[i];
	    if(uf.same(crt.f, crt.t)) continue;
	    uf.unite(crt.f, crt.t);
	    --sz;
	    ans += crt.c;
	}
	if(sz != 0){
	    answer(-1);
	}else{
	    answer(ans);
	}
    }
}

Submission Info

Submission Time
Task A - かえってきたどうぶつたち と しんりんのさいせい (Return of Animals and Regeneration of Forests)
User satashun
Language IOI-Style C++ (GCC 5.4.1)
Score 0
Code Size 1509 Byte
Status CE

Compile Error

./Main.cpp: In function ‘void construct(int, int, int (*)[3])’:
./Main.cpp:65: error: expected primary-expression before ‘.’ token
./Main.cpp:65: error: expected primary-expression before ‘.’ token
./Main.cpp:69: error: expected primary-expression before ‘.’ token
./Main.cpp:70: error: expected primary-expression before ‘[’ token