Submission #895571

#TimeUsernameProblemLanguageResultExecution timeMemory
895571vjudge1Evacuation plan (IZhO18_plan)C++17
0 / 100
146 ms28500 KiB
//#pragma comment(linker, "/stack:200000000") //#pragma GCC optimize("Ofast") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <map> #include <set> #include <list> #include <cmath> #include <ctime> #include <deque> #include <queue> #include <stack> #include <string> #include <bitset> #include <cstdio> #include <limits> #include <vector> #include <climits> #include <cstring> #include <cstdlib> #include <fstream> #include <numeric> #include <sstream> #include <cassert> #include <iomanip> #include <iostream> #include <algorithm> #include <stdio.h> #include <fstream> #include <unordered_map> using namespace std; typedef long long ll; typedef long double ld; #define all(x) x.begin(),x.end() #define pb push_back #define ent "\n" #define int long long const int maxn = (int)2e5 + 13; const ll inf = (long long)1e18 + 20; const int mod = (int)1e9 + 7; int n,m,k,q; vector<pair<int,int>>g[maxn]; int a[maxn],b[maxn],c[maxn]; int dst[maxn]; int pr[maxn]; int sz[maxn]; int get(int x){ if(x == pr[x])return x; return pr[x] = get(pr[x]); } void unite(int x,int y){ x = get(x),y= get(y); if(x == y)return ; if(sz[x] > sz[y])swap(x,y); pr[x] = y; sz[y] += sz[x]; } void solve(){ cin >> n >> m ; for(int i = 1 ; i <= m ; i++){ int x,y,w;cin >> x >> y >> w; g[x].pb({y,w}); g[y].pb({x,w}); a[i] = x,b[i] = y,c[i] = w; } cin >> k; set<pair<int,int>>s; for(int i = 1 ; i <= n ; i ++){ dst[i] = inf; pr[i] = i; } for(int i = 1 ; i <= k ; i ++){ int x;cin >> x; s.insert({0,x}); dst[x] = 0; } while(s.size()){ pair<int,int>v = *s.begin(); s.erase(v); for(auto to : g[v.second]){ int val = dst[v.second] + to.second; if(dst[to.first] > val){ dst[to.first] = val; s.insert({val,to.first}); } } } cin >> q; for(int i = 1 ; i <= q ; i ++){ int x,y;cin >> x >> y; int l = 0,r = 1000,ans = 0; while(l <= r){ int mid = (l + r) >> 1; for(int j = 1 ; j <= n ; j++){ pr[j] = j; sz[j] = 1; } for(int j = 1 ; j <= m ; j ++){ if(dst[a[j]] >= mid && dst[b[j]] >= mid){ unite(a[j],b[j]); } } if(get(x)!=get(y))r = mid - 1; else l = mid + 1,ans = mid; } cout << ans << ent; } } signed main(){ // freopen ("hps.in", "r", stdin); // freopen ("hps.out", "w", stdout); ios_base::sync_with_stdio(0); cin.tie(0); int t = 1; //cin >> t; int test = 0; while(t --){ // cout << "Case " << ++test << ": "; solve(); } return 0; }

Compilation message (stderr)

plan.cpp: In function 'int main()':
plan.cpp:124:6: warning: unused variable 'test' [-Wunused-variable]
  124 |  int test = 0;
      |      ^~~~
#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...