Submission #432379

# Submission time Handle Problem Language Result Execution time Memory
432379 2021-06-18T08:47:34 Z amunduzbaev Islands (IOI08_islands) C++14
33 / 100
1012 ms 131076 KB
/* made by amunduzbaev */
 
#include "bits/stdc++.h"
 
using namespace std;
 
//~ #include <ext/pb_ds/assoc_container.hpp>
//~ #include <ext/pb_ds/tree_policy.hpp>
//~ using namespace __gnu_pbds;
//~ template<class T> using oset = tree<T, 
//~ null_type, less_equal<T>, rb_tree_tag, 
//~ tree_order_statistics_node_update>;
 
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define NeedForSpeed ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define vv vector
#define mem(arr, v) memset(arr, v, sizeof arr)
#define int long long
#define degub(x) cout<<#x<<" : "<<x<<"\n"
#define GG cout<<"here"<<endl;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii; 
typedef vector<int> vii;
typedef vector<pii> vpii;
template<class T> bool umin(T& a, const T& b) { return a > b ? a = b, true : false; }
template<class T> bool umax(T& a, const T& b) { return a < b ? a = b, true : false; }
template<int sz> using tut = array<int, sz>;
void usaco(string s) { freopen((s+".in").c_str(),"r",stdin);  
	freopen((s+".out").c_str(),"w",stdout); NeedForSpeed }
 
const int N = 1e6+5;
const int mod = 1e9+7;
const ll inf = 1e18;
const ld Pi = acos(-1);
 
#define MULTI 0
int n, m, k, t, q, ans, res, a[N];
int par[N], sz[N], used[N];
vpii edges[N];

int f(int x) { return (par[x] == x ? x : par[x] = f(par[x])); }
void merge(int a, int b, int c){
	if(f(a) == f(b)) return;
	edges[a].pb({b, c}), edges[b].pb({a, c});
	a = f(a), b = f(b);
	if(sz[b] > sz[a]) swap(a, b);
	sz[a] += sz[b], par[b] = a;
}

vii tt;
pii dfs(int u){
	used[u] = 1;
	pii mx = {0, u};
	tt.pb(u);
	for(auto x : edges[u]){
		if(used[x.ff]) continue;
		pii tt = dfs(x.ff);
		if(umax(mx.ff, tt.ff + x.ss)) mx.ss = tt.ss;
	} return mx;
}

void solve(int t_case){
	cin>>n;
	vv<tut<3>> ee;
	for(int i=1;i<=n;i++){
		int a, b; cin>>a>>b;
		ee.pb({b, a, i});
	} 
	sort(rall(ee));
	//~ for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n;i++) par[i] = i;
	for(auto x : ee){
		int a = x[1], b = x[2], c = x[0];
		merge(a, b, c);
	}
	
	//~ for(int i=1;i<=n;i++){
		//~ for(auto x : edges[i]) cout<<i<<" "<<x.ff<<" "<<x.ss<<"\n";
	//~ }
	
	for(int i=1;i<=n;i++){
		if(used[i]) continue;
		tt.clear();
		int a = dfs(i).ss;
		for(auto x : tt) used[x] = 0;
		res += dfs(a).ff;
	}
	
	cout<<res<<"\n";
}

signed main(){
	NeedForSpeed
	if(MULTI){
		int t; cin>>t;
		for(int t_case = 1; t_case <= t; t_case++) solve(t_case);
	} else solve(1);
	return 0;
}

Compilation message

islands.cpp: In function 'void usaco(std::string)':
islands.cpp:38:31: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 | void usaco(string s) { freopen((s+".in").c_str(),"r",stdin);
      |                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
islands.cpp:39:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |  freopen((s+".out").c_str(),"w",stdout); NeedForSpeed }
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23756 KB Output is correct
2 Correct 14 ms 23756 KB Output is correct
3 Correct 16 ms 23884 KB Output is correct
4 Correct 14 ms 23768 KB Output is correct
5 Correct 14 ms 23752 KB Output is correct
6 Correct 15 ms 23756 KB Output is correct
7 Correct 14 ms 23756 KB Output is correct
8 Incorrect 14 ms 23828 KB Output isn't correct
9 Correct 21 ms 23800 KB Output is correct
10 Correct 14 ms 23840 KB Output is correct
11 Correct 14 ms 23844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23936 KB Output is correct
2 Correct 14 ms 23884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 23884 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 25580 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 59 ms 32480 KB Output is correct
2 Incorrect 102 ms 36052 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 194 ms 52144 KB Output is correct
2 Correct 172 ms 54820 KB Output is correct
3 Incorrect 334 ms 73952 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 484 ms 65564 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 767 ms 131076 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1012 ms 131076 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -