제출 #893440

#제출 시각아이디문제언어결과실행 시간메모리
893440vjudge1Evacuation plan (IZhO18_plan)C++17
41 / 100
4038 ms55188 KiB
#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;
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
 
// #pragma GCC optimize("Ofast,unroll-loops,fast-math")
// #pragma GCC target("popcnt")


typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pll;
 
#define sz size()
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define pb push_back

const int mod = ll(1e9)+7; //(b + (a%b)) % b (to mod -1%(10^9+7) correctly in c++ its -1 but its suppose to be 10^9+6
const ll MOD = 998244353;  // (a%mod)*(binpow(b,mod-2,mod) = (a/b)%mod
const int N = ll(5e5)+100;
const long long inf = 2e18;
const long double eps = 1e-15L;
 
ll lcm(ll a, ll b) { return (a / __gcd(a,b))*b; }

ll binpow(ll a, ll b, ll m) { ll res=1; a %= m; while(b>0){ if(b&1)res=(res * a) % m; a=(a * a) % m; b/=2; } return res%m;}


void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }

int n, m, k, q, qu[N], qv[N], qw[N], par[N], qs[N], qt[N], siz[N], dis[N], ok[N];
vector<pair<int, int> > g[N];
vector<int> nuc;

int findpar(int v) {
	if(v == par[v]) return v;
	return par[v] = findpar(par[v]);
}

void combine(int a, int b) {
	a = findpar(a);
	b = findpar(b);
	if(a != b) {
		if(siz[a] < siz[b]) swap(a, b);
		par[b] = a;
		siz[a] += siz[b];
	}
}

void Baizho() {	
	cin>>n>>m;
	for(int i = 1; i <= m; i ++) {
		cin>>qu[i]>>qv[i]>>qw[i];
		g[qu[i]].pb({qv[i], qw[i]});
		g[qv[i]].pb({qu[i], qw[i]});
	}
	for(int i = 1; i <= n; i ++) {
		dis[i] = 2e9;
	}
	cin>>k;
	set<pair<int, int> > st;
	for(int i = 1; i <= k; i ++) {
		int x; cin>>x;
		nuc.pb(x);
		dis[x] = 0;
		st.insert({dis[x], x});
	}
	while(!st.empty()) {
		int v = (*st.begin()).ss;
		st.erase(st.begin());
		for(auto to : g[v]) {
			if(dis[to.ff] > dis[v] + to.ss) {
				if(dis[to.ff] != 2e9) st.erase({dis[to.ff], to.ff});
				dis[to.ff] = dis[v] + to.ss;
				st.insert({dis[to.ff], to.ff});
			}
		}
	}
//	for(int i = 1; i <= n; i ++) cout<<dis[i]<<" ";
//	cout<<"\n";
	cin>>q;
	for(int i = 1; i <= q; i ++) {
		cin>>qs[i]>>qt[i];
		int l = 0, r = 2e9;
		while(l <= r) {
			int mid = (l + r) / 2;
			for(int j = 0; j <= n; j ++) {
				par[j] = j;
				siz[j] = 1;
				ok[j] = 0;
			}
			for(int j = 1; j <= n; j ++) {
				if(dis[j] >= mid) ok[j] = 1;
			}
			for(int j = 1; j <= m; j ++) {
				if(ok[qu[j]] && ok[qv[j]]) combine(qu[j], qv[j]);
			}
			if(findpar(qs[i]) == findpar(qt[i])) l = mid + 1;
			else r = mid - 1;
		}
		cout<<l - 1<<"\n";
	}
}
 
signed main() {		
 
    ios_base::sync_with_stdio(false);   
    cin.tie(0);cout.tie(0); 
//   	precalc();
   	
    int ttt = 1;
//    cin>>ttt;

    for(int i=1; i<=ttt; i++) {Baizho(); }
}

컴파일 시 표준 에러 (stderr) 메시지

plan.cpp: In function 'void Freopen(std::string)':
plan.cpp:35:34: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 | void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }
      |                           ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
plan.cpp:35:76: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 | void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }
      |                                                                     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...