Submission #1124729

#TimeUsernameProblemLanguageResultExecution timeMemory
1124729cpptowinAesthetic (NOI20_aesthetic)C++20
0 / 100
420 ms82864 KiB
#include <bits/stdc++.h> #define fo(i, d, c) for (int i = d; i <= c; i++) #define fod(i, c, d) for (int i = c; i >= d; i--) #define maxn 1000010 #define N 1010 #define fi first #define se second #define pb emplace_back #define en cout << "\n"; #define int long long #define inf (int)1e18 #define bitcount(x) __builtin_popcountll(x) #define pii pair<int, int> #define vii vector<pii> #define lb(x) x & -x #define bit(i, j) ((i >> j) & 1) #define offbit(i, j) (i ^ (1LL << j)) #define onbit(i, j) (i | (1LL << j)) #define vi vector<int> #define all(x) x.begin(), x.end() #define ss(x) (int)x.size() #define UNIQUE(v) v.erase(unique(all(v)),v.end()) template <typename T1, typename T2> bool minimize(T1 &a, T2 b) { if (a > b) { a = b; return true; } return false; } template <typename T1, typename T2> bool maximize(T1 &a, T2 b) { if (a < b) { a = b; return true; } return false; } using namespace std; const int nsqrt = 450; const int mod = 1e9 + 7; void add(int &x, int k) { x += k; x %= mod; if(x < 0) x += mod; } void del(int &x, int k) { x -= k; x %= mod; if(x < 0) x += mod; } int n,m,d[2][maxn]; array<int,3> edge[maxn]; vii ke[maxn],adj[maxn]; int p[maxn]; void dij(int inp,int d[],int n) { fo(i,1,n) d[i] = inf; d[inp] = 0; priority_queue<pii,vii,greater<pii>> q; q.push({0,inp}); while(q.size()) { auto [du,u] = q.top(); q.pop(); if(d[u] != du) continue; for(auto [v,w] : ke[u]) { if(d[v] > d[u] + w) { d[v] = d[u] + w; q.push({d[v],v}); } } } } int low[maxn],num[maxn],cnt; vi bridge; void dfs(int u,int par = 0) { low[u] = num[u] = ++cnt; for(auto [v,idx] : adj[u]) if(v != par) { if(!num[v]) { dfs(v,u); minimize(low[u],low[v]); if(low[v] == num[v]) bridge.pb(idx); } else minimize(low[u],num[v]); } } bool check(int val) { cnt = 0; bridge.clear(); fo(i,1,n) adj[i].clear(),low[i] = num[i] = 0; cnt = 0; fo(i,1,m) { auto [u,v,w] = edge[i]; if(min(d[0][u] + w + d[1][v],d[1][u] + w + d[0][v]) < val) { // cout << u << ' ' << v << ' ' << w << "\n"; // << d[0][u] + w + d[1][v] << ' ' << d[1][u] + w + d[0][v] << "\n"; adj[u].pb(v,i),adj[v].pb(u,i); } } dfs(1); for(int it : bridge) { auto [u,v,w] = edge[it]; // cout << u << ' ' << v << ' ' << w;en; if(min(d[0][u] + w + d[1][v],d[1][u] + w + d[0][v]) + p[it] >= val) return 1; } return 0; } main() { #define name "TASK" if (fopen(name ".inp", "r")) { freopen(name ".inp", "r", stdin); freopen(name ".out", "w", stdout); } ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; fo(i,1,m) { int u,v,w; cin >> u >> v >> w; ke[u].pb(v,w); ke[v].pb(u,w); edge[i] = {u,v,w}; } fod(i,m,1) p[i] = max(p[i + 1],edge[i + 1][2]); dij(1,d[0],n); dij(n,d[1],n); int l = d[0][n],r = d[0][n] + p[1] + 5,ans = l; // cout << check(8); while(l <= r) { int mid = l + r >> 1; if(check(mid)) ans = mid,l = mid + 1; else r = mid - 1; } cout << ans; }

Compilation message (stderr)

Aesthetic.cpp:124:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  124 | main()
      | ^~~~
Aesthetic.cpp: In function 'int main()':
Aesthetic.cpp:129:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  129 |         freopen(name ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Aesthetic.cpp:130:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  130 |         freopen(name ".out", "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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...