Submission #322168

# Submission time Handle Problem Language Result Execution time Memory
322168 2020-11-14T07:29:15 Z socho Sightseeing (NOI14_sightseeing) C++14
25 / 25
2750 ms 245900 KB
#include <bits/stdc++.h>
using namespace std;
void fast() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
}
void ran() {
	srand(chrono::steady_clock::now().time_since_epoch().count());
}
long long get_rand() {
	long long a = rand();
	long long b = rand();
	return a * (RAND_MAX + 1ll) + b;
}
void usaco() {
	freopen("problem.in", "r", stdin); 
	freopen("problem.out", "w", stdout);
}
template<typename T>
using min_pq = priority_queue<T, vector<T>, greater<T>>;
// #define endl '\n'
// #define double long double
#define int long long
// int MOD = 1000 * 1000 * 1000 + 7;
// int MOD = 998244353;

const int MXN = 500005;
int n, m, q;
vector<pair<int, pair<int, int>>> edges;

int score[MXN];
vector<pair<int, int>> adj[MXN];

int par[MXN];

int parent(int node) {
	if (par[node] == node) return node;
	return par[node] = parent(par[node]);
}

void connect(int a, int b) {
	a = parent(a); b = parent(b);
	par[a] = b;
}

void dfs(int node, int par, int curr) {
	score[node] = curr;
	for (auto x: adj[node]) {
		if (x.first == par) continue;
		dfs(x.first, node, min(curr, x.second));
	}
}

void fastscan(int &number) {
    bool negative = false;
    register int c;
    number = 0;
    c = getchar();
    if (c=='-') {
        negative = true;
        c = getchar();
    }
    for (; (c>47 && c<58); c=getchar())
        number = number *10 + c - 48;
    if (negative)
        number *= -1;
}

signed main() {
	
	for (int i=0; i<MXN; i++) par[i] = i;

	fastscan(n); fastscan(m); fastscan(q);
	
	for (int i=0; i<m; i++) {
		int a, b, w;
		fastscan(a); fastscan(b); fastscan(w);
		edges.push_back({w, {a, b}});
	}
	
	sort(edges.begin(), edges.end());
	reverse(edges.begin(), edges.end());
	
	for (auto x: edges) {
		int w = x.first, a = x.second.first, b = x.second.second;
		if (parent(a) == parent(b)) continue;
		adj[a].push_back({b, w});
		adj[b].push_back({a, w});
		connect(a, b);
	}
	
	dfs(1, -1, INT_MAX);
	
	for (int i=0; i<q; i++) {
		int x;
		fastscan(x);
		cout << score[x] << endl;
	}
	
}

Compilation message

sightseeing.cpp: In function 'void usaco()':
sightseeing.cpp:15:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   15 |  freopen("problem.in", "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
sightseeing.cpp:16:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   16 |  freopen("problem.out", "w", stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 15980 KB Output is correct
2 Correct 10 ms 15980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 16108 KB Output is correct
2 Correct 10 ms 15980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 19296 KB Output is correct
2 Correct 42 ms 18920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1966 ms 114544 KB Output is correct
2 Correct 2750 ms 245900 KB Output is correct