id
int64
251M
307M
language
stringclasses
12 values
verdict
stringclasses
290 values
source
stringlengths
0
62.5k
problem_id
stringclasses
500 values
type
stringclasses
2 values
276,274,261
C++14 (GCC 6-32)
WRONG_ANSWER on test 8
#include <iostream> #include <stdio.h> #include <vector> #include <queue> using namespace std; const int maxn = 1e5 + 5, ninf = 0x80000000; int T, n, m, t0, t1, t2, et[maxn]; struct Edge{ int to, l1, l2; Edge(int to, int l1, int l2){ this->to = to; this->l1 = l1; this->l2 = l2; } }; struct Node{ int idx, t; inline bool operator < (const Node &other) const{ return t < other.t; } Node(int idx, int t){ this->idx = idx; this->t = t; } }; vector<Edge> to[maxn]; inline void clear_vec(vector<Edge> &vec){ vector<Edge> empty; swap(empty, vec); } inline void solve(){ cin >> n >> m; cin >> t0 >> t1 >> t2; for(int i = 1; i <= n; ++i) clear_vec(to[i]); for(int i = 1; i <= n; ++i) et[i] = ninf; for(int i = 0; i < m; ++i){ int u, v, l1, l2; cin >> u >> v >> l1 >> l2; to[u].push_back(Edge(v, l1, l2)); to[v].push_back(Edge(u, l1, l2)); } priority_queue<Node> pq; pq.push(Node(n, t0)); int rt; while(!pq.empty()){ Node top = pq.top(); pq.pop(); // cerr << "VIS: " << top.idx << ' ' << top.t << endl; rt = top.t; // cerr << et[top.idx] << endl; if(et[top.idx] != ninf) continue; et[top.idx] = rt; for(auto e: to[top.idx]) if(et[e.to] == ninf){ if(rt <= t1 || rt - e.l1 >= t2) pq.push(Node(e.to, rt - e.l1)); else pq.push(Node(e.to, max(rt - e.l2, t1 - e.l1))); } } // for(int i = 1; i <= n; ++i) // cerr << et[i] << " "; // cerr << endl; cout << max(-1, et[1]) << endl; } int main(){ cin.tie(0)->sync_with_stdio(false); cin >> T; while(T--) solve(); return 0; }
2000G
wrong_submission
277,476,713
Java 21
TIME_LIMIT_EXCEEDED on test 8
import java.io.*; import java.util.*; public class Main { public static int INF = 0x3f3f3f3f, mod = 1000000007, mod9 = 998244353; public static void main(String args[]){ try { PrintWriter o = new PrintWriter(System.out); boolean multiTest = true; // init if(multiTest) { int t = nextInt(), loop = 0; while (loop < t) {loop++;solve(o);} } else solve(o); o.close(); } catch (Exception e) {e.printStackTrace();} } static List<int[]>[] G; static int n, m; static int[] t; static void solve(PrintWriter o) { try { n = nextInt(); m = nextInt(); t = new int[3]; for(int i=0;i<3;i++) t[i] = nextInt(); G = new ArrayList[n]; Arrays.setAll(G, key->new ArrayList<>()); for(int i=0;i<m;i++) { int u = nextInt(), v = nextInt(); u--;v--; int l1 = nextInt(), l2 = nextInt(); G[u].add(new int[]{v, l1, l2}); G[v].add(new int[]{u, l1, l2}); } int l = 0, r = t[0]+1; while(l < r) { int mi = (l+r)>>1; if(check(mi)) l = mi+1; else r = mi; } if(l == 0) { o.println(-1); return; } o.println(l-1); } catch (Exception e) { e.printStackTrace(); } } static boolean check(int m) { int[] dist = new int[n]; Arrays.fill(dist, Integer.MAX_VALUE); dist[0] = m; PriorityQueue<int[]> queue = new PriorityQueue<>((x,y)->Integer.compare(x[1], y[1])); queue.offer(new int[]{0, m}); while(!queue.isEmpty()) { int[] it = queue.poll(); int u = it[0], now = it[1]; if(now > dist[u]) continue; if(u == n-1) { return true; } for(int[] it1: G[u]) { int v = it1[0], w1 = it1[1], w2 = it1[2]; boolean used = false; if(now+w1 <= t[0]) { if((now < t[1] && now+w1 <= t[1] || now >= t[2]) && now+w1 < dist[v]) { dist[v] = now+w1; queue.offer(new int[]{v, now+w1}); used = true; } } if(!used) { int comp1 = Integer.MAX_VALUE, comp2 = Integer.MAX_VALUE; if(now < t[2] && t[2]+w1 <= t[0] && t[2]+w1 < dist[v]) comp1 = t[2]+w1; if(now+w2 <= t[0] && now+w2 < dist[v]) comp2 = now+w2; comp1 = Math.min(comp1, comp2); if(comp1 < dist[v]) queue.offer(new int[]{v, comp1}); } } } return false; } public static int upper_bound(int[] a, int val){ int l = 0, r = a.length; while(l < r){ int mid = l + (r - l) / 2; if(a[mid] <= val) l = mid + 1; else r = mid; } return l; } public static int lower_bound(int[] a, int val){ int l = 0, r = a.length; while(l < r){ int mid = l + (r - l) / 2; if(a[mid] < val) l = mid + 1; else r = mid; } return l; } public static long gcd(long a, long b) { return b == 0 ? a : gcd(b, a%b); } public static long[] extgcd(long a, long b) { if(b == 0) return new long[]{1, 0}; long[] it = extgcd(b, a%b); long x = it[1], y = it[0]; y -= a/b*x; return new long[]{x, y}; } public static long lcm(long a, long b){ return a / gcd(a,b)*b; } public static long qpow(long a, long n, int md){ a %= md; long ret = 1l; while(n > 0){ if((n & 1) == 1) ret = ret * a % md; n >>= 1; a = a * a % md; } return ret; } public static class FenWick { int n; long[] a; long[] tree; public FenWick(int n){ this.n = n; a = new long[n+1]; tree = new long[n+1]; } private void add(int x, long val){ while(x <= n){ tree[x] += val; x += x&-x; } } private void addMx(int x, long val) { a[x] += val; tree[x] = a[x]; while(x <= n) { for(int i=1;i<(x&-x);i<<=1) tree[x] = Math.max(tree[x], tree[x-i]); x += x&-x; } } private long query(int x){ long ret = 0l; while(x > 0){ ret += tree[x]; x -= x&-x; } return ret; } private long queryMx(int l, int r) { long res = 0l; while(l <= r) { if(r-(r&-r) >= l) { res = Math.max(res, tree[r]); r -= r&-r; } else { res = Math.max(res, a[r]); r--; } } return res; } } static class DSU { int[] parent; public DSU(int n) { parent = new int[n]; for(int i=0;i<n;i++) parent[i] = i; } public int find(int x) { if(parent[x] != x) parent[x] = find(parent[x]); return parent[x]; } public void union(int x, int y) { int root_x = find(x); int root_y = find(y); if(root_x == root_y) return; parent[root_x] = root_y; } } private static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); private static StringTokenizer tokenizer = new StringTokenizer(""); private static String next() throws IOException{ while(!tokenizer.hasMoreTokens()){tokenizer = new StringTokenizer(reader.readLine());} return tokenizer.nextToken(); } public static int nextInt() throws IOException {return Integer.parseInt(next());} public static Long nextLong() throws IOException {return Long.parseLong(next());} public static double nextDouble() throws IOException {return Double.parseDouble(next());} public static char nextChar() throws IOException {return next().toCharArray()[0];} public static String nextString() throws IOException {return next();} public static String nextLine() throws IOException {return reader.readLine();} }
2000G
wrong_submission
277,104,325
PyPy 3-64
TIME_LIMIT_EXCEEDED on test 9
import math from collections import Counter import sys import heapq input = sys.stdin.readline t = int(input()) for _ in range(t): n, m = map(int, input().split()) eventTime, startCall, endCall = map(int, input().split()) neighbourNodes = [[] for i in range(n)] for i in range(m): path, toPath, durationBus, durationWalk = map(int, input().split()) path -= 1 toPath -= 1 neighbourNodes[path].append([toPath, durationBus, durationWalk]) neighbourNodes[toPath].append([path, durationBus, durationWalk]) def solve(): leftPointer, rightPointer = 0, eventTime ans = float('inf') def isValid(startTime): heap = [[startTime, 0]] arrivalTime = [[float('inf'), float('inf')] for i in range(n)] arrivalTime[0][1 if startTime >= endCall else 0] = startTime while heap: currTime, currNode = heapq.heappop(heap) for node, durationBus, durationWalk in neighbourNodes[currNode]: if currTime + durationWalk <= startCall or currTime >= endCall: endTime = currTime + durationBus newState = 1 if endTime >= endCall else 0 if arrivalTime[node][newState] > endTime: arrivalTime[node][newState] = endTime heapq.heappush(heap, [endTime, node]) continue if endCall >= currTime >= startCall or currTime + durationBus > startCall: for endTime in [currTime + durationWalk, endCall + durationBus]: newState = 1 if endTime >= endCall else 0 if arrivalTime[node][newState] > endTime: arrivalTime[node][newState] = endTime heapq.heappush(heap, [endTime, node]) continue for endTime in [currTime + durationBus, currTime + durationWalk, endCall + durationBus]: newState = 1 if endTime >= endCall else 0 if endTime <= currTime: continue if arrivalTime[node][newState] > endTime: arrivalTime[node][newState] = endTime heapq.heappush(heap, [endTime, node]) return arrivalTime[n - 1][1] <= eventTime or arrivalTime[n - 1][0] <= endCall while rightPointer >= leftPointer: middlePointer = (leftPointer + rightPointer) // 2 if isValid(middlePointer): ans = middlePointer leftPointer = middlePointer + 1 else: rightPointer = middlePointer - 1 return ans if ans != float('inf') else -1 print(solve())
2000G
wrong_submission
276,326,449
Python 3
TIME_LIMIT_EXCEEDED on test 10
# Author : Omm Praksh Sahoo # Calm, Down... Wrong Submission Have 10 Mins Penalty import heapq I = lambda: input() II = lambda: int(input()) MII = lambda: map(int, input().split()) LI = lambda: list(input().split()) LII = lambda: list(map(int, input().split())) LGMII = lambda: map(lambda x: int(x) - 1, input().split()) LGLII = lambda: list(map(lambda x: int(x) - 1, input().split())) inf = float('inf') # ######################################################################################################### # #-----------------------------------------------Code----------------------------------------------------# # ######################################################################################################### # # import heapq def solve(): n, m = MII() t0, t1, t2 = MII() graph = [[] for _ in range(n)] for _ in range(m): u, v, l1, l2 = MII() u -= 1 v -= 1 graph[u].append((v, l1, l2)) graph[v].append((u, l1, l2)) def by_bus(t_start, t_end): return t_end <= t1 or t_start >= t2 def predicate(start_time): pq = [(start_time, 0)] dist = [inf] * n dist[0] = start_time while pq: current_time, u = heapq.heappop(pq) # Early exit if we reach the destination if u == n - 1 and current_time <= t0: return True if current_time > dist[u]: continue for v, l1, l2 in graph[u]: # Relax the edge with l1 new_time = current_time + l1 if by_bus(current_time, new_time) and dist[v] > new_time: dist[v] = new_time heapq.heappush(pq, (new_time, v)) # Relax the edge with adjusted time adjusted_time = max(current_time, t2) + l1 if dist[v] > adjusted_time: dist[v] = adjusted_time heapq.heappush(pq, (adjusted_time, v)) # Relax the edge with l2 new_time_with_l2 = current_time + l2 if dist[v] > new_time_with_l2: dist[v] = new_time_with_l2 heapq.heappush(pq, (new_time_with_l2, v)) return dist[n - 1] <= t0 lo, hi = 0, t0 ans = -1 while lo <= hi: mid = (lo + hi) // 2 if predicate(mid): ans = mid lo = mid + 1 else: hi = mid - 1 return ans t1 = II() for _ in range(t1): print(solve())
2000G
wrong_submission
276,286,179
PyPy 3-64
TIME_LIMIT_EXCEEDED on test 10
I = lambda : list(map(int, input().split(' '))) R = lambda : (int(input())) import math from collections import defaultdict from collections import deque from heapq import heappop, heappush, heapify def is_possible(node, e, t0, t1, t2): dis = [float('inf') for i in range(n + 1)] dis[1] = node[0][0] heapify(node) while len(node) > 0: d, curr, parent = heappop(node) dis[curr] = min(dis[curr], d) for v, l1, l2 in e[curr]: if d <= t1: time_req = d + l1 if d + l1 <= t1 else d + l2 if time_req > t2 + l1: time_req = t2 + l1 elif d > t1 and d < t2: time_req = d + l2 if time_req > t2 + l1: time_req = t2 + l1 elif d >= t2: time_req = d + l1 if v != n and v != parent: if dis[v] > time_req: heappush(node, (time_req, v, curr)) dis[v] = min(time_req, dis[v]) elif v == n and v != parent: dis[v] = min(dis[v], time_req) # if dis[n] <= t0: # print(t0 - dis[n]) # else: # print(-1) return dis[n] <= t0 for kp in range(R()): n,m = I() t0, t1, t2 = I() e = [[] for i in range(n+1)] prev = -1 low = 0 high = t0 for i in range(m): u,v,l1,l2 = I() e[u].append((v,l1,l2)) e[v].append((u,l1,l2)) while low <= high: mid = (low + high)//2 is_d = is_possible( [(mid, 1, -1)] , e, t0, t1, t2) if is_d == True: prev = mid low = mid + 1 else: high = mid - 1 # print(high, low, mid, is_d) print(prev)
2000G
wrong_submission
276,516,287
PyPy 3-64
TIME_LIMIT_EXCEEDED on test 11
import bisect from collections import defaultdict, deque, Counter from math import inf, ceil, gcd from itertools import accumulate,permutations import random from bisect import bisect_left, bisect_right from math import sqrt, comb, ceil,log,floor from collections import Counter import random import heapq def solve(): n,m=map(int,input().split()) t0,t1,t2=map(int,input().split()) g=[[] for _ in range(n)] for _ in range(m): u,v,l1,l2=map(int,input().split()) u-=1 v-=1 g[u].append([v,l1,l2]) g[v].append([u,l1,l2]) t2,t1=t0-t1,t0-t2 def needcall(x,y,t1,t2): if y<=t1 or x>=t2: return False return True def shortestPath(start: int) -> int: dis = [inf] * n dis[start] = 0 vis = [False] * n cnt=0 while True: x = -1 for i in range(n): if not vis[i] and (x < 0 or dis[i] < dis[x]): x = i cnt+=1 if cnt==n: return dis vis[x] = True for y, l1, l2 in g[x]: havecall = needcall(dis[x],dis[x]+l1,t1,t2) w=min(t2+l1-dis[x],l2) if havecall else l1 if dis[x] + w < dis[y]: dis[y] = dis[x] + w dis=shortestPath(n-1) # print(dis,t1,t2) if dis[0]<=t0: print(t0-dis[0]) else: print(-1) T = int(input()) for _ in range(T): solve()
2000G
wrong_submission
276,286,837
PyPy 3-64
TIME_LIMIT_EXCEEDED on test 11
import functools import sys # sys.setrecursionlimit(2000000) from collections import defaultdict import collections #from sortedcontainers import SortedList import math import heapq from collections import deque import bisect import sys input = sys.stdin.readline import heapq def check(curr,dist,x,y): a,b = curr,curr+dist if b <= x or a >= y: return True else: return False def djikstra(start_time,bus_graph,walk_graph,phone_start,phone_end,N): node= 0 heap_list = [] heap_list.append((start_time,node)) best_dist = [math.inf]*(N) best_dist[node] = start_time while heap_list: dist, node = heapq.heappop(heap_list) #print(dist,node) if dist == best_dist[node]: best_dist[node] = dist for child,new_dist in walk_graph[node]: if dist+new_dist < best_dist[child]: #print('chld',child) best_dist[child] = dist+new_dist heapq.heappush(heap_list,(new_dist+dist,child)) for child,new_dist in bus_graph[node]: if dist+new_dist < best_dist[child] and check(dist,new_dist,phone_start,phone_end): #print('chld',child) best_dist[child] = dist+new_dist heapq.heappush(heap_list,(new_dist+dist,child)) elif dist <= phone_end and phone_end + new_dist < best_dist[child]: best_dist[child] = phone_end + new_dist heapq.heappush(heap_list,(phone_end + new_dist,child)) return best_dist # def compute(l,r,bus_graph,walk_graph,phone_start,phone_end,N,end_time): # best_ans = -1 # while l <= r: # mid = l +(r-l)//2 # if djikstra(mid,bus_graph,walk_graph,phone_start,phone_end,N)[-1] <= end_time: # best_ans = mid # l = mid+1 # else: # r = mid-1 # def solve(N,M,arr_t,mat): # bus_graph = collections.defaultdict(list) # walk_graph = collections.defaultdict(list) # for u,v,l1,l2 in mat: # u -= 1 # v -= 1 # bus_graph[u].append([v,l1]) # bus_graph[v].append([u,l2]) # walk_graph[u].append([v,l2]) # walk_graph[v].append([u,l1]) # end_time = arr_t[0] # phone_start = arr_t[1] # phone_end = arr_t[2] # l = 0 # r = end_time # best_ans = -1 # for l,r in [[0,phone_start],[phone_start,phone_end],[phone_end,end_time]]: # temp_res = compute(l,r,bus_graph,walk_graph,phone_start,phone_end,N,end_time): # # print(djikstra(0,bus_graph,walk_graph,phone_start,phone_end,N)) # # print(bus_graph[0]) # # print(walk_graph[0]) # while l <= r: # mid = l +(r-l)//2 # if djikstra(mid,bus_graph,walk_graph,phone_start,phone_end,N)[-1] <= end_time: # best_ans = mid # l = mid+1 # else: # r = mid-1 # return best_ans def solve(N,M,arr_t,mat): bus_graph = collections.defaultdict(list) walk_graph = collections.defaultdict(list) for u,v,l1,l2 in mat: u -= 1 v -= 1 bus_graph[u].append([v,l1]) bus_graph[v].append([u,l1]) walk_graph[u].append([v,l2]) walk_graph[v].append([u,l2]) #print('bus_graph',bus_graph) #print('walk_graph',walk_graph) end_time = arr_t[0] phone_start = arr_t[1] phone_end = arr_t[2] l = 0 r = end_time best_ans = -1 # print(djikstra(0,bus_graph,walk_graph,phone_start,phone_end,N)) # print(bus_graph[0]) # print(walk_graph[0]) while l <= r: mid = l +(r-l)//2 if djikstra(mid,bus_graph,walk_graph,phone_start,phone_end,N)[-1] <= end_time: best_ans = mid l = mid+1 else: r = mid-1 return best_ans t = int(input()) for j in range(1 , t +1): #S = input() #N = int(input()) #A = input().strip() #mat = [] #A,B = input().split(" ") N, M = list(map(int,input().split(" "))) arr_t = list(map(int,input().split(" "))) mat = [] for _ in range(M): mat.append(list(map(int,input().split(" ")))) result = solve(N,M,arr_t,mat) print(result) #print("Case #{}: {}".format(j, result)) ## print('{:.8f}'.format(result))
2000G
wrong_submission
276,231,245
C++20 (GCC 13-64)
TIME_LIMIT_EXCEEDED on test 11
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #pragma GCC target ("avx2") #pragma GCC optimize ("Ofast") #pragma GCC optimize ("unroll-loops") #define f first #define s second #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) ((int) (x).size()) #define pb push_back #define mp make_pair #define int long long using namespace std; using namespace __gnu_pbds; template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template <typename T> inline bool umin(T &a, const T &b) { if(a > b) { a = b; return 1; } return 0; } template <typename T> inline bool umax(T &a, const T &b) { if(a < b) { a = b; return 1; } return 0; } typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const ll mod = 998244353; const ll base = 1e6 + 9; const ll inf = 1e18; const int MAX = 2e5 + 42; const int LG = 20; random_device rd; mt19937 gen(rd()); uniform_int_distribution<ll> dis(1, inf); void solve() { int n, m; cin >> n >> m; int x, y, z; cin >> z >> x >> y; vector<vector<array<int, 3>>> g(n + 1); while(m--) { int u, v, l, r; cin >> u >> v >> l >> r; g[u].pb({v, l, r}); g[v].pb({u, l, r}); } auto check = [&](int st) { auto dijkstra = [&](vector<pii> sources, bool flag) { vector<int> d(n + 1, inf); for(auto [v, dst] : sources) d[v] = dst; priority_queue<pii> q; for(int v = 1; v <= n; v++) q.push({d[v], v}); while(sz(q)) { auto [dst, v] = q.top(); q.pop(); if(d[v] != dst) continue; for(auto [to, a, b] : g[v]) { int w = (flag? b : a); if(d[to] > d[v] + w) { d[to] = d[v] + w; q.push({d[to], to}); } } } return d; }; vector<pii> sources = {mp(1, st)}; auto d1 = dijkstra(sources, 0); if(d1[n] <= x) return true; sources.clear(); for(int v = 1; v <= n; v++) { if(d1[v] <= x) sources.pb({v, d1[v]}); } if(sources.empty()) sources = {mp(1, st)}; auto d2 = dijkstra(sources, 1); if(d2[n] <= y) return true; for(int v = 1; v <= n; v++) umax(d2[v], y); sources.clear(); for(int v = 1; v <= n; v++) { sources.pb({v, d2[v]}); } auto d = dijkstra(sources, 0); // cout << st << ": " << d[n] << endl; return d[n] <= z; }; int l = 0, r = z; while(l <= r) { m = l + r >> 1; if(check(m)) l = m + 1; else r = m - 1; } cout << r << '\n'; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int ttt = 1; cin >> ttt; while(ttt--) { solve(); } }
2000G
wrong_submission
290,172,243
C++20 (GCC 13-64)
TIME_LIMIT_EXCEEDED on test 11
#define TESTS #include <bits/stdc++.h> using namespace std; using llu = unsigned long long; using lld = long long; using Lf = long double; #ifdef LOCAL #define debug(__ARG__) cout << "[" << #__ARG__ << "]: " << __ARG__ << endl #else #define debug(__ARG__) 42 #endif #define vec vector #define ins insert #define pb push_back #define po pop_back #define pr pair #define ers erase #define fs first #define sd second #define all(n) begin(n), end(n) const llu INF = ULLONG_MAX/10; using WAdj = vec<vec<pr<int, llu>>>; llu dist[int(1e5)], dist_main[int(1e5)]; pr<llu, int> s[int(1e5)]; int css = 0; void dijkstra(WAdj &adj) { fill(dist, dist + adj.size(), INF); //for (auto &[d, u] : s) dist[u] = d; for (int i = 0; i < css; ++i) dist[s[i].sd] = s[i].fs; set<pr<llu, int>> pq; for (int i = 0; i < adj.size(); ++i) pq.emplace(dist[i], i); while (!pq.empty()) { auto [d, u] = *pq.begin(); pq.erase(pq.begin()); for (auto &[v, w] : adj[u]) if (d + w <= dist[v]) { pq.ers(pq.find({dist[v], v})); dist[v] = d + w; pq.emplace(dist[v], v); } } } bool calc(int n, llu extra, WAdj &adjf, WAdj &adjs, llu t1, llu t2, llu t0) { css = 0; for (int i = 1; i < n; ++i) if (dist_main[i] + extra <= t1) s[css++] = {dist_main[i] + extra, i}; s[css++] = {min(dist_main[0] + extra, extra), 0}; dijkstra(adjs); css = 0; for (int i = 0; i < n; ++i) s[css++] = {max(t2, dist[i]), i}; dijkstra(adjf); if (dist[n - 1] > t0) return 0; return 1; } void solv() { int n, m; scanf("%d%d", &n, &m); llu t0, t1, t2; scanf("%llu%llu%llu", &t0, &t1, &t2); WAdj adjf(n), adjs(n); while (m--) { int a, b; llu f, s; scanf("%d%d%llu%llu", &a, &b, &f, &s), --a, --b; adjf[a].pb({b, f}); adjf[b].pb({a, f}); adjs[a].pb({b, s}); adjs[b].pb({a, s}); } lld l = -1, r = t0; css = 0; s[css++] = {0, 0}; dijkstra(adjf); memcpy(dist_main, dist, sizeof(llu)*n); while (l + 1 < r) { lld m = (l + r)/2; bool p = calc(n, m, adjf, adjs, t1, t2, t0); if (p) l = m; else r = m; } printf("%lld\n", l); } int main() { #ifdef TESTS int t; scanf("%d", &t); while (t--) #endif solv(); return 0; }
2000G
wrong_submission
277,106,823
PyPy 3-64
TIME_LIMIT_EXCEEDED on test 11
import math from collections import Counter import sys import heapq input = sys.stdin.readline t = int(input()) for _ in range(t): n, m = map(int, input().split()) eventTime, startCall, endCall = map(int, input().split()) neighbourNodes = [[] for i in range(n)] for i in range(m): path, toPath, durationBus, durationWalk = map(int, input().split()) path -= 1 toPath -= 1 neighbourNodes[path].append([toPath, durationBus, durationWalk]) neighbourNodes[toPath].append([path, durationBus, durationWalk]) def solve(): leftPointer, rightPointer = 0, eventTime ans = float('inf') def isValid(startTime): heap = [[startTime, 0]] arrivalTime = [float('inf') for i in range(n)] arrivalTime[0] = startTime while heap: currTime, currNode = heapq.heappop(heap) for node, durationBus, durationWalk in neighbourNodes[currNode]: if currTime + durationWalk <= startCall or currTime >= endCall: endTime = currTime + durationBus if arrivalTime[node] > endTime: arrivalTime[node] = endTime heapq.heappush(heap, [endTime, node]) continue if endCall >= currTime >= startCall or currTime + durationBus > startCall: for endTime in [currTime + durationWalk, endCall + durationBus]: if arrivalTime[node] > endTime: arrivalTime[node] = endTime heapq.heappush(heap, [endTime, node]) continue for endTime in [currTime + durationBus, currTime + durationWalk, endCall + durationBus]: if endTime <= currTime: continue if arrivalTime[node] > endTime: arrivalTime[node] = endTime heapq.heappush(heap, [endTime, node]) return arrivalTime[n - 1] <= eventTime while rightPointer >= leftPointer: middlePointer = (leftPointer + rightPointer) // 2 if isValid(middlePointer): ans = middlePointer leftPointer = middlePointer + 1 else: rightPointer = middlePointer - 1 return ans if ans != float('inf') else -1 print(solve())
2000G
wrong_submission
276,340,216
PyPy 3
TIME_LIMIT_EXCEEDED on test 11
from heapq import * def can(t): dis = [float("inf")] * n q=[(t,0)] while q: cost,node=heappop(q) if cost<dis[node]: dis[node]=cost for cbus,cwalk,child in graph[node]: if cost+cbus<=t1 or cost>=t2: heappush(q, (cost + cbus, child)) else: heappush(q, (t2 + cbus, child)) heappush(q, (cost + cwalk, child)) return dis[n-1]<=t0 import sys input=sys.stdin.readline for _ in range(int(input())): n,m=map(int,input().split()) t0,t1,t2=map(int,input().split()) graph=[[] for _ in range(n)] for _ in range(m): u,v,cbus,cwalk=map(int,input().split()) graph[u-1].append((cbus,cwalk,v-1)) graph[v-1].append((cbus,cwalk,u-1)) low,high=0,t0 while low<=high: mid=(low+high)>>1 if can(mid): low=mid+1 else: high=mid-1 print(high)
2000G
wrong_submission
280,232,384
C++20 (GCC 13-64)
RUNTIME_ERROR on test 11
#include <bits/stdc++.h> using namespace std; #define dbg(a) ((cerr << #a << ": " << (a) << endl), a) #define ll long long void printQueue(priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<>> q) { // Pass by value to copy the queue std::cout << "Queue elements: "; while (!q.empty()) { std::cout << q.top().first << ":" << q.top().second << " "; // Access the front element q.pop(); // Remove the front element from the copy } std::cout << std::endl; } void solve() { int n, m; cin >> n >> m; int t0, t1, t2; cin >> t0 >> t1 >> t2; int bus[n][n]; int walk[n][n]; memset(walk, 0, sizeof walk); memset(bus, 0, sizeof bus); for (int i = 0; i < m; ++i) { int u, v, l1, l2; cin >> u >> v >> l1 >> l2; u--; v--; bus[u][v] = l1; bus[v][u] = l1; walk[u][v] = l2; walk[v][u] = l2; } vector<bool> viewed (n, false); priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<>> q; vector<ll> dist (n, LONG_MAX); q.push({0, n-1}); while (!q.empty()) { pair<ll, int> el = q.top(); q.pop(); ll m_dist = el.first; int node = el.second; if (viewed[node]) continue; dist[node] = m_dist; for (int i = 0; i < n; ++i) { if (i == node) continue; ll i_min_dist; if (!viewed[i] && bus[node][i]) { if (t0 - m_dist - bus[node][i] >= t2 || t0 - m_dist <= t1) { i_min_dist = m_dist + bus[node][i]; } else { i_min_dist = min(m_dist + walk[node][i], (ll)(t0 - t1 + bus[node][i])); } q.push({i_min_dist, i}); } } viewed[node] = true; } cout << max((ll)t0 - dist[0], (ll)-1) << endl; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; cin >> t; while(t--) { solve(); } }
2000G
wrong_submission
277,102,624
PyPy 3-64
TIME_LIMIT_EXCEEDED on test 11
# Created by Ketan_Raut # Copyright © 2024 iN_siDious. All rights reserved. import sys,os import random from math import * from string import ascii_lowercase,ascii_uppercase from collections import Counter, defaultdict, deque from itertools import accumulate, combinations, permutations from heapq import heappushpop, heapify, heappop, heappush from bisect import bisect_left,bisect_right from types import GeneratorType from random import randint RANDOM = randint(1, 10 ** 10) class op(int): def __init__(self, x): int.__init__(x) def __hash__(self): return super(op, self).__hash__() ^ RANDOM def bootstrap(f, stack=[]): def wrappedfunc(*args, **kwargs): if stack: return f(*args, **kwargs) else: to = f(*args, **kwargs) while True: if type(to) is GeneratorType: stack.append(to) to = next(to) else: stack.pop() if not stack: break to = stack[-1].send(to) return to return wrappedfunc inp = lambda: sys.stdin.buffer.readline().decode().strip() out=sys.stdout.write def S(): return inp() def I(): return int(inp()) def F(): return float(inp()) def MI(): return map(int, inp().split()) def MF(): return map(float, inp().split()) def MS(): return inp().split() def LS(): return list(inp().split()) def LI(): return list(map(int,inp().split())) def LF(): return list(map(float,inp().split())) def Query(i,j): print3('?', i, j) sys.stdout.flush() qi=I() return qi def print1(x): return out(str(x)+"\n") def print2(x,y): return out(str(x)+" "+str(y)+"\n") def print3(x,y,z): return out(str(x)+" "+str(y)+" "+str(z)+"\n") def print_arr(arr): for num in arr: out(str(num)+" ") out(str("\n")) def solve(st): heap,dist=[],[sys.maxsize]*n dist[0],gg=st,defaultdict(list) gg[str(st)].append(0) heappush(heap,st) while heap: time=heappop(heap) node=gg[str(time)].pop() for nei,l1,l2 in graph[node]: new_time=time+l1 if not ((t1<new_time<t2) or (time<=t1 and new_time>=t2) or t1<time<t2): if new_time<dist[nei]: dist[nei]=new_time gg[str(new_time)].append(nei) heappush(heap,new_time) else: new_time=min(time+l2,t2+l1) if new_time<dist[nei]: dist[nei]=new_time gg[str(new_time)].append(nei) heappush(heap,new_time) return dist[n-1]<=t0 for _ in range(I()): n,m=MI() t0,t1,t2=MI() graph=[[] for _ in range(n)] for _ in range(m): u,v,l1,l2=MI() u,v=u-1,v-1 graph[u].append((v,l1,l2)) graph[v].append((u,l1,l2)) ans=-sys.maxsize l,h=0,10**9+5 while l<h: mid=(l+h+1)>>1 if solve(mid): l=mid else: h=mid-1 if solve(l): ans=max(ans,l) print1(-1 if ans==-sys.maxsize else ans)
2000G
wrong_submission
276,516,550
PyPy 3-64
TIME_LIMIT_EXCEEDED on test 11
import bisect from collections import defaultdict, deque, Counter from math import inf, ceil, gcd from itertools import accumulate,permutations import random from bisect import bisect_left, bisect_right from math import sqrt, comb, ceil,log,floor from collections import Counter import random import heapq def solve(): n,m=map(int,input().split()) t0,t1,t2=map(int,input().split()) g=[[] for _ in range(n)] for _ in range(m): u,v,l1,l2=map(int,input().split()) u-=1 v-=1 g[u].append([v,l1,l2]) g[v].append([u,l1,l2]) t2,t1=t0-t1,t0-t2 def needcall(x,y,t1,t2): if y<=t1 or x>=t2: return False return True def shortestPath(start: int) -> int: dis = [inf] * n dis[start] = 0 vis = [False] * n cnt=0 while True: x = -1 for i in range(n): if not vis[i] and (x < 0 or dis[i] < dis[x]): x = i cnt+=1 if cnt==n: return dis vis[x] = True for y, l1, l2 in g[x]: havecall = needcall(dis[x],dis[x]+l1,t1,t2) w=min(t2+l1-dis[x],l2) if havecall else l1 if dis[x] + w < dis[y] and dis[x]+w<=t0: dis[y] = dis[x] + w dis=shortestPath(n-1) # print(dis,t1,t2) if dis[0]<=t0: print(t0-dis[0]) else: print(-1) T = int(input()) for _ in range(T): solve()
2000G
wrong_submission
276,339,133
PyPy 3-64
TIME_LIMIT_EXCEEDED on test 11
import sys import math input = lambda: sys.stdin.buffer.readline().decode().rstrip() class FibonacciHeapNode: def __init__(self, key, node): self.key = key self.node = node self.degree = 0 self.parent = None self.child = None self.mark = False self.left = self self.right = self class FibonacciHeap: def __init__(self): self.min_node = None self.num_nodes = 0 def is_empty(self): return self.min_node is None def insert(self, key, node): fib_node = FibonacciHeapNode(key, node) if self.min_node is None: self.min_node = fib_node else: fib_node.left = self.min_node fib_node.right = self.min_node.right self.min_node.right = fib_node fib_node.right.left = fib_node if fib_node.key < self.min_node.key: self.min_node = fib_node self.num_nodes += 1 return fib_node def _remove_from_root_list(self, node): if node == node.right: self.min_node = None else: node.left.right = node.right node.right.left = node.left if node == self.min_node: self.min_node = node.right def _link(self, node1, node2): self._remove_from_root_list(node2) node2.left = node2.right = node2 node2.parent = node1 if node1.child is None: node1.child = node2 else: node2.left = node1.child node2.right = node1.child.right node1.child.right = node2 node2.right.left = node2 node1.degree += 1 node2.mark = False def _consolidate(self): max_degree = math.ceil(math.log(self.num_nodes, 2)) degree_table = [None] * (max_degree + 1) current = self.min_node nodes = [current] while current.right != self.min_node: current = current.right nodes.append(current) for current in nodes: degree = current.degree while degree_table[degree] is not None: other = degree_table[degree] if current.key > other.key: current, other = other, current self._link(current, other) degree_table[degree] = None degree += 1 degree_table[degree] = current self.min_node = None for node in degree_table: if node is not None: if self.min_node is None: self.min_node = node else: node.left.right = node.right node.right.left = node.left node.left = self.min_node node.right = self.min_node.right self.min_node.right = node node.right.left = node if node.key < self.min_node.key: self.min_node = node def extract_min(self): min_node = self.min_node if min_node is not None: if min_node.child is not None: children = [child for child in self._iterate(min_node.child)] for child in children: child.parent = None self.min_node.left.right = child child.left = self.min_node.left child.right = self.min_node self.min_node.left = child if child.key < self.min_node.key: self.min_node = child self._remove_from_root_list(min_node) if min_node == min_node.right: self.min_node = None else: self.min_node = min_node.right self._consolidate() self.num_nodes -= 1 return min_node def decrease_key(self, node, new_key): if new_key > node.key: raise ValueError("New key is greater than current key.") node.key = new_key parent = node.parent if parent is not None and node.key < parent.key: self._cut(node, parent) self._cascade_cut(parent) if node.key < self.min_node.key: self.min_node = node def _cut(self, node, parent): if node == node.right: parent.child = None else: node.left.right = node.right node.right.left = node.left if node == parent.child: parent.child = node.right parent.degree -= 1 node.left = self.min_node.left node.right = self.min_node self.min_node.left.right = node self.min_node.left = node node.parent = None node.mark = False def _cascade_cut(self, node): parent = node.parent if parent is not None: if not node.mark: node.mark = True else: self._cut(node, parent) self._cascade_cut(parent) def _iterate(self, node): start = node while True: yield node node = node.right if node == start: break def check(m): fib_heap = FibonacciHeap() dis = [float("inf")] * (n + 1) dis[1] = m node_map = [None] * (n + 1) node_map[1] = fib_heap.insert(m, 1) while not fib_heap.is_empty(): node = fib_heap.extract_min() if node is None: break d, u = node.key, node.node if u == n: break if dis[u] < d: continue for v, l1, l2 in g[u]: w = l2 if t1 <= d < t2 or (d <= t1 and d + l1 > t1) else l1 new_d = d + w if dis[v] > new_d: dis[v] = new_d if node_map[v] is None: node_map[v] = fib_heap.insert(new_d, v) else: fib_heap.decrease_key(node_map[v], new_d) newd = max(d, t2) if dis[v] > l1 + newd: dis[v] = l1 + newd if node_map[v] is None: node_map[v] = fib_heap.insert(l1 + newd, v) else: fib_heap.decrease_key(node_map[v], l1 + newd) return dis[n] <= t0 def solve(): global n, m, g, t0, t1, t2 n, m = map(int, input().split()) t0, t1, t2 = map(int, input().split()) g = [[] for _ in range(n + 1)] for _ in range(m): u, v, l1, l2 = map(int, input().split()) g[u].append((v, l1, l2)) g[v].append((u, l1, l2)) l, r = -2, t0 while l < r: mid = (r + l + 1) >> 1 if check(mid): l = mid else: r = mid - 1 r = max(-1, r) print(r) ############################################################################### ############################################################################### ############################################################################### for t in range(int(input())): solve()
2000G
wrong_submission
276,516,732
PyPy 3-64
TIME_LIMIT_EXCEEDED on test 11
import bisect from collections import defaultdict, deque, Counter from math import inf, ceil, gcd from itertools import accumulate,permutations import random from bisect import bisect_left, bisect_right from math import sqrt, comb, ceil,log,floor from collections import Counter import random import heapq def solve(): n,m=map(int,input().split()) t0,t1,t2=map(int,input().split()) g=[[] for _ in range(n)] for _ in range(m): u,v,l1,l2=map(int,input().split()) u-=1 v-=1 g[u].append([v,l1,l2]) g[v].append([u,l1,l2]) t2,t1=t0-t1,t0-t2 def needcall(x,y,t1,t2): if y<=t1 or x>=t2: return False return True def shortestPath(start: int) -> int: dis = [inf] * n dis[start] = 0 vis = [False] * n cnt=0 while True: x = -1 for i in range(n): if not vis[i] and (x < 0 or dis[i] < dis[x]): x = i cnt+=1 if cnt==n: return dis vis[x] = True for y, l1, l2 in g[x]: havecall = needcall(dis[x],dis[x]+l1,t1,t2) w=min(t2+l1-dis[x],l2) if havecall else l1 if dis[x] + w < dis[y]: dis[y] = min(t0+1,dis[x] + w) dis=shortestPath(n-1) # print(dis,t1,t2) if dis[0]<=t0: print(t0-dis[0]) else: print(-1) T = int(input()) for _ in range(T): solve()
2000G
wrong_submission
276,326,410
PyPy 3-64
TIME_LIMIT_EXCEEDED on test 11
# Author : Omm Praksh Sahoo # Calm, Down... Wrong Submission Have 10 Mins Penalty import heapq I = lambda: input() II = lambda: int(input()) MII = lambda: map(int, input().split()) LI = lambda: list(input().split()) LII = lambda: list(map(int, input().split())) LGMII = lambda: map(lambda x: int(x) - 1, input().split()) LGLII = lambda: list(map(lambda x: int(x) - 1, input().split())) inf = float('inf') # ######################################################################################################### # #-----------------------------------------------Code----------------------------------------------------# # ######################################################################################################### # # import heapq from collections import defaultdict inf = float('inf') def solve(): n, m = MII() t0, t1, t2 = MII() graph = defaultdict(list) for _ in range(m): u, v, l1, l2 = MII() u -= 1 v -= 1 graph[u].append((v, l1, l2)) graph[v].append((u, l1, l2)) def can_take_bus(start_time, end_time): return end_time <= t1 or start_time >= t2 def predicate(start_time): dist = [inf] * n dist[0] = start_time pq = [(start_time, 0)] # (current_time, node) while pq: current_time, u = heapq.heappop(pq) if current_time > dist[u]: continue for v, l1, l2 in graph[u]: # Relax the edge with l2 new_time_l2 = current_time + l2 if dist[v] > new_time_l2: dist[v] = new_time_l2 heapq.heappush(pq, (new_time_l2, v)) # Relax the edge with l1 new_time_l1 = current_time + l1 if can_take_bus(current_time, new_time_l1) and dist[v] > new_time_l1: dist[v] = new_time_l1 heapq.heappush(pq, (new_time_l1, v)) else: adjusted_time = max(current_time, t2) + l1 if dist[v] > adjusted_time: dist[v] = adjusted_time heapq.heappush(pq, (adjusted_time, v)) return dist[n-1] <= t0 lo, hi = 0, t0 ans = -1 while lo <= hi: mid = (lo + hi) // 2 if predicate(mid): ans = mid lo = mid + 1 else: hi = mid - 1 return ans t1 = II() for _ in range(t1): print(solve())
2000G
wrong_submission
276,340,273
PyPy 3
TIME_LIMIT_EXCEEDED on test 11
# ﷽ import sys from heapq import * input = lambda: sys.stdin.buffer.readline().decode().rstrip() def can(t): dis = [float("inf")] * n q=[(t,0)] while q: cost,node=heappop(q) if cost<dis[node]: dis[node]=cost for cbus,cwalk,child in graph[node]: if cost+cbus<=t1 or cost>=t2: heappush(q, (cost + cbus, child)) else: heappush(q, (t2 + cbus, child)) heappush(q, (cost + cwalk, child)) return dis[n-1]<=t0 for _ in range(int(input())): n,m=map(int,input().split()) t0,t1,t2=map(int,input().split()) graph=[[] for _ in range(n)] for _ in range(m): u,v,cbus,cwalk=map(int,input().split()) graph[u-1].append((cbus,cwalk,v-1)) graph[v-1].append((cbus,cwalk,u-1)) low,high=0,t0 while low<=high: mid=(low+high)>>1 if can(mid): low=mid+1 else: high=mid-1 print(high)
2000G
wrong_submission
276,285,428
PyPy 3-64
TIME_LIMIT_EXCEEDED on test 12
import sys; input = sys.stdin.readline sys.setrecursionlimit(1000) from random import * from collections import * from heapq import * from bisect import * from array import * old_pow = pow from math import * pow = old_pow num = lambda: int(input()) line = lambda: [*map(int, input().split())] RANDOM = getrandbits(32) class Wrapper(int): def __init__(self, x): int.__init__(x) def __hash__(self): return super(Wrapper, self).__hash__() ^ RANDOM def can(x): if x == -1: return 1 INF = float('inf'); D = [INF]*n; D[0] = x; pq = [(x, 0)] while pq: dd, vv = heappop(pq) if dd != D[vv]: continue for nn in g[vv]: s, f = g[vv][Wrapper(nn)] if dd+s <= t1 or dd >= t2: if D[nn] > (new:=dd+s): D[nn] = new; heappush(pq, (new, nn)) else: if D[nn] > (new:=min(dd+f, t2+s)): D[nn] = new; heappush(pq, (new, nn)) return D[-1] <= t0 for _ in range(int(input())): n, m = line() t0, t1, t2 = line() g = [{} for _ in range(n)] for _ in range(m): a, b, s, f = line() g[a-1][Wrapper(b-1)] = g[b-1][Wrapper(a-1)] = (s, f) lo, hi = -1, t0 while hi-lo>1: if can(mi:=(lo+hi)//2): lo = mi else: hi = mi-1 print(hi if can(hi) else hi-1)
2000G
wrong_submission
276,326,170
PyPy 3-64
TIME_LIMIT_EXCEEDED on test 12
# Author : Omm Praksh Sahoo # Calm, Down... Wrong Submission Have 10 Mins Penalty import heapq I = lambda: input() II = lambda: int(input()) MII = lambda: map(int, input().split()) LI = lambda: list(input().split()) LII = lambda: list(map(int, input().split())) LGMII = lambda: map(lambda x: int(x) - 1, input().split()) LGLII = lambda: list(map(lambda x: int(x) - 1, input().split())) inf = float('inf') # ######################################################################################################### # #-----------------------------------------------Code----------------------------------------------------# # ######################################################################################################### # # # def solve(): # ans=0 # n,m=MII() # t0,t1,t2=MII() # g1=[[] for i in range (n)] # g2=[[] for i in range (n)] # for __ in range (m): # u,v,l1,l2= MII() # u-=1 # v-=1 # g1[u].append([v,l1]) # g1[v].append([u,l1]) # g2[u].append([v,l2]) # g2[v].append([u,l2]) # def by_bus(t11,t22): # if t11<=t1 or t22>=t2: # return True # return False # # q=queue.Deque() # def predicate (mid): # pq=[(mid,0)] # dist=[inf]*n # dist[0]=0 # while pq: # t,u=heapq.heappop(pq) # if t>dist[u]:continue # for v,ti in g1[u]: # if by_bus(t,t+ti): # if dist[v]>(t+ti): # # q.append(ti,v) # dist[v]=t+ti # heapq.heappush(pq,(dist[v],v)) # # if t+l2<: # if dist[v]>max(t,t2)+ti: # # q.append(t2+dist[u],v) # dist[v]=max(t,t2)+ti # heapq.heappush(pq,(dist[v],v)) # for v,ti in g2[u]: # # print(v,ti) # if dist[v]>(t+ti): # # q.append(ti,v) # dist[v]=t+ti # heapq.heappush(pq,(dist[v],v)) # # print(*dist) # return dist[-1]<=t0 # lo=0 # hi=10**18 # while lo <= hi: # mid = (lo+hi)//2 # if predicate(mid): # ans=mid # lo=mid+1 # else: # hi=mid-1 # return ans if ans<=t0 else -1 # t111=1 # t111=int(input()) # for _ in range (t111): # print(solve()) def solve(): n, m = MII() t0, t1, t2 = MII() graph = [[] for _ in range(n)] for _ in range(m): u, v, l1, l2 = MII() u -= 1 v -= 1 graph[u].append((v, l1, l2)) graph[v].append((u, l1, l2)) def by_bus(t_start, t_end): return t_end <= t1 or t_start >= t2 def predicate(start_time): pq = [(start_time, 0)] dist = [inf] * n dist[0] = start_time while pq: current_time, u = heapq.heappop(pq) if current_time > dist[u]: continue for v, l1, l2 in graph[u]: if by_bus(current_time, current_time + l1) and dist[v] > current_time + l1: dist[v] = current_time + l1 heapq.heappush(pq, (dist[v], v)) adjusted_time = max(current_time, t2) + l1 if dist[v] > adjusted_time: dist[v] = adjusted_time heapq.heappush(pq, (dist[v], v)) if dist[v] > current_time + l2: dist[v] = current_time + l2 heapq.heappush(pq, (dist[v], v)) return dist[n-1] <= t0 lo, hi = 0, t0 ans = -1 while lo <= hi: mid = (lo + hi) // 2 if predicate(mid): ans = mid lo = mid + 1 else: hi = mid - 1 return ans t1 = II() for _ in range(t1): print(solve())
2000G
wrong_submission
278,877,912
C++20 (GCC 13-64)
TIME_LIMIT_EXCEEDED on test 12
#include<bits/stdc++.h> using namespace std; const int N = 1e5+7; const int inf = 1e9; struct edge{ int from,to,w1,w2; }e[N]; struct node { int d,u; bool operator< (const node &x) const { return d<x.d; } }; set<pair<int, int>> q; vector<int> G[N]; bool vis[N]; int d[N]; int n,m,cnt,t0,t1,t2; void addEdge(int f,int t,int w1,int w2) { cnt++; e[cnt].from = f; e[cnt].to = t; e[cnt].w1 = w1; e[cnt].w2 = w2; G[f].push_back(cnt); } void solve(){ d[n] = t0;q.insert({d[n],n}); for(int i=1;i<n;i++) { q.insert({d[i],i}); } while(!q.empty()) { auto x = *(q.rbegin());q.erase(x); int U = x.second,D=x.first; if(vis[U]) continue; //cout<<x.u<<endl; vis[U] = true; for(auto k : G[U]) { int f=e[k].from,t=e[k].to,w1=e[k].w1,w2=e[k].w2; int dis; if(D-w1>=t2||D<=t1) { dis = D-w1; }else { dis = D-w2; dis = max(dis,t1-w1); } if(dis > d[t]) { q.erase({d[t],t}); d[t]=dis; q.insert({d[t],t}); } } } if(d[1]<0) { cout<<"-1\n"; }else cout<<d[1]<<"\n"; } int main(){ int _; cin>>_; while(_--){ cin>>n>>m>>t0>>t1>>t2; cnt=0; for(int i=1;i<=n;i++) { G[i].clear(); vis[i]=false; d[i] = -inf; } int u,v,l1,l2; for(int i=1;i<=m;i++) { scanf("%d%d%d%d",&u,&v,&l1,&l2); addEdge(u,v,l1,l2); addEdge(v,u,l1,l2); } solve(); } return 0; }
2000G
wrong_submission
276,199,233
PyPy 3-64
TIME_LIMIT_EXCEEDED on test 12
from sys import stdin input=lambda :stdin.readline()[:-1] from collections import defaultdict from heapq import heappop, heappush def solve(): n,m=map(int,input().split()) t0,t1,t2=map(int,input().split()) edge=[[] for i in range(n)] for _ in range(m): u,v,l1,l2=map(int,input().split()) u-=1 v-=1 edge[u].append((v,l1,l2)) edge[v].append((u,l1,l2)) inf=1<<60 def check(s,t): if t<=t1 or s>=t2: return True return False def calc(mid): dist=[inf]*n dist[0]=mid hq=[(mid,0)] while hq: tm,v=heappop(hq) if dist[v]<tm: continue for u,l1,l2 in edge[v]: if check(tm,tm+l1): if dist[u]>tm+l1: dist[u]=tm+l1 heappush(hq,(tm+l1,u)) else: if tm<=t2: if dist[u]>t2+l1: dist[u]=t2+l1 heappush(hq,(t2+l1,u)) if dist[u]>tm+l2: dist[u]=tm+l2 heappush(hq,(tm+l2,u)) return dist[n-1]<=t0 ok,ng=-1,t0+1 while ng-ok>1: mid=(ng+ok)//2 if calc(mid): ok=mid else: ng=mid print(ok) for _ in range(int(input())): solve()
2000G
wrong_submission
276,517,037
PyPy 3-64
TIME_LIMIT_EXCEEDED on test 14
import bisect from collections import defaultdict, deque, Counter from math import inf, ceil, gcd from itertools import accumulate,permutations import random from bisect import bisect_left, bisect_right from math import sqrt, comb, ceil,log,floor from collections import Counter import random import heapq def min(x,y): return x if x<y else y def solve(): n,m=map(int,input().split()) t0,t1,t2=map(int,input().split()) g=[[] for _ in range(n)] for _ in range(m): u,v,l1,l2=map(int,input().split()) u-=1 v-=1 g[u].append([v,l1,l2]) g[v].append([u,l1,l2]) t2,t1=t0-t1,t0-t2 def needcall(x,y,t1,t2): if y<=t1 or x>=t2: return False return True def shortestPath(start: int) -> int: dis = [inf] * n dis[start] = 0 vis = [False] * n cnt=0 while True: x = -1 for i in range(n): if not vis[i] and (x < 0 or dis[i] < dis[x]): x = i if dis[x]>t0: return dis cnt+=1 if cnt==n: return dis vis[x] = True for y, l1, l2 in g[x]: havecall = needcall(dis[x],dis[x]+l1,t1,t2) w=min(t2+l1-dis[x],l2) if havecall else l1 if dis[x] + w < dis[y]: dis[y] = min(t0+1,dis[x] + w) dis=shortestPath(n-1) # print(dis,t1,t2) if dis[0]<=t0: print(t0-dis[0]) else: print(-1) T = int(input()) for _ in range(T): solve()
2000G
wrong_submission
276,516,950
PyPy 3-64
TIME_LIMIT_EXCEEDED on test 14
import bisect from collections import defaultdict, deque, Counter from math import inf, ceil, gcd from itertools import accumulate,permutations import random from bisect import bisect_left, bisect_right from math import sqrt, comb, ceil,log,floor from collections import Counter import random import heapq def solve(): n,m=map(int,input().split()) t0,t1,t2=map(int,input().split()) g=[[] for _ in range(n)] for _ in range(m): u,v,l1,l2=map(int,input().split()) u-=1 v-=1 g[u].append([v,l1,l2]) g[v].append([u,l1,l2]) t2,t1=t0-t1,t0-t2 def needcall(x,y,t1,t2): if y<=t1 or x>=t2: return False return True def shortestPath(start: int) -> int: dis = [inf] * n dis[start] = 0 vis = [False] * n cnt=0 while True: x = -1 for i in range(n): if not vis[i] and (x < 0 or dis[i] < dis[x]): x = i if dis[x]>t0: return dis cnt+=1 if cnt==n: return dis vis[x] = True for y, l1, l2 in g[x]: havecall = needcall(dis[x],dis[x]+l1,t1,t2) w=min(t2+l1-dis[x],l2) if havecall else l1 if dis[x] + w < dis[y]: dis[y] = min(t0+1,dis[x] + w) dis=shortestPath(n-1) # print(dis,t1,t2) if dis[0]<=t0: print(t0-dis[0]) else: print(-1) T = int(input()) for _ in range(T): solve()
2000G
wrong_submission
276,516,853
PyPy 3-64
TIME_LIMIT_EXCEEDED on test 14
import bisect from collections import defaultdict, deque, Counter from math import inf, ceil, gcd from itertools import accumulate,permutations import random from bisect import bisect_left, bisect_right from math import sqrt, comb, ceil,log,floor from collections import Counter import random import heapq def solve(): n,m=map(int,input().split()) t0,t1,t2=map(int,input().split()) g=[[] for _ in range(n)] for _ in range(m): u,v,l1,l2=map(int,input().split()) u-=1 v-=1 g[u].append([v,l1,l2]) g[v].append([u,l1,l2]) t2,t1=t0-t1,t0-t2 def needcall(x,y,t1,t2): if y<=t1 or x>=t2: return False return True def shortestPath(start: int) -> int: dis = [inf] * n dis[start] = 0 vis = [False] * n cnt=0 while True: x = -1 for i in range(n): if not vis[i] and (x < 0 or dis[i] < dis[x]): x = i if dis[x]>t0: return dis cnt+=1 if cnt==n: return dis vis[x] = True for y, l1, l2 in g[x]: havecall = needcall(dis[x],dis[x]+l1,t1,t2) w=min(t2+l1-dis[x],l2) if havecall else l1 if dis[x] + w < dis[y]: dis[y] = dis[x] + w dis=shortestPath(n-1) # print(dis,t1,t2) if dis[0]<=t0: print(t0-dis[0]) else: print(-1) T = int(input()) for _ in range(T): solve()
2000G
wrong_submission
276,376,474
PyPy 3-64
TIME_LIMIT_EXCEEDED on test 14
from bisect import * import heapq as heapq for _ in range(int(input())): n,m=map(int,input().split()) t0,t1,t2=map(int,input().split()) res=[] inf=(1<<32) for _ in range(m): a,b,w1,w2=map(int,input().split()) res.append([a-1,b-1,w1,w2]) g=[[] for _ in range(n)] for a,b,w1,w2 in res: g[a].append([b,w1,w2]) g[b].append([a,w1,w2]) def check(x): q=[] dist=[inf]*n q.append([x,0]) while q: cost,i=heapq.heappop(q) if i==n-1: return cost<=t0 for j,w1,w2 in g[i]: if dist[j]>cost+w1 and (cost+w1<=t1 or cost>=t2): dist[j]=cost+w1 heapq.heappush(q,[cost+w1,j]) if dist[j]>t2+w1 and cost<=t2: dist[j]=t2+w1 heapq.heappush(q,[t2+w1,j]) if dist[j]>cost+w2: dist[j]=cost+w2 heapq.heappush(q,[cost+w2,j]) return False b=bisect_left(range(t0),1,key=lambda x:0 if check(x) else 1)-1 print(b if b>=0 else -1)
2000G
wrong_submission
276,328,251
C++20 (GCC 13-64)
TIME_LIMIT_EXCEEDED on test 15
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int,int> pii; typedef pair<double, double> pdd; #define pb push_back #define mp make_pair #define fs first #define sc second #define rep(i, from, to) for (int i = from; i < (to); ++i) #define all(x) x.begin(), x.end() #define sz(x) (int)(x).size() #define FOR(i, to) for (int i = 0; i < (to); ++i) typedef vector<vector<int> > vvi; typedef vector<ll> vll; typedef vector<vll> vvll; typedef vector<pair<int, int> > vpi; typedef pair<ll,ll> pll; typedef vector<string> vs; #define inf 1000000000LL*10000000 class Graph { public: int Nx; vector<ll> d, viz; vector<vector<pll>> g; Graph(int n): Nx(n), d(n+1, inf), viz(n+1, 0), g(n+1) {} void addEdge(int x, int y, ll cost) { g[x].push_back({y, cost}); } vll runDijkstra(const vector<int>& s) { priority_queue<pll, vector<pll>, greater<pll>> pq; for (int i = 0; i <= Nx; ++i) d[i] = inf; fill(viz.begin(), viz.end(), 0); for (int x : s) { d[x] = 0; pq.push({0, x}); } while (!pq.empty()) { ll x = pq.top().second; pq.pop(); if (viz[x]) continue; viz[x] = 1; for (const auto& a : g[x]) { ll y = a.first, c = a.second; if (d[y] > d[x] + c) { d[y] = d[x] + c; pq.push({d[y], y}); } } } return d; } vll runDijkstra(int s) { return runDijkstra(vector<int>({s})); } }; ll t0,t1,t2; vector<pair<ll,pii>> ge1,ge2; int N,M; int check(int start) { Graph g1(N+1), g2(N+1); for (auto e : ge1) { g1.addEdge(e.sc.fs, e.sc.sc, e.fs); } for (auto e : ge2) { g2.addEdge(e.sc.fs, e.sc.sc, e.fs); } g1.addEdge(0, 1, start); vll d1 = g1.runDijkstra(0); vll d2 = g1.runDijkstra(N); for (int i=1;i<=N;++i) { if (d1[i] <= t0) { g2.addEdge(0, i, d1[i]); } } g2.addEdge(0, 1, start); vll d3 = g2.runDijkstra(0); for (int i=1;i<=N;++i) { //cout << d2[i] << " " << max(t1, d3[i]) << " " << i << endl; if (d2[i] + max(t1, d3[i]) <= t2) { return 1; } } return 0; } int main() { cin.sync_with_stdio(0); cin.tie(0); int T; cin >> T; while(T--) { ge1.clear(); ge2.clear(); cin >> N >> M; cin >> t2 >> t0 >> t1; for (int i=1;i<=M;++i) { int x,y,c1,c2; cin >> x >> y >> c1 >> c2; ge1.pb({c1,{x,y}}); ge1.pb({c1,{y,x}}); ge2.pb({c2,{x,y}}); ge2.pb({c2,{y,x}}); } int st = 0; int dr = t2; int ret = -1; while (st <= dr) { int mid = (st+dr)/2; if (check(mid)) { ret = mid; st = mid + 1; } else { dr = mid - 1; } } cout << ret << "\n"; } }
2000G
wrong_submission
288,835,419
Java 21
TIME_LIMIT_EXCEEDED on test 15
import java.util.*; public class Main{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int i=0;i<t;i++){ int n=sc.nextInt(),m=sc.nextInt(),t0=sc.nextInt(),t1=sc.nextInt(),t2=sc.nextInt(); List<int[]> path[]=new List[n+5]; for(int j=1;j<=n;j++){ path[j]=new ArrayList<>(); } for(int j=0;j<m;j++){ int u=sc.nextInt(),v=sc.nextInt(),l1=sc.nextInt(),l2=sc.nextInt(); path[u].add(new int[]{v,l1,l2}); path[v].add(new int[]{u,l1,l2}); } if(find(n,0,path,t1,t2)>t0){ System.out.println("-1"); } else{ int l=0,r=(int)1e9; while(l<r){ int mid=(l+r)>>1; if(find(n,mid,path,t1,t2)<=t0){ l=mid; } else{ r=mid-1; } if(l==r-1){ if(find(n,r,path,t1,t2)<=t0){ l=r; } break; } } System.out.println(l); } } } static long find(int n,int start,List<int[]> path[],int t1,int t2){ Queue<long[]> q=new PriorityQueue<>((a,b)->Long.compare(a[1],b[1])); long dis[]=new long[n+5]; Arrays.fill(dis,(long)1e18); dis[1]=start; q.add(new long[]{1,start}); while(!q.isEmpty()){ long a[]=q.poll(); if(dis[(int)a[0]]<a[1]){ continue; } for(int b[]:path[(int)a[0]]){ long d=a[1]+b[2]; if(dis[b[0]]>d){ q.add(new long[]{b[0],d}); dis[b[0]]=d; } d=a[1]+b[1]; if(!(d<=t1||a[1]>=t2)){ d=t2+b[1]; } if(dis[b[0]]>d){ q.add(new long[]{b[0],d}); dis[b[0]]=d; } } } return dis[n]; } }
2000G
wrong_submission
276,213,847
PyPy 3-64
TIME_LIMIT_EXCEEDED on test 15
import sys, time, random from collections import deque, Counter, defaultdict def debug(*x):print('debug:',*x, file=sys.stderr) input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) inf = 2 ** 30 - 1 mod = 998244353 import heapq def solve(): n, m = mi() graph = [[] for _ in range(n)] t0, t1, t2 = mi() for _ in range(m): a, b, c, d = mi() a -= 1 b -= 1 graph[a].append((b, c, 1)) graph[b].append((a, c, 1)) graph[a].append((b, d, 0)) graph[b].append((a, d, 0)) def check(x): dist = [inf] * n dist[0] = x hq = [(x, 0)] heapq.heapify(hq) while hq: c, now = heapq.heappop(hq) if c > dist[now]: continue for to, cost, t in graph[now]: #もしtが1であり,区間 (c, c + cost) と区間 (t1, t2) が共通部分を持つならば,t2 + cost が dist[to] より小さいならば,dist[to] を t2 + cost に更新し,hq に (dist[to], to) を追加する if t == 1 and max(c, t1) < min(c + cost, t2): if t2 + cost < dist[to]: dist[to] = t2 + cost heapq.heappush(hq, (dist[to], to)) else: if dist[now] + cost < dist[to]: dist[to] = cost + dist[now] heapq.heappush(hq, (dist[to], + to)) return dist[n - 1] <= t0 if not check(0): print(-1) return ok = 0 ng = t0 while ng - ok > 1: mid = (ok + ng) // 2 if check(mid): ok = mid else: ng = mid print(ok) for _ in range(ii()): solve()
2000G
wrong_submission
276,308,317
PyPy 3-64
TIME_LIMIT_EXCEEDED on test 15
import sys input = sys.stdin.readline import heapq def check(x): q = [(x, 0)] D[0] = x while q: a,b = heapq.heappop(q) if V[b]: V[b] = 0 for c,l1,l2 in G[b]: if V[c]: if a+l1 <= t1: if a+l1 < D[c]: D[c] = a+l1 heapq.heappush(q,(a+l1,c)) elif max(a,t2) + l1 < D[c]: D[c] = max(a,t2) + l1 heapq.heappush(q,(max(a,t2)+l1,c)) if a+l2 <= D[c]: D[c] = a+l2 heapq.heappush(q,(a+l2,c)) #print(a,b,D) #print(D,x) return D[-1] <= t0 for _ in range(int(input())): n, m = map(int, input().split()) t0,t1,t2 = map(int, input().split()) G = [[] for i in range(n)] for _ in range(m): a,b,l1,l2 = map(int, input().split()) a-=1;b-=1 G[a].append((b,l1,l2)) G[b].append((a,l1,l2)) lo = -1 hi = t0 + 1 while hi - lo > 1: V = [1] * n D = [int(1e15)] * n mid = (lo + hi) // 2 if check(mid):lo=mid else:hi=mid print(lo)
2000G
wrong_submission
276,214,637
C++14 (GCC 6-32)
WRONG_ANSWER on test 16
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define pb push_back const ld pi = 3.14159265358979323846; int mod = 998244353; ll INF = (ll)1e9; template<typename T> T chmax(T a, T b) { return a > b ? a : b; } template<typename T> T chmin(T a, T b) { return a > b ? b : a; } const int N = (int)1e6 + 1, M = N * 2; ll h[N], e[M], ne[M], w1[M], w2[M], idx, t0, t1, t2; void add(ll u, ll v, ll c1, ll c2){ e[idx] = v, w1[idx] = c1, w2[idx] = c2, ne[idx] = h[u], h[u] = idx++; } void solve(){ int n, m; cin >> n >> m; for(int i = 0; i <= n; i++){ h[i] = -1; } idx = 0; cin >> t0 >> t1 >> t2; for(int i = 0; i < m; i++){ ll u, v, l1, l2; cin >> u >> v >> l1 >> l2; add(u, v, l1, l2); add(v, u, l1, l2); } ll l = 0, r = t0, qwq = -1; while(l < r){ ll mid = l + r >> 1; ll f[n + 1], v[n + 1]; for(int i = 0; i <= n; i++){ f[i] = INF; v[i] = 0; } priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<>> q; f[1] = mid; q.push({f[1], 1}); while(!q.empty()){ auto p = q.top(); q.pop(); int u = p.second; if(v[u]) continue; v[u] = 1; for(int i = h[u]; i != -1; i = ne[i]){ int j = e[i]; if(f[u] >= t1 && f[u] < t2){ if(f[j] > f[u] + chmin(1ll * w2[i], t2 - f[u] + w1[i])){ f[j] = f[u] + chmin(1ll * w2[i], t2 - f[u] + w1[i]); q.push({f[j], j}); } } else if(f[u] + w1[i] > t1 && f[u] < t2){ if(f[j] > f[u] + chmin(1ll * w2[i], t1 - f[u] + t2 - t1 + w1[i])){ f[j] = f[u] + chmin(1ll * w2[i], t1 - f[u] + t2 - t1 + w1[i]); q.push({f[j], j}); } } else{ if(f[j] > f[u] + w1[i]){ f[j] = f[u] + w1[i]; q.push({f[j], j}); } } } } if(f[n] <= t0){ qwq = chmax(qwq, 1ll * mid); l = mid + 1; } else r = mid; } cout << (qwq == 1e18 ? -1 : qwq) << endl; } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(0); int t = 1; cin >> t; while (t--) { solve(); } return 0; }
2000G
wrong_submission
276,340,093
PyPy 3-64
TIME_LIMIT_EXCEEDED on test 16
# https://codeforces.com/contest/2000 import sys from heapq import heappush, heappop input = lambda: sys.stdin.readline().rstrip() # faster! INF = 10 ** 18 def dijkstra(n, adj, start, finish, t_start, t1, t2): dist = [INF] * n dist[start] = t_start queue = [] heappush(queue, (t_start, start)) while queue: d, v = heappop(queue) if d == dist[v]: for u, l1, l2 in adj[v]: if d + l1 <= t1 or d >= t2: if d + l1 < dist[u]: dist[u] = d + l1 heappush(queue, (d + l1, u)) else: if d + l2 < dist[u]: dist[u] = d + l2 heappush(queue, (d + l2, u)) if t2 + l1 < dist[u]: dist[u] = t2 + l1 heappush(queue, (t2 + l1, u)) return dist[finish] def solve_case(): n, m = map(int, input().split()) # 2 <= n <= 10**5, 1 <= m <= 10**5 t0, t1, t2 = map(int, input().split()) # t1 < t2 < t0 adj = [[] for _ in range(n)] for _ in range(m): u, v, l1, l2 = map(int, input().split()) u -= 1 v -= 1 adj[u] += [(v, l1, l2)] adj[v] += [(u, l1, l2)] start = 0 finish = n - 1 tn = dijkstra(n, adj, start, finish, 0, t1, t2) if tn > t0: return -1 lo, hi = 0, t0 while lo + 1 < hi: mid = (lo + hi) // 2 tn = dijkstra(n, adj, start, finish, mid, t1, t2) if tn <= t0: lo = mid else: hi = mid return lo ans = [] for _ in range(int(input())): ans += [str(solve_case())] print("\n".join(ans))
2000G
wrong_submission
277,101,156
PyPy 3-64
TIME_LIMIT_EXCEEDED on test 16
import sys,os import random from math import * from string import ascii_lowercase,ascii_uppercase from collections import Counter, defaultdict, deque from itertools import accumulate, combinations, permutations from heapq import heappushpop, heapify, heappop, heappush from bisect import bisect_left,bisect_right from types import GeneratorType from random import randint RANDOM = randint(1, 10 ** 10) class op(int): def __init__(self, x): int.__init__(x) def __hash__(self): return super(op, self).__hash__() ^ RANDOM def bootstrap(f, stack=[]): def wrappedfunc(*args, **kwargs): if stack: return f(*args, **kwargs) else: to = f(*args, **kwargs) while True: if type(to) is GeneratorType: stack.append(to) to = next(to) else: stack.pop() if not stack: break to = stack[-1].send(to) return to return wrappedfunc inp = lambda: sys.stdin.buffer.readline().decode().strip() out=sys.stdout.write def S(): return inp() def I(): return int(inp()) def F(): return float(inp()) def MI(): return map(int, inp().split()) def MF(): return map(float, inp().split()) def MS(): return inp().split() def LS(): return list(inp().split()) def LI(): return list(map(int,inp().split())) def LF(): return list(map(float,inp().split())) def Query(i,j): print3('?', i, j) sys.stdout.flush() qi=I() return qi def print1(x): return out(str(x)+"\n") def print2(x,y): return out(str(x)+" "+str(y)+"\n") def print3(x,y,z): return out(str(x)+" "+str(y)+" "+str(z)+"\n") def print_arr(arr): for num in arr: out(str(num)+" ") out(str("\n")) def solve(st): heap,dist=[],[sys.maxsize]*n dist[0]=st heappush(heap,(st,0)) while heap: time,node=heappop(heap) if node==n-1: return time<=t0 for nei,l1,l2 in graph[node]: #check and perform way 1 new_time=time+l1 if not ((t1<new_time<t2) or (time<=t1 and new_time>=t2) or t1<time<t2): if new_time<dist[nei]: dist[nei]=new_time heappush(heap,(new_time,nei)) else: #way 2 new_time=time+l2 if new_time<dist[nei]: dist[nei]=new_time heappush(heap,(new_time,nei)) #a valid way 1 new_time=t2+l1 if new_time<dist[nei]: dist[nei]=new_time heappush(heap,(new_time,nei)) return dist[n-1]<=t0 for _ in range(I()): n,m=MI() t0,t1,t2=MI() graph=[[] for _ in range(n)] for _ in range(m): u,v,l1,l2=MI() u,v=u-1,v-1 graph[u].append((v,l1,l2)) graph[v].append((u,l1,l2)) ans=-sys.maxsize l,h=0,t1 while l<h: mid=(l+h+1)>>1 if solve(mid): l=mid else: h=mid-1 if solve(l): ans=max(ans,l) l,h=t1+1,t2-1 while l<h: mid=(l+h+1)>>1 if solve(mid): l=mid else: h=mid-1 if solve(l): ans=max(ans,l) l,h=t2,10**9+5 while l<h: mid=(l+h+1)>>1 if solve(mid): l=mid else: h=mid-1 if solve(l): ans=max(ans,l) print1(-1 if ans==-sys.maxsize else ans)
2000G
wrong_submission
276,354,067
C++20 (GCC 13-64)
TIME_LIMIT_EXCEEDED on test 17
// cpp long long #include <bits/stdc++.h> using namespace std; #define int long long #define u64 unsigned long long #define rep(i, a, n) for (int i = a; i <= n; i++) #define rept(i, a, n, t) for (int i = a; i <= n; i += t) #define per(i, a, n) for (int i = n; i >= a; i--) #define pert(i, a, n, t) for (int i = n; i >= a; i -= t) #define pb push_back #define SZ(v) ((int)v.size()) #define fs first #define sc second #define all(x) x.begin(), x.end() typedef long long ll; typedef double db; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<vi> vvi; const int N = 200005; const int M = 200005; int h[N], nex[M], to[M], la[M], lb[M], ee; #define ef(i, y, x) for (int i = h[x], y = to[i]; i; i = nex[i], y = to[i]) void add(int x, int y, int v, int w) { nex[++ee] = h[x]; to[ee] = y; la[ee] = v; lb[ee] = w; h[x] = ee; } struct e{ int l, r; bool operator < (const e &t) const { return l > t.l; } }; // bool cmp(e x, e y) { // return x.l < y.l; // } priority_queue<e> q; int n, m, t0, t1, t2; int d[N]; const int inf = 1e9; void solve() { ee = 0; cin >> n >> m >> t0 >> t1 >> t2; rep(i, 1, n) { d[i] = -inf; h[i] = 0; } rep(i, 1, m) { int x, y, v, w; cin >> x >> y >> v >> w; add(x, y, v, w); add(y, x, v, w); } d[n] = t0; q.push(e{t0, n}); while (!q.empty()) { int w = q.top().l, x = q.top().r; q.pop(); if (w > d[x]) continue; ef(i, y, x) { int v = w - la[i]; if (!(v >= t2 || w <= t1)) { v = t1 - la[i]; } v = max(w - lb[i], v); if (d[y] < v) { d[y] = v; q.push(e{v, y}); } } } // rep(i, 1, n) cout << d[i] << " \n"[i == n]; int res = d[1]; if (res < 0) cout << -1 << "\n"; else cout << res << "\n"; } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while(T--) solve(); return 0; }
2000G
wrong_submission
277,106,242
C++20 (GCC 13-64)
TIME_LIMIT_EXCEEDED on test 17
// Sinner, How you do what you do? #include <bits/stdc++.h> #include <fstream> #include <ext/pb_ds/assoc_container.hpp> #include <chrono> #include <format> using namespace std::chrono; using namespace std; using namespace __gnu_pbds; using ll = long long; #define int long long const int N = 1e5 + 5, maxN = 1e7 + 1; const int blockSize = 320; const int mod = 1e9 + 7, LOG = 20; void fast() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } vector<vector<int>> neighbourNodes[N]; int solve() { int n, m, eventStart, startCall, endCall; cin >> n >> m; cin >> eventStart >> startCall >> endCall; for (int i = 0; i < n; ++i) { neighbourNodes[i].clear(); } for (int i = 0; i < m; ++i) { int path, toPath, durationBus, durationWalk; cin >> path >> toPath >> durationBus >> durationWalk; path--, toPath--; neighbourNodes[path].push_back({toPath, durationBus, durationWalk}); neighbourNodes[toPath].push_back({path, durationBus, durationWalk}); } int leftPointer = 0, rightPointer = eventStart; int ans = -1; function<bool(int startTime)> isValid= [&](int startTime) -> bool { priority_queue<pair<int, int>> pq; vector<vector<int>> arrivalTime(n, vector<int>(2, INT32_MAX)); pq.push({-startTime, 0}); arrivalTime[0][startTime >= endCall] = startTime; while(!pq.empty()) { auto [currTime, currNode] = pq.top(); currTime *= -1; pq.pop(); for(auto &v : neighbourNodes[currNode]) { int node = v[0], durationBus = v[1], durationWalk = v[2]; if(currTime + durationWalk <= startCall || currTime >= endCall) { int endTime = currTime + durationBus; bool newState = endTime >= endCall; if(arrivalTime[node][newState] > endTime) arrivalTime[node][newState] = endTime, pq.push({-endTime, node}); continue; } if((endCall >= currTime && currTime >= startCall) || (currTime + durationBus > startCall)) { for(int endTime : {currTime + durationWalk, endCall + durationBus}) { bool newState = endTime >= endCall; if(arrivalTime[node][newState] > endTime) arrivalTime[node][newState] = endTime, pq.push({-endTime, node}); } continue; } for(int endTime : {currTime + durationBus, currTime + durationWalk, endCall + durationBus}) { bool newState = endTime >= endCall; if(arrivalTime[node][newState] > endTime) arrivalTime[node][newState] = endTime, pq.push({-endTime, node}); } } } return arrivalTime[n - 1][1] <= eventStart || arrivalTime[n - 1][0] <= endCall; }; while(rightPointer >= leftPointer) { int middlePointer = (leftPointer + rightPointer) / 2; if (isValid(middlePointer)) { ans = middlePointer; leftPointer = middlePointer + 1; } else { rightPointer = middlePointer - 1; } } return ans; } int32_t main() { fast(); int t; cin >> t; while(t--) cout << solve() << "\n"; }
2000G
wrong_submission
293,568,323
C++17 (GCC 7-32)
TIME_LIMIT_EXCEEDED on test 17
// Source: https://usaco.guide/general/io #include <bits/stdc++.h> using namespace std; #define MAXN 100100 #define MOD 1e9 + 7 typedef long long ll; typedef pair<int, ll> pi; typedef vector<int> vi; struct edge { int v; ll l1, l2; }; vector<edge> adj[MAXN]; priority_queue<pi , vector<pi>, greater<pi>> pq; ll dist[MAXN]; ll solve(ll cur, ll start, ll end, int n) { for (int i = 1; i <= n; i++) dist[i] = 1e12; dist[1] = cur; pq.push({1, cur}); while (pq.size()) { pi u = pq.top(); pq.pop(); for (edge v : adj[u.first]) { ll temp = v.l2 + u.second; ll len = dist[u.first]; if (len + v.l1 > start && len < end) { temp = min(temp, end + v.l1); } else { temp = min(temp, len + v.l1); } if (temp < dist[v.v]) { dist[v.v] = temp; pq.push({v.v, temp}); } } } return dist[n]; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int tt; cin >> tt; while (tt--) { // being earlier is always better so bs int n, m; cin >> n >> m; ll fin, start, end; cin >> fin >> start >> end; for (int i = 1; i <= n; i++) adj[i].clear(); for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; ll l1, l2; cin >> l1 >> l2; adj[u].push_back({v, l1, l2}); adj[v].push_back({u, l1, l2}); } ll lo = 0, hi = fin; ll ans = -1; while (lo <= hi) { ll md = (lo + hi)/2; bool pos = (solve(md, start, end, n) <= fin); if (pos) { ans = max(ans, md); lo = md+1; } else { hi = md-1; } } cout << ans << "\n"; } }
2000G
wrong_submission
276,472,230
C++20 (GCC 13-64)
TIME_LIMIT_EXCEEDED on test 17
#pragma GCC optimize(3,"Ofast","inline") #pragma GCC optimize(2) #pragma GCC optimize("O3,unroll-loops") #include<bits/stdc++.h> #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define int long long using ll = long long; using LL = long long; using i64 = long long; // #define double long double #define endl '\n' #define all(x) (x).begin(), (x).end() #define lowbit(x) (x & (-(x))) constexpr ll mod = 998244353; constexpr ll inf = 1e17 + 7; constexpr int M = 2e5 + 3; const int N = 2e6 + 10; const double eps = 1e-9; const double pi = acos(-1); void slove(){ int n, m; cin >> n >> m; array<int, 3> t; for(int i = 0;i < 3;++i) cin >> t[i]; vector<array<int, 3>> edge[n + 1]; for(int i = 1;i <= m;++i) { int u, v, l, r; cin >> u >> v >> l >> r; edge[u].emplace_back(array<int, 3>{v, l, r}); edge[v].emplace_back(array<int, 3>{u, l, r}); } auto get = [&](int x)->int{ return t[1] <= x and x < t[2]; }; auto check = [&](int x)->int{ priority_queue<array<int, 3>, vector<array<int, 3>>, greater<>> que; vector<array<int, 2>> dis(n + 1); fill(all(dis), array<int, 2>{inf, inf}); dis[1][get(x)] = x; que.push({x, 1, get(x)}); while(que.size()) { auto [w, u, s] = que.top(); que.pop(); // if(dis[u][s] != w) continue; if(dis[u][0] > t[2] and t[2] >= w) dis[u][0] = t[2], que.push({t[2], u, 0});// cout << (x == 2) << ' ' << t[2] << ' ' << u << ' ' << w << endl; // if(dis[u][1] > t[1] and t[1] >= w) dis[u][1] = t[1], que.push({t[1], u, 1}); if(dis[n][0] <= t[0]) return true; for(auto& [v, l, r] : edge[u]) { // if(x == 2 and u == 4 and w == 6) cout << w << ' ' << v << ' ' << l << ' ' << r << endl; if(dis[v][get(w + r)] > w + r) dis[v][get(w + r)] = w + r, que.push({w + r, v, get(w + r)}); if(w < t[2] and dis[v][get(t[2] + l)] > t[2] + l) dis[v][get(t[2] + l)] = t[2] + l, que.push({t[2] + l, v, get(t[2] + l)}); if (dis[v][get(w + l)] > w + l) { if((w + l != t[1] and get(w + l)) or s) continue; if(w < t[1] and t[2] <= w + l) continue; // cout << w + l << ' ' << l << endl; dis[v][get(w + l)] = w + l; que.push({w + l, v, get(w + l)}); } } } return dis[n][0] <= t[0]; }; int l = -1, r = t[0] + t[0]; while(l + 1 < r) { int mid = (l + r) / 2; if(check(mid)) l = mid; else r = mid; } //for(int i = 1;i <= 8;++i) // cout << check(i) << "#"; cout << l << endl; } signed main(){ cin.tie(0)->sync_with_stdio(false); cout << fixed << setprecision(15); int t = 1; cin >> t; // comb.init(200005); // init(); while(t--) slove(); return 0; }
2000G
wrong_submission
277,978,229
Java 8
TIME_LIMIT_EXCEEDED on test 17
import java.io.*; import java.util.*; public class CallDuringTheJourney { public static PrintWriter out; public static void main(String[] args)throws IOException{ JS sc=new JS(); out=new PrintWriter(System.out); int t=sc.nextInt(); outer: while(t-->0) { int n=sc.nextInt(); int m=sc.nextInt(); int t0=sc.nextInt(); int t1=sc.nextInt(); int t2=sc.nextInt(); ArrayList<ArrayList<Triple>>al=new ArrayList<>(); for(int i=0;i<n;i++) { al.add(new ArrayList<Triple>()); } for(int i=0;i<m;i++) { int a=sc.nextInt()-1; int b=sc.nextInt()-1; int bus=sc.nextInt(); int walk=sc.nextInt(); al.get(a).add(new Triple(b, bus, walk)); al.get(b).add(new Triple(a, bus, walk)); } int dist[]=new int[n]; Arrays.fill(dist, (int) -1e9); dist[n-1]=t0; PriorityQueue<Integer>q=new PriorityQueue<>((Integer p1,Integer p2)->Integer.compare(dist[p1],dist[p2])); // ArrayDeque<Integer>q=new ArrayDeque<>(); q.add(n-1); while(!q.isEmpty()) { int cur=q.poll(); for(Triple next:al.get(cur)) { int nexttime=dist[cur]-next.bus; if(nexttime>=t2||dist[cur]<=t1) { nexttime=dist[cur]-next.bus; }else { nexttime=dist[cur]-next.walk; nexttime=Math.max(nexttime, t1-next.bus); } if(dist[next.node]<nexttime) { dist[next.node]=nexttime; q.add(next.node); } } } out.println(dist[0]>=0?dist[0]:-1); } out.close(); } static void add(HashMap<Integer,Integer> A, int key){ A.put(key,A.getOrDefault(key,0)+1); } static void remove(HashMap<Integer,Integer>A, int key){ if(!A.containsKey(key))return; A.put(key,A.get(key)-1); if(A.get(key)==0){ A.remove(key); } } static class Pair implements Comparable<Pair>{ int x, y; public Pair(int x, int y) { this.x=x;this.y=y; } public int compareTo(Pair p) { if(y==p.y) { return Integer.compare(x, p.x); } return Integer.compare(y, p.y); } } static class Triple{ int node, bus, walk; public Triple(int node, int bus, int walk) { this.node=node;this.bus=bus;this.walk=walk; } } static void sort(int a[]) { ArrayList<Integer>al=new ArrayList<>(); for(int i=0;i<a.length;i++) { al.add(a[i]); } Collections.sort(al); for(int i=0;i<a.length;i++) { a[i]=al.get(i); } } static class JS { public int BS = 1<<16; public char NC = (char)0; byte[] buf = new byte[BS]; int bId = 0, size = 0; char c = NC; double num = 1; BufferedInputStream in; public JS() { in = new BufferedInputStream(System.in, BS); } public JS(String s) throws FileNotFoundException { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } public char nextChar(){ while(bId==size) { try { size = in.read(buf); }catch(Exception e) { return NC; } if(size==-1)return NC; bId=0; } return (char)buf[bId++]; } public int nextInt() { return (int)nextLong(); } public long nextLong() { num=1; boolean neg = false; if(c==NC)c=nextChar(); for(;(c<'0' || c>'9'); c = nextChar()) { if(c=='-')neg=true; } long res = 0; for(; c>='0' && c <='9'; c=nextChar()) { res = (res<<3)+(res<<1)+c-'0'; num*=10; } return neg?-res:res; } public double nextDouble() { double cur = nextLong(); return c!='.' ? cur:cur+nextLong()/num; } public String next() { StringBuilder res = new StringBuilder(); while(c<=32)c=nextChar(); while(c>32) { res.append(c); c=nextChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while(c<=32)c=nextChar(); while(c!='\n') { res.append(c); c=nextChar(); } return res.toString(); } public boolean hasNext() { if(c>32)return true; while(true) { c=nextChar(); if(c==NC)return false; else if(c>32)return true; } } } }
2000G
wrong_submission
276,841,561
Java 21
TIME_LIMIT_EXCEEDED on test 17
// package Codeforces; import java.util.*; public class CallDuringTheJourney { final static Scanner sc = new Scanner(System.in); public static void main(String[] args) { int testcases = sc.nextInt(); for (int test = 0; test<testcases; ++test) { int n = sc.nextInt(); int m = sc.nextInt(); Graph g = new Graph(n, m); int t0 = sc.nextInt(); int t1 = sc.nextInt(); int t2 = sc.nextInt(); for(int i=0; i<m; ++i){ int u = sc.nextInt(); int v = sc.nextInt(); int bussTime = sc.nextInt(); int walkTime = sc.nextInt(); g.createEdge(u, v, bussTime, walkTime); } int result = findTimeToReach(g, t0, t1, t2); System.out.println(result); } } private static int findTimeToReach(Graph g, int t0, int t1, int t2){ g.populateMaxTimeToReach(t0, t1, t2); return g.nodes.get(0).maxTimeTorReach; } private static boolean isOverlappingInterval(int busTime, int maxTimeTorReach, int t1, int t2) { return (t2 > busTime && t1 < maxTimeTorReach); } public static class Graph{ List<Node> nodes; List<Edge> edges; Map<Node, List<Edge>> adjacencyList; static int edgeid = 0; int N; int M; Graph(int N, int M){ this.N = N; this.M = M; nodes = new ArrayList<Node>(); edges = new ArrayList<>(); adjacencyList = new HashMap<>(); for(int i = 0; i < N; i++){ Node u = new Node(i); nodes.add(u); adjacencyList.put(u, new ArrayList<>()); } } void populateMaxTimeToReach(int t0, int t1, int t2){ nodes.get(N-1).maxTimeTorReach = t0; PriorityQueue<Graph.Node> pq = new PriorityQueue<>(); pq.add(nodes.get(N-1)); int walkTime, busTime, currentBestTime; while(!pq.isEmpty()){ Graph.Node node = pq.poll(); if(node.maxTimeTorReach < 0) break; for(Graph.Edge edge: adjacencyList.get(node)){ Graph.Node neib = edge.u; if(edge.u.id == node.id){ neib = edge.v; } walkTime = node.maxTimeTorReach - edge.walkTime; busTime = node.maxTimeTorReach - edge.busTime; if(isOverlappingInterval(busTime, node.maxTimeTorReach, t1, t2)){ busTime = t1 - edge.busTime; } currentBestTime = Math.max(walkTime, busTime); if(neib.maxTimeTorReach < currentBestTime){ neib.maxTimeTorReach = currentBestTime; pq.add(neib); } } } } public static class Node implements Comparable<Node>{ int id; int maxTimeTorReach; Node(int id){ this.id = id; this.maxTimeTorReach = -1; } @Override public int compareTo(Node o) { return this.maxTimeTorReach - o.maxTimeTorReach; } } public static class Edge{ int id; Node u; Node v; int walkTime; int busTime; public Edge(Node u, Node v, int walkTime, int busTime) { this.u = u; this.v = v; this.walkTime = walkTime; this.busTime = busTime; this.id = edgeid; edgeid++; } } void createEdge(int u, int v, int busTime, int walkTime){ u--; v--; Node uNode = nodes.get(u); Node vNode = nodes.get(v); Edge edge = new Edge(uNode, vNode, walkTime, busTime); adjacencyList.get(uNode).add(edge); adjacencyList.get(vNode).add(edge); } } }
2000G
wrong_submission
277,024,637
PyPy 3-64
TIME_LIMIT_EXCEEDED on test 17
import queue for _ in range(int(input())): n, m = map(int, input().split()) t0, t1, t2 = map(int, input().split()) g = [[] for _ in range(n+1)] dis = [int(-1e9) for _ in range(n+1)] def dijkstra(): dis[n] = t0 q = queue.PriorityQueue() q.put((t0, n)) while q.qsize() != 0: p = q.get() u = p[1] if dis[u] == int(-1e9): continue SIZE = len(g[u]) for i in range(SIZE): v, l1, l2 = g[u][i][0], g[u][i][1], g[u][i][2] if dis[u] - l1 >= t2 or dis[u] <= t1: d = dis[u] - l1 else: d = dis[u] - l2 if d == dis[u] - l2: d = max(d, t1 - l1) if dis[v] < d: dis[v] = d q.put((dis[v], v)) for _ in range(m): u, v, l1, l2 = map(int, input().split()) g[u].append([v, l1, l2]) g[v].append([u, l1, l2]) dijkstra() if dis[1] >= 0: print(dis[1]) else: print(-1)
2000G
wrong_submission
276,537,510
PyPy 3-64
TIME_LIMIT_EXCEEDED on test 17
def bin_vstavka(mas, x): global time if len(mas) == 0: return 0 if time[mas[0] - 1] >= time[x - 1]: return 0 if time[mas[-1] - 1] <= time[x - 1]: return len(mas) l = 0 r = len(mas) while r - l > 1: m = (r + l) // 2 if time[x - 1] > time[mas[m] - 1]: l = m else: r = m return l + 1 for t in range(int(input())): n, m = map(int, input().split()) t0, t1, t2 = map(int, input().split()) graf = {} for i in range(1, n + 1): graf[i] = set() for i in range(m): x, y, l1, l2 = map(int, input().split()) graf[x].add((y, l1, l2)) graf[y].add((x, l1, l2)) l = -1 r = t0 + 1 while r - l > 1: mid = (r + l) // 2 time = [mid] + [10 ** 17] * (n - 1) ochered = [1] while len(ochered) > 0: now = ochered.pop() for nextt in graf[now]: if (time[now - 1] <= t1 < time[now - 1] + nextt[1]) or (time[now - 1] < t2 <= time[now - 1] + nextt[1]) or (t1 <= time[now - 1] and t2 >= time[now - 1] + nextt[1]): time_plus = min(t2 + nextt[1], time[now - 1] + nextt[2]) else: time_plus = time[now - 1] + nextt[1] if time_plus < time[nextt[0] - 1]: time[nextt[0] - 1] = time_plus pos = bin_vstavka(ochered, nextt[0]) ochered.insert(pos, nextt[0]) if time[-1] > t0: r = mid else: l = mid print(l)
2000G
wrong_submission
277,096,675
Python 3
TIME_LIMIT_EXCEEDED on test 17
for test in range(int(input())): n, m = [int(i) for i in input().split()] t0, t1, t2 = [int(i) for i in input().split()] G = dict() for i in range(m): #made graph start, end, bus, walk = [int(i) for i in input().split()] if start not in G: G[start] = [[end,(bus,walk)]] else: G[start].append([end,(bus,walk)]) if end not in G: G[end] = [[start,(bus,walk)]] else: G[end].append([start,(bus,walk)]) #Djikstras from the end (node n) to start (node 1) using latest, latest[n]=t0 #if he can ride bus (not on call), ride bus #else choose max (starting time) of walking and waiting for call to end then ride bus latest = [-1]*(n)+[t0] cur = n; vis = []; frontier = [n] while True: #if cur=k, then we have the shortest path to k cur = frontier[0] #pick largest time for i in frontier: if latest[i] > latest[cur]: cur = i if cur == 1: break frontier.remove(cur) vis.append(cur) for prev, time in G[cur]: if prev in vis: continue bus = time[0]; walk = time[1] a = latest[cur] if (t2 <= a - bus) or (t1 >= a): #can ride bus latest[prev] = max(latest[prev], a - bus) else: latest[prev] = max(latest[prev], t1 - bus, a - walk) if prev not in frontier: frontier.append(prev) print(latest[1])
2000G
wrong_submission
277,101,253
PyPy 3-64
TIME_LIMIT_EXCEEDED on test 17
# Created by Ketan_Raut # Copyright © 2024 iN_siDious. All rights reserved. import sys,os import random from math import * from string import ascii_lowercase,ascii_uppercase from collections import Counter, defaultdict, deque from itertools import accumulate, combinations, permutations from heapq import heappushpop, heapify, heappop, heappush from bisect import bisect_left,bisect_right from types import GeneratorType from random import randint RANDOM = randint(1, 10 ** 10) class op(int): def __init__(self, x): int.__init__(x) def __hash__(self): return super(op, self).__hash__() ^ RANDOM def bootstrap(f, stack=[]): def wrappedfunc(*args, **kwargs): if stack: return f(*args, **kwargs) else: to = f(*args, **kwargs) while True: if type(to) is GeneratorType: stack.append(to) to = next(to) else: stack.pop() if not stack: break to = stack[-1].send(to) return to return wrappedfunc inp = lambda: sys.stdin.buffer.readline().decode().strip() out=sys.stdout.write def S(): return inp() def I(): return int(inp()) def F(): return float(inp()) def MI(): return map(int, inp().split()) def MF(): return map(float, inp().split()) def MS(): return inp().split() def LS(): return list(inp().split()) def LI(): return list(map(int,inp().split())) def LF(): return list(map(float,inp().split())) def Query(i,j): print3('?', i, j) sys.stdout.flush() qi=I() return qi def print1(x): return out(str(x)+"\n") def print2(x,y): return out(str(x)+" "+str(y)+"\n") def print3(x,y,z): return out(str(x)+" "+str(y)+" "+str(z)+"\n") def print_arr(arr): for num in arr: out(str(num)+" ") out(str("\n")) def solve(st): heap,dist=[],[sys.maxsize]*n dist[0]=st heappush(heap,(st,0)) while heap: time,node=heappop(heap) if node==n-1: return time<=t0 for nei,l1,l2 in graph[node]: #check and perform way 1 new_time=time+l1 if not ((t1<new_time<t2) or (time<=t1 and new_time>=t2) or t1<time<t2): if new_time<dist[nei]: dist[nei]=new_time heappush(heap,(new_time,nei)) else: #way 2 new_time=time+l2 if new_time<dist[nei]: dist[nei]=new_time heappush(heap,(new_time,nei)) #a valid way 1 new_time=t2+l1 if new_time<dist[nei]: dist[nei]=new_time heappush(heap,(new_time,nei)) return dist[n-1]<=t0 for _ in range(I()): n,m=MI() t0,t1,t2=MI() graph=[[] for _ in range(n)] for _ in range(m): u,v,l1,l2=MI() u,v=u-1,v-1 graph[u].append((v,l1,l2)) graph[v].append((u,l1,l2)) ans=-sys.maxsize l,h=0,10**9+5 while l<h: mid=(l+h+1)>>1 if solve(mid): l=mid else: h=mid-1 if solve(l): ans=max(ans,l) print1(-1 if ans==-sys.maxsize else ans)
2000G
wrong_submission
276,954,580
C++17 (GCC 7-32)
TIME_LIMIT_EXCEEDED on test 17
#include <bits/stdc++.h> #define ll long long int #define FASTIO std::ios::sync_with_stdio(false); #define pb push_back #define mp make_pair #define pi pair <ll,ll> #define F first #define S second #define inf 1e18 #define pi pair <ll,ll> #define g(x) cout<<x<<endl #define all(x) x.begin(),x.end() #define rall(a) a.rbegin(), a.rend() #define input_from_file freopen("input.txt", "r", stdin); #define mod 1000000007ll #define sz 400005 #define bitcnt(x) __builtin_popcountll(x) #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1){ cout << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...); } ll n,m; ll to,t1,t2; vector <tuple <ll,ll,ll> > ve[sz]; bool check(ll mid){ priority_queue <pi, vector <pi>, greater <pi> > pq; vector <ll> dp(n); for(ll i=0;i<n;i++)dp[i] = inf; vector <ll> tried(n); dp[0] = mid; pq.push({dp[0], 0}); while(!pq.empty()){ auto p = pq.top(); pq.pop(); ll s = p.second; ll d = p.first; if(!tried[s] && d < t2) { tried[s] = 1; pq.push({t2, s}); } // trace(s,d); for(auto [v,lo,l1]: ve[s]){ if(d<t1 && d+lo < t1 && dp[v] > d+lo){ pq.push({d+lo, v}); dp[v] = d+lo; } else if(d < t1 && d+lo > t1){ if(dp[v] > d+l1){ pq.push({d+l1, v}); dp[v] = d+l1; } } else if(d >= t1 && d < t2){ if(dp[v] > d + l1){ pq.push({d+l1, v}); dp[v] = d+l1; } } else{ if(dp[v] > d + lo){ pq.push({d+lo, v}); dp[v] = d + lo; } } } } return dp[n-1] <= to; } void solve(){ cin >> n >> m; cin >> to >> t1 >> t2; for(ll i=0;i<n;i++){ ve[i].clear(); } for(ll i=0;i<m;i++){ ll u,v,lo,l1; cin >> u >> v >> lo >> l1; --u; --v; ve[u].emplace_back(v,lo,l1); ve[v].emplace_back(u,lo,l1); } // trace("opk"); ll lo = 0; ll hi = to; // check(0); while(hi > lo){ ll mid = (lo+hi+1)/2; // trace(lo,hi); if(check(mid)){ lo = mid; }else{ hi = mid - 1; } } if(check(lo)){ g(lo); }else { g(-1); } } int main() { #ifndef ONLINE_JUDGE input_from_file #endif FASTIO cin.tie(NULL); fflush(stdout); ll t = 1; cin >> t; for(ll tcase = 1;tcase <= t;tcase++){ solve(); } return 0; }
2000G
wrong_submission
285,748,943
C++23 (GCC 14-64, msys2)
TIME_LIMIT_EXCEEDED on test 17
// Problem: G. Call During the Journey // Contest: Codeforces - Codeforces Round 966 (Div. 3) // URL: https://codeforces.com/problemset/problem/2000/G // Memory Limit: 256 MB // Time Limit: 4000 ms // // Powered by CP Editor (https://cpeditor.org) #include<bits/stdc++.h> //#define int long long #define fi first #define se second #define PII pair<int, int> using namespace std; const int N = 2e5 + 10, M = 1e6 + 10, mod = 1e9 + 7, INF = 0x3f3f3f3f; int n, m, q, ans, s[N], dist[N]; int t0, t1, t2; struct node {int to, v1, v2;}; vector<node> e[N]; inline void dijkstra(int T) { for(int i = 1; i <= n; i ++) dist[i] = INF; priority_queue<PII, vector<PII>, greater<> > pq; pq.push({T, 1}), dist[1] = T; while(!pq.empty()) { int now = pq.top().se; pq.pop(); if(dist[now] > t0) continue; for(auto i : e[now]) { int v = i.to, w1 = i.v1, w2 = i.v2, dis = dist[v]; if(dist[now] + w1 <= t1) dis = min(dis, dist[now] + w1); else if(dist[now] >= t2) dis = min(dis, dist[now] + w1); else dis = min(dis, min(t2 + w1, dist[now] + w2)); if(dis < dist[v]) { dist[v] = dis; pq.push({dis, v}); } } } } signed main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int T; cin >> T; while(T --) { cin >> n >> m >> t0 >> t1 >> t2; for(int i = 1; i <= m; i ++) { int u, v, w1, w2; cin >> u >> v >> w1 >> w2; e[u].push_back({v, w1, w2}), e[v].push_back({u, w1, w2}); } int l = 0, r = t0, res = -1; while(l <= r) { int mid = l + r >> 1; dijkstra(mid); if(dist[n] <= t0) l = mid + 1, res = mid; else r = mid - 1; } cout << res << '\n'; for(int i = 1; i <= n; i ++) e[i].clear(); } return 0; }
2000G
wrong_submission
277,253,408
C++17 (GCC 7-32)
TIME_LIMIT_EXCEEDED on test 17
#include <bits/stdc++.h> using namespace std; #define ll long long #define db double #define ld long double #define pii pair<int,int> #define pll pair<ll,ll> #define pb push_back #define fi first #define se second #define debug(x) cout << #x << " => " << x << "\n" #define all(x) x.begin(),x.end() #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") int n,m,t0,t1,t2; vector<pair<int,pll>> adj[100010]; ll dist[100010]; bool ok(int x) { for(int i=0;i<=n;i++) dist[i]=1e18; priority_queue<pll> pq; pq.push({x,1}); dist[1]=x; bool ret=0; while(!pq.empty()) { int u=pq.top().se; pq.pop(); for(auto i : adj[u]) { ll bus=i.se.fi,walk=i.se.se; if((dist[u]<=t1 && bus+dist[u]>t1) || (t1<=dist[u] && dist[u]<=t2)) bus+=t2; else bus+=dist[u]; walk+=dist[u]; if(dist[i.fi]>bus) { dist[i.fi]=bus; pq.push({-dist[i.fi],i.fi}); } if(dist[i.fi]>walk) { dist[i.fi]=walk; pq.push({-dist[i.fi],i.fi}); } } } // for(int i=1;i<=n;i++) cout<<dist[i]<<' ';cout<<'\n'; return dist[n]<=t0; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t;cin>>t; while(t--) { cin>>n>>m>>t0>>t1>>t2; for(int i=0;i<=n;i++) adj[i].clear(); for(int i=0;i<m;i++) { int u,v,w,x;cin>>u>>v>>w>>x; adj[u].pb({v,{w,x}}); adj[v].pb({u,{w,x}}); } int l=0,r=t0,ans=-1; while(l<=r) { int mid=(l+r)/2; if(ok(mid)) l=mid+1,ans=mid; else r=mid-1; } cout<<ans<<'\n'; } return 0; }
2000G
wrong_submission
276,365,054
C++20 (GCC 13-64)
TIME_LIMIT_EXCEEDED on test 17
/***--_Mr.Turtle_--***/ #include "bits/stdc++.h" using namespace std; #define ll long long #define sz(x) (int)x.size() #define el '\n' const ll N = 2e5 + 5, mod = 1e9 + 7; void solve() { int n, m; cin >> n >> m; int a, b, c; cin >> a >> b >> c; vector<vector<vector<int>>> adj(n + 1); for (int i = 0, d, e, f, g; i < m; i++) { cin >> d >> e >> f >> g; adj[d].push_back({e, f, g}); adj[e].push_back({d, f, g}); } auto dijkstra = [&](int st) { vector<int> dis(n + 1, 2e9); dis[1] = st; priority_queue<pair<int, int>> q; q.push({-st, 1}); while (!q.empty()) { int x = q.top().first; x *= -1; int id = q.top().second; q.pop(); if(x > a || id == n) break; if (x < dis[id]) continue; for (auto i : adj[id]) { int w = i[1]; if ((c > x && x >= b) || (c >= x + w && x + w > b) || (x < b && c < x + w)) w = min(i[2], i[1] + c - x); if (dis[i[0]] > x + w) dis[i[0]] = x + w, q.push({-dis[i[0]], i[0]}); } } return (dis[n] <= a); }; int l = -1, r = a, mid; while(l < r - 1) { mid = (l + r) / 2; if(dijkstra(mid)) l = mid; else r = mid; } cout << l << el; } signed main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false), cout.tie(NULL), cin.tie(NULL); int _t = 1; cin >> _t; for (int i = 1; i <= _t; i++) { // cout << "Case #" << i << solve(); } }
2000G
wrong_submission
276,500,965
C++20 (GCC 13-64)
TIME_LIMIT_EXCEEDED on test 17
#include "bits/stdc++.h" using namespace std; #define int long long #define double long double #define TxtIO freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #define pb push_back const int mod=1e9+7; const int inf=1e18; #define sz size() #define nl cout<<'\n'; #define Yes cout<<"Yes\n"; #define No cout<<"No\n"; #define vc vector #define vi vector<int> #define pii pair<int,int> #define all(p) p.begin(),p.end() #define fri(i,n) for(int i=0;i<n;i++) #define fra(a) for(auto it:a) #define fro(i,x,y) for(int i=x;i<y;i++) #define test int _;cin>>_;while(_--) #define inp(v) for(int i=0;i<v.size();i++){cin>>v[i];} #define yn(x) if(x) cout<<"YES"<<endl; else cout<<"NO"<<endl; // #include<ext/pb_ds/assoc_container.hpp> // #include<ext/pb_ds/tag_and_trait.hpp> // using namespace __gnu_pbds; // typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbt; template<typename... T> void get(T&... args) { ((cin >> args), ...);} template<typename... T> void put(T&&... args) { ((cout << args << " "), ...);} void __print(int x) { cerr << x; } void __print(double x) { cerr << x; } void __print(char x) { cerr << "'" << x << "'"; } void __print(string x) { cerr << '"' << x << '"'; } template <typename T, typename V> void __print(const pair<T, V> &x){cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template <typename T> void __print(const T &x){int f = 0;cerr << '{';for (auto &i : x)cerr << (f++ ? "," : ""), __print(i);cerr << "}";} void _print() { cerr << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) {__print(t);if (sizeof...(v))cerr << ", ";_print(v...);} #ifndef ONLINE_JUDGE #define dbg(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define dbg(x...) #endif bool check(int t1,int t2,int tx,int ty) { if(ty<=t1||t2<=tx) return 1; return 0; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); test { int t0,t1,t2,n,m,u,v,l1,l2; get(n,m,t0,t1,t2); vc<pair<int,pii>> adj[n]; while(m--) { get(u,v,l1,l2); u--,v--; adj[u].push_back({v,{l1,l2}}); adj[v].push_back({u,{l1,l2}}); } int l=0,r=1e9,ans=-1; while(l<=r) { int mid=(l+r)/2; priority_queue<pii,vector<pii>,greater<pii>>q; vi time(n,inf); time[0]=mid; q.push({mid,0}); while(q.sz) { int i=q.top().second; int t=q.top().first; q.pop(); fra(adj[i]) { int j=it.first; int l1=it.second.first; int l2=it.second.second; if(check(t1,t2,t,t+l1)) { if(time[j]>t+l1) { time[j]=t+l1; q.push({t+l1,j}); } } else { if(time[j]>t2+l1) { time[j]=t2+l1; q.push({t2+l1,j}); } if(time[j]>t+l2) { time[j]=t+l2; q.push({t+l2,j}); } } } } if(t0-time[n-1]>=0) ans=mid,l=mid+1; else r=mid-1; } put(ans);nl } return 0; }
2000G
wrong_submission
276,512,939
C++20 (GCC 13-64)
TIME_LIMIT_EXCEEDED on test 17
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #include <random> #include <climits> #include <ctime> #include <unordered_set> #include <cassert> #define fast_io \ std::ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define f first #define s second using namespace std; typedef int ll; typedef unsigned long long ull; #define pii pair<int, int> #define pll pair<ll, ll> #define all(x) (x).begin(), (x).end() #define vec vector #define vi vector<int> #define ld long double //#define LLONG_MAX 9223372036854775807 //#define double long double #define int long long //const int mod = 1e9 + 7; struct Node { int to; int time; int type; // 0 -> ride, 1 -> walk }; vector<vector<Node> > g; int n, m; int t0, t1, t2; bool is_per(int l1, int r1, int l2, int r2) { int l_max = max(l1, l2); int r_min = min(r1, r2); return (r_min >= l_max); } bool can(int st) { priority_queue<pii, vector<pii>, greater<pii>> q; q.push({0, st}); //q.push(0); vector<int> dist(n, INT_MAX); dist[0] = st; while (!q.empty()) { int cur = q.top().f; int cur_time = dist[cur]; q.pop(); for (Node to : g[cur]) { if (to.type == 1 && dist[to.to] > dist[cur] + to.time) { dist[to.to] = dist[cur] + to.time; q.push({to.to, dist[to.to]}); } if (to.type == 0 && is_per(cur_time, cur_time + to.time, t1 + 1, t2) == 0 && dist[to.to] > dist[cur] + to.time) { dist[to.to] = dist[cur] + to.time; q.push({to.to, dist[to.to]}); } if (to.type == 0 && is_per(cur_time, cur_time + to.time, t1 + 1, t2) == 1 && dist[to.to] > t2 + to.time) {///t2 - 1 ? dist[to.to] = t2 + to.time; q.push({to.to, dist[to.to]}); } } } return (dist[n - 1] <= t0); } void solve() { cin >> n >> m; cin >> t0 >> t1 >> t2; g.resize(n); for (int i = 0;i < m;i++) { int u, v, ride, walk; cin >> u >> v >> ride >> walk; u--; v--; g[u].push_back({v, ride, 0}); g[u].push_back({v, walk, 1}); g[v].push_back({u, ride, 0}); g[v].push_back({u, walk, 1}); } //cout << can(1); int l = 0, r = 1e9; int ans = -1; while (l <= r) { int mid = (l + r) / 2; if (can(mid)) { ans = mid; l = mid + 1; } else { r = mid - 1; } } cout << ans << "\n"; g.clear(); } signed main() { #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif //freopen("express.in", "r", stdin); //freopen("express.out", "w", stdout); srand(time(NULL)); fast_io; int t = 1; cin >> t; while (t--) { solve(); } return 0; }
2000G
wrong_submission
281,542,511
C++20 (GCC 13-64)
TIME_LIMIT_EXCEEDED on test 17
#pragma GCC optimize("Ofast") #pragma GCC optimization("unroll-loops") #include<iostream> #include<iomanip> #include<algorithm> #include<vector> #include<utility> #include<set> #include<unordered_set> #include<list> #include<iterator> #include<deque> #include<queue> #include<stack> #include<set> #include<bitset> #include<random> #include<map> #include<unordered_map> #include<stdio.h> #include<complex> #include<math.h> #include<cstring> #include<chrono> #include<string> #include "ext/pb_ds/assoc_container.hpp" #include "ext/pb_ds/tree_policy.hpp" using namespace std; using namespace __gnu_pbds; template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update> ; template<class key, class value, class cmp = std::less<key>> using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>; // find_by_order(k) returns iterator to kth element starting from 0; // order_of_key(k) returns count of elements strictly smaller than k; #define inf 2e18 #define ll long long #define FAIZAN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) const ll mod = 1e9 + 7; vector<ll> sieve(int n) {int*arr = new int[n + 1](); vector<ll> vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;} ll inv(ll i) {if (i == 1) return 1; return (mod - ((mod / i) * inv(mod % i)) % mod) % mod;} ll mod_mul(ll a, ll b) {a = a % mod; b = b % mod; return (((a * b) % mod) + mod) % mod;} ll mod_add(ll a, ll b) {a = a % mod; b = b % mod; return (((a + b) % mod) + mod) % mod;} ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b);} ll ceil_div(ll a, ll b) {return a % b == 0 ? a / b : a / b + 1;} ll pwr(ll a, ll b) {a %= mod; ll res = 1; while (b > 0) {if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1;} return res;} bool isCheck(int start,int t0,int t1,int t2,vector<vector<array<int,3>>> &adj) { int n=adj.size(); vector<vector<int>> time(n,vector<int>(2,1e9+7)); priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq; if(start>t1 && start<t2) { time[0][0]=start; time[0][1]=t2; pq.push({0,0}); pq.push({0,1}); } else { time[0][0]=start; pq.push({0,0}); } while(!pq.empty()) { auto [node,isWait]=pq.top(); pq.pop(); // cout<<"node = "<<node+1<<"\n"; if(node==n-1 && time[node][isWait]<=t0) return true; for(auto x : adj[node]) { ll dist=time[node][isWait]; ll bus=dist+x[1]; if((bus>t1 && bus<t2) || (dist>t1 && dist<t2) || (dist<=t1 && bus>=t2)) { ll walk=dist+x[2]; if(walk<time[x[0]][isWait] && walk<=t0) { time[x[0]][isWait]=walk; // cout<<"time = "<<time[x[0]][isWait]<<"\n"; pq.push({x[0],isWait}); } if(isWait==0 && t2<time[node][1]) { time[node][1]=t2; pq.push({node,1}); } } else { if(bus<time[x[0]][isWait] && bus<=t0) { time[x[0]][isWait]=bus; pq.push({x[0],isWait}); } } } // for(int i=0; i<n; i++) { // cout<<"("<<(time[i][0]==inf ? -1 : time[i][0])<<","<<(time[i][1]==inf ? -1 : time[i][1])<<") "; // } // cout<<"\n"; } int ans=min(time[n-1][0],time[n-1][1]); // cout<<"ans = "<<ans<<"\n"; return ans<=t0; } int main() { FAIZAN; int t; cin>>t; while(t--) { ll n,m; cin>>n>>m; ll t0,t1,t2; cin>>t0>>t1>>t2; vector<vector<array<int,3>>> adj(n); for(int i=0; i<m; i++) { int u,v,l1,l2; cin>>u>>v>>l1>>l2; u--,v--; adj[u].push_back({v,l1,l2}); adj[v].push_back({u,l1,l2}); } int l=0,r=t0; int ans=-1; while(l<=r) { int mid=(l+r)/2; if(isCheck(mid,t0,t1,t2,adj)) { ans=mid; l=mid+1; } else { r=mid-1; } } // isCheck(50,t0,t1,t2,adj); cout<<ans<<"\n"; } return 0; }
2000G
wrong_submission
277,116,398
C++20 (GCC 13-64)
TIME_LIMIT_EXCEEDED on test 17
#include<bits/stdc++.h> #define int long long #define IOS ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL) using namespace std; const int N=1e5+1,inf=1e9; int n,m,t0,t1,t2,dis[N]; struct fy{ int v,w1,w2; }; vector<fy>E[N]; void addE(int x,int y,int z1,int z2){ E[x].push_back({y,z1,z2}); E[y].push_back({x,z1,z2}); } struct _{ int dist,id; }; bool operator < (_ x,_ y){ return x.dist>y.dist;} signed main(){ IOS; int T; cin>>T; while(T--){ cin>>n>>m>>t0>>t1>>t2; for(int i=1;i<=n;i++) E[i].clear(),dis[i]=-inf; for(int i=1,x,y,z1,z2;i<=m;i++){ cin>>x>>y>>z1>>z2; addE(x,y,z1,z2); } priority_queue<_>q; for(int i=1;i<n;i++) q.push({-inf,i}); q.push({t0,n}); dis[n]=t0; while(!q.empty()){ int d=q.top().dist,u=q.top().id; q.pop(); for(fy e:E[u]){ int v=e.v,d1=e.w1,d2=e.w2; int D=(d-d1>=t2||d<=t1)?d-d1:max(d-d2,t1-d1); if(dis[v]<D) q.push({D,v}),dis[v]=D; } } cout<<(dis[1]>=0?dis[1]:-1)<<"\n"; } return 0; }
2000G
wrong_submission
276,725,995
C++20 (GCC 13-64)
TIME_LIMIT_EXCEEDED on test 17
#include <bits/stdc++.h> using namespace std; #define ll long long #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define II ({ int a; cin>>a; a; }) #define p pair<ll, ll> struct Node { ll v, bus, walk; }; class Solution { ll n, m, eventStart, callStart, callEnd; vector<vector<Node>> g; bool isPossible(ll startTime) { priority_queue<p, vector<p>, greater<p>> pq; vector<ll> vis(n + 1, 0), time(n + 1, LLONG_MAX); pq.push({startTime, 1}); time[1] = startTime; vis[0] = 0, time[0] = 0; while (!pq.empty()) { auto [t, u] = pq.top(); pq.pop(); vis[u] = 1; for (auto [v, bus, walk] : g[u]) if (!vis[v]) { ll onCall = t >= callStart && t <= callEnd, timeTaken = LLONG_MAX; if (t < callStart && t + bus > callStart) onCall = 1; if (onCall) { if (callEnd >= t + walk) timeTaken = t + walk; else timeTaken = min(callEnd + bus, t + walk); } else timeTaken = t + bus; if (timeTaken < time[v]) { time[v] = timeTaken; pq.push({timeTaken, v}); } } } return time[n] <= eventStart; } public: ll solve() { n = II, m = II, eventStart = II, callStart = II, callEnd = II; g = vector<vector<Node>>(n + 1); for (int i = 0; i < m; i++) { ll u = II, v = II, bus = II, walk = II; Node node(v, bus, walk); g[u].push_back(node); node.v = u; g[v].push_back(node); } if (!isPossible(0)) return -1; ll l = 0, r = LLONG_MAX; while (l <= r) { ll mid = l + ((r - l) / 2); if (isPossible(mid)) l = mid + 1; else r = mid - 1; } return l - 1; } }; int main() { fast; for (int tc = II; tc; tc--) { Solution sol; cout << sol.solve() << "\n"; } return 0; }
2000G
wrong_submission
278,493,206
C++14 (GCC 6-32)
TIME_LIMIT_EXCEEDED on test 17
#include<bits/stdc++.h> #define int long long #define x first #define y second #define il inline #define em emplace #define eb emplace_back #define debug() puts("-----") using namespace std; typedef pair<int,int> pii; il int read(){ int x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9'){ if(ch=='-') f=-1; ch=getchar(); } while(ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+(ch^48),ch=getchar(); return x*f; } const int INF=1e18+7; const int N=1e5+10,M=1e5+10; int n,m; int dis[N]; bool st[N]; int t0,t1,t2; int h[N],idx=0; struct Edge{ int to,ne; int l1,l2; }e[M<<1]; il void add(int u,int v,int l1,int l2){ e[idx].l1=l1,e[idx].l2=l2,e[idx].to=v,e[idx].ne=h[u],h[u]=idx++; } il bool check(int mid){ priority_queue<pii> q; for(int i=1;i<=n;i++) dis[i]=INF,st[i]=false; dis[1]=mid,q.push({0,1}); while(!q.empty()){ int u=q.top().y; q.pop(); for(int i=h[u];i!=-1;i=e[i].ne){ int to=e[i].to; if(dis[u]+e[i].l2<dis[to]){ dis[to]=dis[u]+e[i].l2; q.push({-dis[to],to}); } if(dis[u]+e[i].l1<=t1||dis[u]>=t2){ if(dis[u]+e[i].l1<dis[to]){ dis[to]=dis[u]+e[i].l1; q.push({-dis[to],to}); } } else{ if(t2+e[i].l1<dis[to]){ dis[to]=t2+e[i].l1; q.push({-dis[to],to}); } } } } return (dis[n]<=t0); } il void solve(){ n=read(),m=read(); idx=0; t0=read(),t1=read(),t2=read(); for(int i=1;i<=n;i++) h[i]=-1; while(m--){ int u=read(),v=read(),l1=read(),l2=read(); add(u,v,l1,l2),add(v,u,l1,l2); } int l=0,r=t0,res=-1; while(l<=r){ int mid=l+r>>1; if(check(mid)) l=mid+1,res=mid; else r=mid-1; } printf("%lld\n",res); } signed main(){ int T=read(); while(T--) solve(); return 0; }
2000G
wrong_submission
277,977,617
Java 8
TIME_LIMIT_EXCEEDED on test 17
import java.io.*; import java.util.*; public class CallDuringTheJourney { public static PrintWriter out; public static void main(String[] args)throws IOException{ JS sc=new JS(); out=new PrintWriter(System.out); int t=sc.nextInt(); outer: while(t-->0) { int n=sc.nextInt(); int m=sc.nextInt(); int t0=sc.nextInt(); int t1=sc.nextInt(); int t2=sc.nextInt(); ArrayList<ArrayList<Triple>>al=new ArrayList<>(); for(int i=0;i<n;i++) { al.add(new ArrayList<Triple>()); } for(int i=0;i<m;i++) { int a=sc.nextInt()-1; int b=sc.nextInt()-1; int bus=sc.nextInt(); int walk=sc.nextInt(); al.get(a).add(new Triple(b, bus, walk)); al.get(b).add(new Triple(a, bus, walk)); } int dist[]=new int[n]; Arrays.fill(dist, (int) -1e9); dist[n-1]=t0; PriorityQueue<Integer>q=new PriorityQueue<>((q1, q2)->Integer.compare(dist[q1], dist[q2])); q.add(n-1); while(!q.isEmpty()) { int cur=q.poll(); for(Triple next:al.get(cur)) { int nexttime=dist[cur]-next.bus; if(nexttime>=t2||dist[cur]<=t1) { nexttime=dist[cur]-next.bus; }else { nexttime=dist[cur]-next.walk; nexttime=Math.max(nexttime, t1-next.bus); } if(dist[next.node]<nexttime) { dist[next.node]=nexttime; q.add(next.node); } } } out.println(dist[0]>=0?dist[0]:-1); } out.close(); } static void add(HashMap<Integer,Integer> A, int key){ A.put(key,A.getOrDefault(key,0)+1); } static void remove(HashMap<Integer,Integer>A, int key){ if(!A.containsKey(key))return; A.put(key,A.get(key)-1); if(A.get(key)==0){ A.remove(key); } } static class Pair implements Comparable<Pair>{ int x, y; public Pair(int x, int y) { this.x=x;this.y=y; } public int compareTo(Pair p) { if(y==p.y) { return Integer.compare(x, p.x); } return Integer.compare(y, p.y); } } static class Triple{ int node, bus, walk; public Triple(int node, int bus, int walk) { this.node=node;this.bus=bus;this.walk=walk; } } static void sort(int a[]) { ArrayList<Integer>al=new ArrayList<>(); for(int i=0;i<a.length;i++) { al.add(a[i]); } Collections.sort(al); for(int i=0;i<a.length;i++) { a[i]=al.get(i); } } static class JS { public int BS = 1<<16; public char NC = (char)0; byte[] buf = new byte[BS]; int bId = 0, size = 0; char c = NC; double num = 1; BufferedInputStream in; public JS() { in = new BufferedInputStream(System.in, BS); } public JS(String s) throws FileNotFoundException { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } public char nextChar(){ while(bId==size) { try { size = in.read(buf); }catch(Exception e) { return NC; } if(size==-1)return NC; bId=0; } return (char)buf[bId++]; } public int nextInt() { return (int)nextLong(); } public long nextLong() { num=1; boolean neg = false; if(c==NC)c=nextChar(); for(;(c<'0' || c>'9'); c = nextChar()) { if(c=='-')neg=true; } long res = 0; for(; c>='0' && c <='9'; c=nextChar()) { res = (res<<3)+(res<<1)+c-'0'; num*=10; } return neg?-res:res; } public double nextDouble() { double cur = nextLong(); return c!='.' ? cur:cur+nextLong()/num; } public String next() { StringBuilder res = new StringBuilder(); while(c<=32)c=nextChar(); while(c>32) { res.append(c); c=nextChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while(c<=32)c=nextChar(); while(c!='\n') { res.append(c); c=nextChar(); } return res.toString(); } public boolean hasNext() { if(c>32)return true; while(true) { c=nextChar(); if(c==NC)return false; else if(c>32)return true; } } } }
2000G
wrong_submission
276,842,425
Java 21
TIME_LIMIT_EXCEEDED on test 17
//package Codeforces; import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.LinkedList; import java.util.StringTokenizer; import java.util.TreeSet; import java.util.*; public class CallDuringTheJourney { final static Scanner sc = new Scanner(System.in); public static void main(String[] args) { new Thread(null, null, "Thread", 1 << 27) { public void run() { try { s = new FastReader(); out = new PrintWriter(new BufferedOutputStream(System.out)); solve(); out.close(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } } }.start(); } static void solve() throws Exception { int testcases = sc.nextInt(); for (int test = 0; test<testcases; ++test) { int n = sc.nextInt(); int m = sc.nextInt(); Graph g = new Graph(n, m); int t0 = sc.nextInt(); int t1 = sc.nextInt(); int t2 = sc.nextInt(); for(int i=0; i<m; ++i){ int u = sc.nextInt(); int v = sc.nextInt(); int bussTime = sc.nextInt(); int walkTime = sc.nextInt(); g.createEdge(u, v, bussTime, walkTime); } int result = findTimeToReach(g, t0, t1, t2); out.println(result); } } private static int findTimeToReach(Graph g, int t0, int t1, int t2){ g.populateMaxTimeToReach(t0, t1, t2); return g.nodes.get(0).maxTimeTorReach; } private static boolean isOverlappingInterval(int busTime, int maxTimeTorReach, int t1, int t2) { return (t2 > busTime && t1 < maxTimeTorReach); } public static class Graph{ List<Node> nodes; List<Edge> edges; Map<Node, List<Edge>> adjacencyList; static int edgeid = 0; int N; int M; Graph(int N, int M){ this.N = N; this.M = M; nodes = new ArrayList<Node>(); edges = new ArrayList<>(); adjacencyList = new HashMap<>(); for(int i = 0; i < N; i++){ Node u = new Node(i); nodes.add(u); adjacencyList.put(u, new ArrayList<>()); } } void populateMaxTimeToReach(int t0, int t1, int t2){ nodes.get(N-1).maxTimeTorReach = t0; PriorityQueue<Graph.Node> pq = new PriorityQueue<>(); pq.add(nodes.get(N-1)); int walkTime, busTime, currentBestTime; while(!pq.isEmpty()){ Graph.Node node = pq.poll(); if(node.maxTimeTorReach < 0) break; for(Graph.Edge edge: adjacencyList.get(node)){ Graph.Node neib = edge.u; if(edge.u.id == node.id){ neib = edge.v; } walkTime = node.maxTimeTorReach - edge.walkTime; busTime = node.maxTimeTorReach - edge.busTime; if(isOverlappingInterval(busTime, node.maxTimeTorReach, t1, t2)){ busTime = t1 - edge.busTime; } currentBestTime = Math.max(walkTime, busTime); if(neib.maxTimeTorReach < currentBestTime){ neib.maxTimeTorReach = currentBestTime; pq.add(neib); } } } } public static class Node implements Comparable<Node>{ int id; int maxTimeTorReach; Node(int id){ this.id = id; this.maxTimeTorReach = -1; } @Override public int compareTo(Node o) { return this.maxTimeTorReach - o.maxTimeTorReach; } } public static class Edge{ int id; Node u; Node v; int walkTime; int busTime; public Edge(Node u, Node v, int walkTime, int busTime) { this.u = u; this.v = v; this.walkTime = walkTime; this.busTime = busTime; this.id = edgeid; edgeid++; } } void createEdge(int u, int v, int busTime, int walkTime){ u--; v--; Node uNode = nodes.get(u); Node vNode = nodes.get(v); Edge edge = new Edge(uNode, vNode, walkTime, busTime); adjacencyList.get(uNode).add(edge); adjacencyList.get(vNode).add(edge); } } public static FastReader s; public static PrintWriter out; public static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } double nextDouble() { return Double.parseDouble(next()); } long nextLong() { return Long.parseLong(next()); } int[] nextIntArray(int n) { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = nextInt(); } return arr; } long[] nextLongArray(int n) { long[] arr = new long[n]; for (int i = 0; i < n; i++) { arr[i] = nextLong(); } return arr; } String nextLine() { String str = ""; try { str = br.readLine(); } catch (Exception e) { e.printStackTrace(); } return str; } } }
2000G
wrong_submission
276,842,295
Java 21
TIME_LIMIT_EXCEEDED on test 17
//package Codeforces; import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.LinkedList; import java.util.StringTokenizer; import java.util.TreeSet; import java.util.*; public class CallDuringTheJourney { final static Scanner sc = new Scanner(System.in); public static void main(String[] args) { new Thread(null, null, "Thread", 1 << 27) { public void run() { try { s = new FastReader(); out = new PrintWriter(new BufferedOutputStream(System.out)); solve(); out.close(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } } }.start(); } static void solve() throws Exception { int testcases = sc.nextInt(); for (int test = 0; test<testcases; ++test) { int n = sc.nextInt(); int m = sc.nextInt(); Graph g = new Graph(n, m); int t0 = sc.nextInt(); int t1 = sc.nextInt(); int t2 = sc.nextInt(); for(int i=0; i<m; ++i){ int u = sc.nextInt(); int v = sc.nextInt(); int bussTime = sc.nextInt(); int walkTime = sc.nextInt(); g.createEdge(u, v, bussTime, walkTime); } int result = findTimeToReach(g, t0, t1, t2); System.out.println(result); } } private static int findTimeToReach(Graph g, int t0, int t1, int t2){ g.populateMaxTimeToReach(t0, t1, t2); return g.nodes.get(0).maxTimeTorReach; } private static boolean isOverlappingInterval(int busTime, int maxTimeTorReach, int t1, int t2) { return (t2 > busTime && t1 < maxTimeTorReach); } public static class Graph{ List<Node> nodes; List<Edge> edges; Map<Node, List<Edge>> adjacencyList; static int edgeid = 0; int N; int M; Graph(int N, int M){ this.N = N; this.M = M; nodes = new ArrayList<Node>(); edges = new ArrayList<>(); adjacencyList = new HashMap<>(); for(int i = 0; i < N; i++){ Node u = new Node(i); nodes.add(u); adjacencyList.put(u, new ArrayList<>()); } } void populateMaxTimeToReach(int t0, int t1, int t2){ nodes.get(N-1).maxTimeTorReach = t0; PriorityQueue<Graph.Node> pq = new PriorityQueue<>(); pq.add(nodes.get(N-1)); int walkTime, busTime, currentBestTime; while(!pq.isEmpty()){ Graph.Node node = pq.poll(); if(node.maxTimeTorReach < 0) break; for(Graph.Edge edge: adjacencyList.get(node)){ Graph.Node neib = edge.u; if(edge.u.id == node.id){ neib = edge.v; } walkTime = node.maxTimeTorReach - edge.walkTime; busTime = node.maxTimeTorReach - edge.busTime; if(isOverlappingInterval(busTime, node.maxTimeTorReach, t1, t2)){ busTime = t1 - edge.busTime; } currentBestTime = Math.max(walkTime, busTime); if(neib.maxTimeTorReach < currentBestTime){ neib.maxTimeTorReach = currentBestTime; pq.add(neib); } } } } public static class Node implements Comparable<Node>{ int id; int maxTimeTorReach; Node(int id){ this.id = id; this.maxTimeTorReach = -1; } @Override public int compareTo(Node o) { return this.maxTimeTorReach - o.maxTimeTorReach; } } public static class Edge{ int id; Node u; Node v; int walkTime; int busTime; public Edge(Node u, Node v, int walkTime, int busTime) { this.u = u; this.v = v; this.walkTime = walkTime; this.busTime = busTime; this.id = edgeid; edgeid++; } } void createEdge(int u, int v, int busTime, int walkTime){ u--; v--; Node uNode = nodes.get(u); Node vNode = nodes.get(v); Edge edge = new Edge(uNode, vNode, walkTime, busTime); adjacencyList.get(uNode).add(edge); adjacencyList.get(vNode).add(edge); } } public static FastReader s; public static PrintWriter out; public static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } double nextDouble() { return Double.parseDouble(next()); } long nextLong() { return Long.parseLong(next()); } int[] nextIntArray(int n) { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = nextInt(); } return arr; } long[] nextLongArray(int n) { long[] arr = new long[n]; for (int i = 0; i < n; i++) { arr[i] = nextLong(); } return arr; } String nextLine() { String str = ""; try { str = br.readLine(); } catch (Exception e) { e.printStackTrace(); } return str; } } }
2000G
wrong_submission
277,095,729
Python 3
TIME_LIMIT_EXCEEDED on test 17
for test in range(int(input())): n, m = [int(i) for i in input().split()] t0, t1, t2 = [int(i) for i in input().split()] G = dict() for i in range(m): #graph made start, end, bus, walk = [int(i) for i in input().split()] if start not in G: G[start] = [[end,(bus,walk)]] else: G[start] += [[end,(bus,walk)]] if end not in G: G[end] = [[start,(bus,walk)]] else: G[end] += [[start,(bus,walk)]] #Djikstras from the end (node n) to start (node 1) using latest, latest[n]=t0 #if he can ride bus (not on call), ride bus #else choose max (starting time) of walking and waiting for call to end then ride bus latest = [-1]*(n)+[t0] cur = n; vis = []; frontier = [n] while True: #if cur=k, then we have the shortest path to k cur = frontier[0] #pick largest time for i in frontier: if latest[i] > latest[cur]: cur = i if cur == 1: break frontier.remove(cur) vis.append(cur) for prev, time in G[cur]: if prev in vis: continue bus = time[0]; walk = time[1] if (t2 <= latest[cur] - bus) or (t1 >= latest[cur]): #can ride bus latest[prev] = max(latest[prev], latest[cur] - bus) else: latest[prev] = max(latest[prev], t1-bus, latest[cur]-walk) if prev not in frontier: frontier.append(prev) print(latest[1])
2000G
wrong_submission
279,379,713
PyPy 3-64
TIME_LIMIT_EXCEEDED on test 17
import heapq, math from collections import Counter, defaultdict, deque from functools import cache import io,os import sys # input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline t = int(input()) ret = [] MOD = 1_000_000_007 for _ in range(t): # n = int(input()) n, m = list(map(int, input().split())) deadline, pstart, pend = list(map(int, input().split())) # m = int(input()) # s = input() adj = defaultdict(list) for _ in range(m): u, v, c1, c2 = list(map(int, input().split())) u -= 1 v -= 1 adj[u].append((v, c1, c2)) adj[v].append((u, c1, c2)) def nooverlap(a, b): return b <= pstart or a >= pend def check(start): h = [(start, 0)] vis = [math.inf] * n vis[0] = h[0][0] # print(vis) # print('--------------START---------------') while h: # print(h) time, curr = heapq.heappop(h) if time > vis[curr]: continue if time > deadline: return False if curr == n - 1: return True for j, c1, c2 in adj[curr]: if vis[j] > time + c2 and time + c2 <= deadline: vis[j] = time + c2 heapq.heappush(h, (time + c2, j)) # else:/ # print(vis[j], j, time, time + c2) if nooverlap(time, time + c1) and vis[j] > time + c1 and time + c1 <= deadline: vis[j] = time + c1 heapq.heappush(h, (time + c1, j)) ltime = max(time, pend) if vis[j] > ltime + c1 and ltime + c1 <= deadline: vis[j] = ltime + c1 heapq.heappush(h, (ltime + c1, j)) def bins(start, end): if start >= end: return -math.inf if start + 1 == end: return start if check(start) else -math.inf mid = (start + end) // 2 res = check(mid) # print(mid, res) if not res: return bins(start, mid) else: return max(mid, bins(mid + 1, end)) # l = 0 # r = deadline + 1 # res = -1 # while l < r: # mid = (l + r) // 2 # if check(mid): # res = mid # l = mid + 1 # else: # r = mid res = bins(0, deadline + 1) # ret.append((res if res != -math.inf else -1)) print((res if res != -math.inf else -1)) # print(ret) # 1 # 4 4 # 100 40 60 # 1 2 30 100 # 2 4 30 100 # 1 3 20 50 # 3 4 20 50 # 1 # 2 1 # 12 9 10 # 2 1 6 10 # 1 # 5 5 # 100 20 80 # 1 5 30 100 # 1 2 20 50 # 2 3 20 50 # 3 4 20 50 # 4 5 20 50 # 1 # 3 2 # 58 55 57 # 2 1 1 3 # 2 3 3 4
2000G
wrong_submission
277,024,407
PyPy 3-64
TIME_LIMIT_EXCEEDED on test 17
import queue for _ in range(int(input())): n, m = map(int, input().split()) t0, t1, t2 = map(int, input().split()) g = [[] for _ in range(n+1)] dis = [int(-1e9) for _ in range(n+1)] def dijkstra(): dis[n] = t0 q = queue.PriorityQueue() q.put((t0, n)) while q.qsize() != 0: p = q.get() u = p[1] SIZE = len(g[u]) for i in range(SIZE): v, l1, l2 = g[u][i][0], g[u][i][1], g[u][i][2] if dis[u] - l1 >= t2 or dis[u] <= t1: d = dis[u] - l1 else: d = dis[u] - l2 if d == dis[u] - l2: d = max(d, t1 - l1) if dis[v] < d: dis[v] = d q.put((dis[v], v)) for _ in range(m): u, v, l1, l2 = map(int, input().split()) g[u].append([v, l1, l2]) g[v].append([u, l1, l2]) dijkstra() if dis[1] >= 0: print(dis[1]) else: print(-1)
2000G
wrong_submission
276,340,330
PyPy 3
TIME_LIMIT_EXCEEDED on test 17
# ﷽ import sys from heapq import * input = lambda: sys.stdin.buffer.readline().decode().rstrip() def can(t): dis = [float("inf")] * n q=[(t,0)] while q: cost,node=heappop(q) if cost<dis[node]: dis[node]=cost if node == n-1 : break for cbus,cwalk,child in graph[node]: if cost+cbus<=t1 or cost>=t2: heappush(q, (cost + cbus, child)) else: heappush(q, (t2 + cbus, child)) heappush(q, (cost + cwalk, child)) return dis[n-1]<=t0 for _ in range(int(input())): n,m=map(int,input().split()) t0,t1,t2=map(int,input().split()) graph=[[] for _ in range(n)] for _ in range(m): u,v,cbus,cwalk=map(int,input().split()) graph[u-1].append((cbus,cwalk,v-1)) graph[v-1].append((cbus,cwalk,u-1)) low,high=0,t0 while low<=high: mid=(low+high)>>1 if can(mid): low=mid+1 else: high=mid-1 print(high)
2000G
wrong_submission
276,315,178
PyPy 3-64
TIME_LIMIT_EXCEEDED on test 17
def solve(): n,m=map(int, input().split()) t,l,r=map(int, input().split()) g=[[] for _ in range(n+1)] dist=[-1]*(n+1) q=[] def upd(u,x): if dist[u]<x: dist[u]=x q.append((x,u)) for i in range(m): u,v,x,y=map(int,input().split()) g[u].append((v,x,y)) g[v].append((u,x,y)) upd(n,t) while q: q=sorted(q,reverse=True) cur,u=q.pop() if cur!=dist[u]: continue for v,x,y in g[u]: if cur-x>=r: upd(v,cur-x) else: upd(v,min(cur,l)-x) upd(v,cur-y) print(dist[1]) for i in range(int(input())): solve()
2000G
wrong_submission
276,885,216
C++14 (GCC 6-32)
TIME_LIMIT_EXCEEDED on test 17
#include <bits/stdc++.h> #define ll long long using namespace std; const int N=2e5+10; ll t,n,m,t0,t1,t2,x,y,l1,l2,ans,dis[N]; struct node { ll x,d; bool friend operator<(node x,node y) { return x.d>y.d; } }; vector<node>vec[N]; vector<node>vecc[N]; void dijkstra(ll s) { for(int i=1; i<=n; ++i) dis[i]=-1e10; dis[s]=t0; priority_queue<node>q; node p,t; p.x=s;p.d=t0; q.push(p); while(!q.empty()) { p=q.top(); q.pop(); if(p.d<dis[p.x])continue; for(int i=0; i<vec[p.x].size(); ++i) { t.x=vec[p.x][i].x; ll u=vec[p.x][i].d,v=vecc[p.x][i].d; if(dis[p.x]>t1&&dis[p.x]-u<t2) t.d=max(dis[p.x]-v,t1-u); else t.d=dis[p.x]-u; if(t.d>dis[t.x]) { dis[t.x]=t.d; q.push(t); } } } } ll read() { ll k=0,f=1; char c; c=getchar(); while(c<'0'||c>'9') { if(c=='-') f=-1; c=getchar(); } while(c>='0'&&c<='9') { k=k*10+(c-'0'); c=getchar(); } return k*f; } int main() { t=read(); while(t--) { n=read();m=read(); t0=read();t1=read();t2=read(); for(int i=0; i<=n; ++i) { vec[i].clear(); vecc[i].clear(); } for(int i=1; i<=m; ++i) { x=read();y=read();l1=read();l2=read(); vec[x].push_back({y,l1}); vec[y].push_back({x,l1}); vecc[x].push_back({y,l2}); vecc[y].push_back({x,l2}); } dijkstra(n); ll ans=dis[1]; if(ans<0)printf("-1\n"); else printf("%lld\n",ans);// } return 0; }
2000G
wrong_submission
276,738,892
C++20 (GCC 13-64)
TIME_LIMIT_EXCEEDED on test 17
#include<bits/stdc++.h> using namespace std; typedef long long int ll; #define int ll int n,m; int t1,t2,t3; vector<vector<pair<int,int>>>graph; map<pair<int,int>,int>mp; bool dijestra(int node,int start, vector<int> &dis) { for (int i = 0; i < graph.size(); i++) dis[i] = INT_MAX; dis[node] = start; priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> p; p.push({start, node}); while (!p.empty()) { int dist = p.top().first; int node = p.top().second; // cout<<dist<<" "<<node<<endl; p.pop(); for (auto x : graph[node]) { int len = x.second; int child = x.first; // cout<<child<<" "<<len<<endl; if ( dist + len < dis[child]&& (dist>=t3||(dist<=t2 && dist+len<=t2))) { // cout<<node<<" "<<child<<" "<<dist+len<<" "<<" h"<<endl; dis[child] = dist + len; p.push({len + dist, child}); } else if(dist+len<dis[child]){ int small=min(t3+len,dist+mp[{node,child}]); if(small<dis[child]) { // cout<<node<<" "<<child<<" "<<small<<endl; dis[child] = small; p.push({small, child}); } } } } // for(int i=1;i<=n;i++) cout<<dis[i]<<" "; if(dis[n]<=t1) return true; return false; } void solve(){ cin>>n>>m; cin>>t1>>t2>>t3; graph.clear(); graph.resize(n+1); mp.clear(); for(int i=0;i<m;i++) { int u,v,l1,l2; cin>>u>>v>>l1>>l2; graph[u].push_back({v,l1}); graph[v].push_back({u,l1}); mp[{u,v}]=l2; mp[{v,u}]=l2; } int l=0; int h=t1+1; vector<int>dis(n+1); int ans=-1; while(l<=h) { int mid=(l+h)/2; dis.clear();dis.resize(n+1); bool temp=dijestra(1,mid,dis); if(temp) { ans=mid; l=mid+1; } else{ h=mid-1; } } // cout<<dijestra(1,50,dis); cout<<ans<<endl; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int t=1; cin>>t; while(t--) solve(); }
2000G
wrong_submission
293,985,550
C++23 (GCC 14-64, msys2)
TIME_LIMIT_EXCEEDED on test 17
#include <algorithm> #include <vector> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #if __cplusplus >= 201103L #include <array> #include <atomic> #include <chrono> #include <condition_variable> #include <forward_list> #include <future> #include <initializer_list> #include <mutex> #include <random> #include <ratio> #include <regex> #include <scoped_allocator> #include <system_error> #include <thread> #include <tuple> #include <typeindex> #include <type_traits> #include <unordered_map> #include <unordered_set> #endif using namespace std; // mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; // template<class T> // struct cmp { // bool operator()(const T& a, const T& b) const { // if (a == b) return true; // return a > b; // } // }; // template <class T> using ordered_multiset = // tree < // T, // null_type, // cmp <T>, // rb_tree_tag, // tree_order_statistics_node_update >; // struct cmpl { // bool operator() (const tuple<long long, long long, long long>& a, const tuple<long long, long long, long long>& b) const { // if (get<0>(a) == get<0>(b)) { // return get<1LL>(a) < get<1LL>(b); // } // return get<0>(a) < get<0>(b); // } // }; // struct cmpr { // bool operator() (const tuple<long long, long long, long long>& a, const tuple<long long, long long, long long>& b) const { // if (get<1LL>(a) == get<1LL>(b)) { // return get<0>(a) < get<0>(b); // } // return get<1LL>(a) < get<1LL>(b); // } // }; // set < tuple <int,int,int>, cmpl> stl; // set < tuple <int,int,int>, cmpr> str; // #pragma GCC optimize("O3") // #pragma GCC optimize("Ofast,unroll-loops") // #pragma GCC target("avx2,tune=native") #define int long long #define pb push_back #define m_p make_pair const int INF = 1e18; const int mod = 1e9 + 7; struct edge { int to,l1,l2; edge () {} edge (int to,int l1,int l2): to(to), l1(l1), l2(l2) {} }; bool is_cross (pair <int,int> a,pair <int,int> b) { if (a.first <= b.first && b.first <= a.second) { return 1; } if (a.first <= b.second && b.second <= a.second) { return 1; } if (b.first <= a.first && a.first <= b.second) { return 1; } if (b.first <= a.second && a.second <= b.second) { return 1; } return 0; } void solve() { int n,m; cin >> n >> m; int t0,t1,t2; cin >> t0 >> t1 >> t2; vector < vector < edge> > g(n + 1); for (int _ = 0;_ < m;_++) { int u,v,l1,l2; cin >> u >> v >> l1 >> l2; g[u].pb(edge(v,l1,l2)); g[v].pb(edge(u,l1,l2)); } priority_queue < pair <int,int>, vector <pair <int,int> > ,greater < pair <int,int> > > q; vector <int> used(n + 1,0),dist(n + 1,-INF); q.push(m_p(t0,n)); dist[n] = t0; while (!q.empty()) { auto [d,v] = q.top(); q.pop(); if (used[v] > d) { continue; } used[v] = d; for (auto [u,l1,l2]: g[v]) { if (!(d - l1 >= t2 || d <= t1)) { int d1 = t1 - l1; int d2 = d - l2; if (dist[u] < d1) { dist[u] = d1; q.push(m_p(dist[u],u)); } if (dist[u] < d2) { dist[u] = d2; q.push(m_p(dist[u],u)); } } else { if (dist[u] < d - l1) { dist[u] = d - l1; q.push(m_p(dist[u],u)); } } } } cout << max(dist[1],-1LL) << endl; } signed main() { #ifdef LOCAL freopen("input.txt","r",stdin); #endif ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { solve(); } return 0; }
2000G
wrong_submission
277,112,411
C++20 (GCC 13-64)
TIME_LIMIT_EXCEEDED on test 17
#include<bits/stdc++.h> #define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define pb push_back #define ll long long using namespace std; const int N = 1e5 + 7, mod = 1e9 + 7; vector<pair<int,pair<int,int>>>adj[N]; int n,m,t1,t2,t3,u,v,x1,x2,ans; ll dijkstra(int a,int start) { priority_queue<pair<ll,ll>>q; vector<ll>dist(n+1,1e9 + 7); q.push({-start,a}); dist[a] = 0; while(!q.empty()) { int parent = q.top().second; ll cd = -q.top().first; q.pop(); for(auto ch:adj[parent]) { int child = ch.first,l1 = ch.second.first,l2 = ch.second.second; if(cd < t2 && cd + l1 > t1) { if(cd + l2 < dist[child] || t2 + l1 < dist[child]) dist[child] = min((ll)(cd + l2),(ll)(t2 + l1)),q.emplace( -min((ll)(cd + l2),(ll)(t2 + l1)),child); } else { if(cd + l1 < dist[child]) dist[child] = cd + l1,q.emplace(-(cd+l1),child); } } } return dist[n]; } void solve() { ans = -1; cin >> n >> m >> t3 >> t1 >> t2; for(int i=0 ; i < m ; i++) { cin >> u >> v >> x1 >> x2; adj[u].pb({v,{x1,x2}}); adj[v].pb({u,{x1,x2}}); } int l = 0,r = t3 + 1; while(r >= l) { int mid = (l+r)/2; //cout << mid << endl; int dis = dijkstra(1,mid); if(dis <= t3) { l = mid + 1; ans = max(ans,mid); } else r = mid - 1; } cout << ans << '\n'; for(int i=0 ; i <= n ; i++) adj[i].clear(); } /* weighted graph -> li1,li2 currently at node -> 1, time = 0 go to node n with time <= t3 phone call t1 -> t2 -> you can walk only */ signed main() { IO int t = 1; cin >> t; while (t--) { solve(); } }
2000G
wrong_submission
277,105,841
C++20 (GCC 13-64)
TIME_LIMIT_EXCEEDED on test 17
// Sinner, How you do what you do? #include <bits/stdc++.h> #include <fstream> #include <ext/pb_ds/assoc_container.hpp> #include <chrono> #include <format> using namespace std::chrono; using namespace std; using namespace __gnu_pbds; using ll = long long; #define int long long const int N = 1e5 + 5, maxN = 1e7 + 1; const int blockSize = 320; const int mod = 1e9 + 7, LOG = 20; void fast() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } vector<vector<int>> neighbourNodes[N]; int solve() { int n, m, eventStart, startCall, endCall; cin >> n >> m; cin >> eventStart >> startCall >> endCall; for (int i = 0; i < n; ++i) { neighbourNodes[i].clear(); } for (int i = 0; i < m; ++i) { int path, toPath, durationBus, durationWalk; cin >> path >> toPath >> durationBus >> durationWalk; path--, toPath--; neighbourNodes[path].push_back({toPath, durationBus, durationWalk}); neighbourNodes[toPath].push_back({path, durationBus, durationWalk}); } int leftPointer = 0, rightPointer = eventStart; int ans = -1; function<bool(int startTime)> isValid= [&](int startTime) -> bool { priority_queue<pair<int, int>> pq; vector<vector<int>> arrivalTime(n, vector<int>(2, INT32_MAX)); pq.push({-startTime, 0}); while(!pq.empty()) { auto [currTime, currNode] = pq.top(); currTime *= -1; pq.pop(); for(auto &v : neighbourNodes[currNode]) { int node = v[0], durationBus = v[1], durationWalk = v[2]; if(currTime + durationWalk <= startCall || currTime >= endCall) { int endTime = currTime + durationBus; bool newState = endTime >= endCall; if(arrivalTime[node][newState] > endTime) arrivalTime[node][newState] = endTime, pq.push({-endTime, node}); continue; } if((endCall >= currTime && currTime >= startCall) || (currTime + durationBus > startCall)) { for(int endTime : {currTime + durationWalk, endCall + durationBus}) { bool newState = endTime >= endCall; if(arrivalTime[node][newState] > endTime) arrivalTime[node][newState] = endTime, pq.push({-endTime, node}); } continue; } for(int endTime : {currTime + durationBus, currTime + durationWalk, endCall + durationBus}) { bool newState = endTime >= endCall; if(arrivalTime[node][newState] > endTime) arrivalTime[node][newState] = endTime, pq.push({-endTime, node}); } } } return arrivalTime[n - 1][1] <= eventStart || arrivalTime[n - 1][0] <= endCall; }; while(rightPointer >= leftPointer) { int middlePointer = (leftPointer + rightPointer) / 2; if (isValid(middlePointer)) { ans = middlePointer; leftPointer = middlePointer + 1; } else { rightPointer = middlePointer - 1; } } return ans; } int32_t main() { int t; cin >> t; while(t--) cout << solve() << "\n"; }
2000G
wrong_submission
277,286,268
C++14 (GCC 6-32)
TIME_LIMIT_EXCEEDED on test 17
#include<bits/stdc++.h> using namespace std; #define int long long #define ll long long #ifndef ONLINE_JUDGE #include "debug.h" #else #define deb(x...) #endif const int mod = 1000000007; // 998244353; const int N = 2 * 1e5 + 5; const int INF = 1000000000000000000; void solve() { int n, m, t0, t1, t2, u, v, l1, l2; cin >> n >> m >> t0 >> t1 >> t2; vector<vector<int>> adj[n + 1]; for (int i = 0; i < m; i++) { cin >> u >> v >> l1 >> l2; adj[u].push_back({v, l1, l2}); adj[v].push_back({u, l1, l2}); } vector<int> dist(n + 1, -INF); dist[n] = t0; set<pair<int, int>> s; s.insert({t0, n}); while (!s.empty()) { auto it = *s.begin(); s.erase(it); int node = it.second; for (auto &it : adj[node]) { int adjNode = it[0], busTime = it[1], walkTime = it[2]; if (dist[node] <= t1 or dist[node] - busTime >= t2) { // free to use bus if (dist[node] - busTime > dist[adjNode]) { if (dist[adjNode] != -INF) s.erase({dist[adjNode], adjNode}); dist[adjNode] = dist[node] - busTime; s.insert({dist[adjNode], adjNode}); } } else { int best = max(dist[node] - walkTime, t1 - busTime); if (best > dist[adjNode]) { if (dist[adjNode] != -INF) s.erase({dist[adjNode], adjNode}); dist[adjNode] = best; s.insert({dist[adjNode], adjNode}); } } } } if (dist[1] >= 0) cout << dist[1] << "\n"; else cout << -1 << "\n"; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) solve(); return 0; }
2000G
wrong_submission
276,462,954
C++17 (GCC 7-32)
TIME_LIMIT_EXCEEDED on test 17
#include <bits/stdc++.h> #define int long long using namespace std; const int N = 2e5+10; int ar[N],n,m; vector<array<int,3>> q[N]; int t0,t1,t2; int dist[N]; inline bool check(int mid){ for(int i=1; i<=n; i++) dist[i] = 1e15; dist[1] = mid; priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int>>> p; p.push({dist[1],1}); while(!p.empty()){ auto [zz,x] = p.top(); p.pop(); for(auto[a,b,c]:q[x]){ if(dist[x]>=t1&&dist[x]<t2){ int xx = dist[x]+c; int yy = t2+b; xx = min(xx,yy); if(xx<dist[a]){ dist[a] = xx; p.push({dist[a],a}); } }else if(dist[x]<t1&&dist[x]+b>t1){ int xx = dist[x]+c; int yy = t2+b; xx = min(xx,yy); if(xx<dist[a]){ dist[a] = xx; p.push({dist[a],a}); } }else { if(dist[x]+b<dist[a]){ dist[a] = dist[x]+b; p.push({dist[a],a}); } } } } return dist[n]<=t0; } inline void solve(){ cin>>n>>m; cin>>t0>>t1>>t2; for(int i=1; i<=n; i++) q[i].clear(); for(int i=1,a,b,c,d; i<=m; i++) { cin>>a>>b>>c>>d; q[a].push_back({b,c,d}); q[b].push_back({a,c,d}); } int l = 0,r = 1e10; while(l<r){ int mid = l+r+1>>1; if(check(mid)) l = mid; else r = mid-1; } if(check(l)) cout<<l<<"\n"; else cout<<"-1\n"; } signed main(){ ios::sync_with_stdio(false); cin.tie(0); int _ = 1; cin>>_; while(_--){ solve(); } return 0; }
2000G
wrong_submission
277,823,222
C++17 (GCC 7-32)
TIME_LIMIT_EXCEEDED on test 17
#include <bits/stdc++.h> using namespace std; #define int long long #define f first #define s second #define pb push_back const int inf = 1e18; void solve() { int n, m; cin >> n >> m; int t0, t1, t2; cin >> t0 >> t1 >> t2; vector<pair<int, pair<int, int>>> adj[n + 1]; for (int i = 1; i <= m; i++) { int u, v, l1, l2; cin >> u >> v >> l1 >> l2; adj[u].pb({v, {l1, l2}}); adj[v].pb({u, {l1, l2}}); } int dst[n + 1]; // distance from final destination for (int i = 0; i <= n; i++) dst[i] = -inf; dst[n] = t0; priority_queue<pair<int, int>> pq; pq.push({-t0, n}); // bool first = true; while (!pq.empty()) { int mv = pq.top().f; int pos = pq.top().s; pq.pop(); if (-mv < dst[pos]) continue; //cout << -mv << " " << pos << "\n"; for (auto& edge : adj[pos]) { int nxt = edge.f, l1 = edge.s.f, l2 = edge.s.s; int best = inf; if (-mv - l1 >= t2 || -mv <= t1) best = -mv - l1; else best = max(-mv - l2, t1 - l1); //cout << -mv - l2 << " " << t1-l1 << " " << best << "best\n"; if (best > dst[nxt]) { pq.push({-best, nxt}); dst[nxt] = best; } } } if (dst[1] >= 0) cout << dst[1] << "\n"; else cout << "-1\n"; } signed main(){ int t; cin >> t; while (t--) { solve(); } }
2000G
wrong_submission
293,568,853
C++17 (GCC 7-32)
TIME_LIMIT_EXCEEDED on test 17
// Source: https://usaco.guide/general/io #include <bits/stdc++.h> using namespace std; #define MAXN 100100 #define MOD 1e9 + 7 typedef long long ll; typedef pair<int, ll> pi; typedef vector<int> vi; struct edge { int v; ll l1, l2; }; vector<edge> adj[MAXN]; priority_queue<pi , vector<pi>, greater<pi>> pq; ll dist[MAXN]; ll solve(ll cur, ll start, ll end, int n) { for (int i = 1; i <= n; i++) dist[i] = 1e16; dist[1] = cur; pq.push({1, cur}); while (pq.size()) { pi u = pq.top(); pq.pop(); for (edge v : adj[u.first]) { ll temp = v.l2 + u.second; ll len = dist[u.first]; if (len + v.l1 > start && len < end) { temp = min(temp, end + v.l1); } else { temp = min(temp, len + v.l1); } if (temp < dist[v.v]) { dist[v.v] = temp; pq.push({v.v, temp}); } } } return dist[n]; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int tt; cin >> tt; while (tt--) { // being earlier is always better so bs int n, m; cin >> n >> m; ll fin, start, end; cin >> fin >> start >> end; for (int i = 1; i <= n; i++) adj[i].clear(); for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; ll l1, l2; cin >> l1 >> l2; adj[u].push_back({v, l1, l2}); adj[v].push_back({u, l1, l2}); } ll lo = 0, hi = fin; ll ans = -1; int cnt = 0; while (lo <= hi) { cnt++; if (n == 50002) assert(cnt <= 2); ll md = (lo + hi)/2; bool pos = (solve(md, start, end, n) <= fin); if (pos) { ans = max(ans, md); lo = md+1; } else { hi = md-1; } } cout << ans << "\n"; } }
2000G
wrong_submission
276,322,217
C++17 (GCC 7-32)
TIME_LIMIT_EXCEEDED on test 17
//#pragma GCC optimize("Ofast,unroll-loops") //#pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; using ll = long long; using vi = vector<ll>; using pi = pair<ll, ll>; using grid = vector<vi>; template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define en "\n" #define sz(_O) _O.size() #define fix(_O) cout<<setprecision(_O)<<fixed #define fir(_O) for(int i=0; i<_O; ++i) #define fjr(_O) for(int j=0; j<_O; ++j) ll const inf = LLONG_MAX; //0x3f3f3f3f3f3f; ll const mod = 998244353; //1e9+7; void solve(){ ll n, m; cin>>n>>m; grid edg(n+1); ll t0, t, tt; cin>>t0>>t>>tt; map<pi, ll> bs, wk; fir(m){ ll fr, to, b, w; cin>>fr>>to>>b>>w; edg[fr].push_back(to); edg[to].push_back(fr); bs[{min(fr, to), max(fr, to)}]=b; wk[{min(fr, to), max(fr, to)}]=w; } ll l=-1, r=t0; while(l<r){ ll m=(r+l+1)/2; vi dis(n+1, inf); dis[1]=m; vi vis(n+1, 0); priority_queue<pi> pq; pq.push({m, 1}); ll t1=t, t2=tt; while(!pq.empty()){ auto [wt, at]=pq.top(); pq.pop(); vis[at]=1; for(ll to: edg[at]) if(!vis[to]){ ll rt=dis[at]+bs[{min(at, to), max(at, to)}]; if(rt>t1 and dis[at]<=t1) rt+=(t2-dis[at]); else if(t1<dis[at] and t2>dis[at]) rt+=(t2-dis[at]); ll wt=dis[at]+wk[{min(at, to), max(at, to)}]; ll mt=min(rt, wt); dis[to]=min(mt, dis[to]); pq.push({-mt, to}); } } if(dis[n]>t0) r=m-1; else l=m; } cout<<l<<en; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int tt = 1; cin>>tt; while(tt--) solve(); }
2000G
wrong_submission
277,988,465
Java 8
TIME_LIMIT_EXCEEDED on test 17
import java.io.*; import java.util.*; public class CallDuringTheJourney { public static PrintWriter out; public static void main(String[] args)throws IOException{ JS sc=new JS(); out=new PrintWriter(System.out); int t=sc.nextInt(); outer: while(t-->0) { int n=sc.nextInt(); int m=sc.nextInt(); int t0=sc.nextInt(); int t1=sc.nextInt(); int t2=sc.nextInt(); ArrayList<ArrayList<int[]>>al=new ArrayList<>(); for(int i=0;i<n;i++) { al.add(new ArrayList<int[]>()); } for(int i=0;i<m;i++) { int a=sc.nextInt()-1; int b=sc.nextInt()-1; int bus=sc.nextInt(); int walk=sc.nextInt(); al.get(a).add(new int[] {b, bus, walk}); al.get(b).add(new int[] {a, bus, walk}); } int dist[]=new int[n]; Arrays.fill(dist, (int) -1e9); dist[n-1]=t0; PriorityQueue<Integer>q=new PriorityQueue<>((Integer p1,Integer p2)->(dist[p1]-dist[p2])); // ArrayDeque<Integer>q=new ArrayDeque<>(); q.add(n-1); while(!q.isEmpty()) { int cur=q.poll(); for(int[] next:al.get(cur)) { int nexttime=dist[cur]-next[1]; if(nexttime>=t2||dist[cur]<=t1) { nexttime=dist[cur]-next[1]; }else { nexttime=dist[cur]-next[2]; nexttime=Math.max(nexttime, t1-next[1]); } if(dist[next[0]]<nexttime&&nexttime>=-20) { dist[next[0]]=nexttime; q.add(next[0]); } } } out.println(dist[0]>=0?dist[0]:-1); } out.close(); } static void add(HashMap<Integer,Integer> A, int key){ A.put(key,A.getOrDefault(key,0)+1); } static void remove(HashMap<Integer,Integer>A, int key){ if(!A.containsKey(key))return; A.put(key,A.get(key)-1); if(A.get(key)==0){ A.remove(key); } } static class Pair implements Comparable<Pair>{ int x, y; public Pair(int x, int y) { this.x=x;this.y=y; } public int compareTo(Pair p) { if(y==p.y) { return Integer.compare(x, p.x); } return Integer.compare(y, p.y); } } // static class Triple{ // int node, bus, walk; // public Triple(int node, int bus, int walk) { // this.node=node;this.bus=bus;this.walk=walk; // } // } static void sort(int a[]) { ArrayList<Integer>al=new ArrayList<>(); for(int i=0;i<a.length;i++) { al.add(a[i]); } Collections.sort(al); for(int i=0;i<a.length;i++) { a[i]=al.get(i); } } static class JS { public int BS = 1<<16; public char NC = (char)0; byte[] buf = new byte[BS]; int bId = 0, size = 0; char c = NC; double num = 1; BufferedInputStream in; public JS() { in = new BufferedInputStream(System.in, BS); } public JS(String s) throws FileNotFoundException { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } public char nextChar(){ while(bId==size) { try { size = in.read(buf); }catch(Exception e) { return NC; } if(size==-1)return NC; bId=0; } return (char)buf[bId++]; } public int nextInt() { return (int)nextLong(); } public long nextLong() { num=1; boolean neg = false; if(c==NC)c=nextChar(); for(;(c<'0' || c>'9'); c = nextChar()) { if(c=='-')neg=true; } long res = 0; for(; c>='0' && c <='9'; c=nextChar()) { res = (res<<3)+(res<<1)+c-'0'; num*=10; } return neg?-res:res; } public double nextDouble() { double cur = nextLong(); return c!='.' ? cur:cur+nextLong()/num; } public String next() { StringBuilder res = new StringBuilder(); while(c<=32)c=nextChar(); while(c>32) { res.append(c); c=nextChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while(c<=32)c=nextChar(); while(c!='\n') { res.append(c); c=nextChar(); } return res.toString(); } public boolean hasNext() { if(c>32)return true; while(true) { c=nextChar(); if(c==NC)return false; else if(c>32)return true; } } } }
2000G
wrong_submission
276,832,367
Java 21
TIME_LIMIT_EXCEEDED on test 17
//package Codeforces; import java.util.*; public class CallDuringTheJourney { final static Scanner sc = new Scanner(System.in); public static void main(String[] args) { int testcases = sc.nextInt(); for (int test = 0; test<testcases; ++test) { int n = sc.nextInt(); int m = sc.nextInt(); Graph g = new Graph(n, m); int t0 = sc.nextInt(); int t1 = sc.nextInt(); int t2 = sc.nextInt(); for(int i=0; i<m; ++i){ int u = sc.nextInt(); int v = sc.nextInt(); int bussTime = sc.nextInt(); int walkTime = sc.nextInt(); g.createEdge(u, v, bussTime, walkTime); } int result = findTimeToReach(g, t0, t1, t2); System.out.println(result); } } private static int findTimeToReach(Graph g, int t0, int t1, int t2){ g.populateMaxTimeToReach(t0, t1, t2); return g.nodes.get(0).maxTimeTorReach; } private static boolean isOverlappingInterval(int busTime, int maxTimeTorReach, int t1, int t2) { return (t2 > busTime && t1 < maxTimeTorReach); } public static class Graph{ List<Node> nodes; List<Edge> edges; Map<Node, List<Edge>> adjacencyList; static int edgeid = 0; int N; int M; Graph(int N, int M){ this.N = N; this.M = M; nodes = new ArrayList<Node>(); edges = new ArrayList<>(); adjacencyList = new HashMap<>(); for(int i = 0; i < N; i++){ Node u = new Node(i); nodes.add(u); adjacencyList.put(u, new ArrayList<>()); } } void populateMaxTimeToReach(int t0, int t1, int t2){ nodes.get(N-1).maxTimeTorReach = t0; PriorityQueue<Graph.Node> pq = new PriorityQueue<>(); pq.add(nodes.get(N-1)); while(!pq.isEmpty()){ Graph.Node node = pq.poll(); for(Graph.Edge edge: adjacencyList.get(node)){ Graph.Node neib = edge.u; if(edge.u.id == node.id){ neib = edge.v; } int walkTime = node.maxTimeTorReach - edge.walkTime; int busTime = node.maxTimeTorReach - edge.busTime; if(isOverlappingInterval(busTime, node.maxTimeTorReach, t1, t2)){ busTime = t1 - edge.busTime; } int mx = Math.max(walkTime, busTime); if(neib.maxTimeTorReach < mx){ pq.add(neib); neib.maxTimeTorReach = mx; } } } } public static class Node implements Comparable<Node>{ int id; int maxTimeTorReach; Node(int id){ this.id = id; this.maxTimeTorReach = -1; } @Override public int compareTo(Node o) { return this.maxTimeTorReach - o.maxTimeTorReach; } } public static class Edge{ int id; Node u; Node v; int walkTime; int busTime; public Edge(Node u, Node v, int walkTime, int busTime) { this.u = u; this.v = v; this.walkTime = walkTime; this.busTime = busTime; this.id = edgeid; edgeid++; } } void createEdge(int u, int v, int busTime, int walkTime){ u--; v--; Node uNode = nodes.get(u); Node vNode = nodes.get(v); Edge edge = new Edge(uNode, vNode, walkTime, busTime); adjacencyList.get(uNode).add(edge); adjacencyList.get(vNode).add(edge); } } }
2000G
wrong_submission
279,273,564
PyPy 3-64
TIME_LIMIT_EXCEEDED on test 17
import heapq, math from collections import Counter, defaultdict, deque from functools import cache import io,os import sys # input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline t = int(input()) ret = [] MOD = 1_000_000_007 for _ in range(t): # n = int(input()) n, m = list(map(int, input().split())) deadline, pstart, pend = list(map(int, input().split())) # m = int(input()) # s = input() adj = defaultdict(list) for _ in range(m): u, v, c1, c2 = list(map(int, input().split())) u -= 1 v -= 1 adj[u].append((v, c1, c2)) adj[v].append((u, c1, c2)) def overlap(a, b, x, y): return not (b < x or y < a) def check(start): h = [(start, 0)] vis = [math.inf] * n vis[0] = h[0][0] # print('--------------START---------------') while h: # print(h) time, curr = heapq.heappop(h) if time > deadline: return False if curr == n - 1: return True # if pstart < time < pend: # time = pend for j, c1, c2 in adj[curr]: if not overlap(time, time + c1, pstart + 1, pend - 1) and vis[j] > time + c1 and time + c1 <= deadline: vis[j] = time + c1 heapq.heappush(h, (time + c1, j)) if time <= pend and vis[j] > pend + c1 and pend + c1 <= deadline: vis[j] = pend + c1 heapq.heappush(h, (pend + c1, j)) if vis[j] > time + c2 and time + c2 <= deadline: vis[j] = time + c2 heapq.heappush(h, (time + c2, j)) def bins(start, end): if start >= end: return -math.inf if start + 1 == end: return start if check(start) else -math.inf mid = (start + end) // 2 if not check(mid): return bins(start, mid) else: return max(mid, bins(mid + 1, end)) res = bins(0, deadline + 1) # ret.append((res if res != -math.inf else -1)) print((res if res != -math.inf else -1)) # print(ret) # 1 # 4 4 # 100 40 60 # 1 2 30 100 # 2 4 30 100 # 1 3 20 50 # 3 4 20 50 # 1 # 2 1 # 12 9 10 # 2 1 6 10 # 1 # 5 5 # 100 20 80 # 1 5 30 100 # 1 2 20 50 # 2 3 20 50 # 3 4 20 50 # 4 5 20 50
2000G
wrong_submission
281,497,152
C++17 (GCC 7-32)
TIME_LIMIT_EXCEEDED on test 18
#include <bits/stdc++.h> using namespace std; #define ll long long void solve(){ ll n, m; cin >> n >> m; ll t0, t1, t2; cin >> t0 >> t1 >> t2; vector<vector<vector<ll>>> g(n+1); while(m--){ ll u, v, b, f; cin >> u >> v >> b >> f; u -= 1, v -= 1; g[u].push_back({v, b, f}); g[v].push_back({u, b, f}); } const ll INF = 1e18; vector<ll> time(n+1, -INF); time[n-1] = t0; // cout << "call times: " << t1 << " to " << t2 << "\n"; priority_queue<vector<ll>> pq; pq.push({t0, n-1}); // <time, node> while(!pq.empty()){ auto tuple = pq.top(); pq.pop(); ll curtime = tuple[0], curnode = tuple[1]; if(curnode == 0){ // cout << "FIRST NODE: " << curnode << "\n"; break; } // cout << "curtime: " << curtime << "\n"; for(auto it:g[curnode]){ ll v = it[0], b = it[1], f = it[2]; if(curtime <= t1 or curtime-b >= t2){ // cout << "u: " << curnode << " v: " << v << " - OUTSIDE CALL TIME CASE\nb: " << b << " f: " << f << "\n"; if(time[v] < curtime-b){ // cout << "time_v: " << time[v] << ", greater time: " << curtime-b << "\n"; time[v] = curtime-b; pq.push({time[v], v}); } }else{ // cout << "u: " << curnode << " v: " << v << " - DURING CALL CASE\nb: " << b << " f: " << f << "\n"; ll ntime = max(curtime-f, t1-b); // cout << "opt1: " << curtime-f << " opt2: " << t1-b << "\n"; if(ntime > time[v]){ // cout << "time_v: " << time[v] << ", greater time: " << ntime << "\n"; time[v] = ntime; pq.push({time[v], v}); } } } // cout << "----------------------------------\n"; } // cout << "FINAL TIMES\n"; // for(int u=0; u<n; u+=1){ // cout << time[u] << " "; // } // cout << "\n"; ll mxtimefrom0 = time[0]; if(mxtimefrom0 < 0){ cout << "-1\n"; }else{ cout << mxtimefrom0 << endl; } // cout << "-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x\n"; } // 0 // -1 // 60 // 80 // 53 // 3 // 2 int main(){ int tc; cin >> tc; while(tc--){ solve(); } return 0; }
2000G
wrong_submission
298,415,066
C++17 (GCC 7-32)
TIME_LIMIT_EXCEEDED on test 18
#include<bits/stdc++.h> #define PII pair<int,int> #define int long long using namespace std; const int N=1e5+10; int n,m,t0,t1,t2,ans; int dis[N]; struct edge{ int to,w1,w2,nxt; }e[N<<1]; int en,h[N]; void add(int u,int v,int w1,int w2){ ++en; e[en].to=v,e[en].w1=w1,e[en].w2=w2,e[en].nxt=h[u]; h[u]=en; return; } priority_queue<PII,vector<PII>,greater<PII> > q; void dij(){ for(int i=1;i<n;++i) dis[i]=1e18; dis[n]=0; q.push({0,n}); while(!q.empty()){ int u=q.top().second; q.pop(); for(int i=h[u];i;i=e[i].nxt){ int v=e[i].to; int t=dis[u]+e[i].w1; if(t<=t0-t2||dis[u]>=t0-t1){ if(t<dis[v]){ dis[v]=t; q.push({t,v}); } }else{ int tt=min(dis[u]+e[i].w2,t0-t1+e[i].w1); if(tt<dis[v]){ dis[v]=tt; q.push({tt,v}); } } } } return; } signed _main(){ // ios::sync_with_stdio(false); // cin.tie(0);cout.tie(0); cin>>n>>m; cin>>t0>>t1>>t2; for(int i=1;i<=m;++i){ int u,v,w1,w2; cin>>u>>v>>w1>>w2; add(u,v,w1,w2); add(v,u,w1,w2); } dij(); if(dis[1]>t0) cout<<-1<<'\n'; else cout<<t0-dis[1]<<'\n'; return 0; } signed main(){ ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); int T; cin>>T; while(T--){ en=0; for(int i=1;i<=n;++i) h[i]=0; _main(); } return 0; }
2000G
wrong_submission
277,978,083
Java 8
TIME_LIMIT_EXCEEDED on test 18
import java.io.*; import java.util.*; public class CallDuringTheJourney { public static PrintWriter out; public static void main(String[] args)throws IOException{ JS sc=new JS(); out=new PrintWriter(System.out); int t=sc.nextInt(); outer: while(t-->0) { int n=sc.nextInt(); int m=sc.nextInt(); int t0=sc.nextInt(); int t1=sc.nextInt(); int t2=sc.nextInt(); ArrayList<ArrayList<Triple>>al=new ArrayList<>(); for(int i=0;i<n;i++) { al.add(new ArrayList<Triple>()); } for(int i=0;i<m;i++) { int a=sc.nextInt()-1; int b=sc.nextInt()-1; int bus=sc.nextInt(); int walk=sc.nextInt(); al.get(a).add(new Triple(b, bus, walk)); al.get(b).add(new Triple(a, bus, walk)); } int dist[]=new int[n]; Arrays.fill(dist, (int) -1e9); dist[n-1]=t0; PriorityQueue<Integer>q=new PriorityQueue<>((Integer p1,Integer p2)->-Integer.compare(dist[p1],dist[p2])); // ArrayDeque<Integer>q=new ArrayDeque<>(); q.add(n-1); while(!q.isEmpty()) { int cur=q.poll(); for(Triple next:al.get(cur)) { int nexttime=dist[cur]-next.bus; if(nexttime>=t2||dist[cur]<=t1) { nexttime=dist[cur]-next.bus; }else { nexttime=dist[cur]-next.walk; nexttime=Math.max(nexttime, t1-next.bus); } if(dist[next.node]<nexttime) { dist[next.node]=nexttime; q.add(next.node); } } } out.println(dist[0]>=0?dist[0]:-1); } out.close(); } static void add(HashMap<Integer,Integer> A, int key){ A.put(key,A.getOrDefault(key,0)+1); } static void remove(HashMap<Integer,Integer>A, int key){ if(!A.containsKey(key))return; A.put(key,A.get(key)-1); if(A.get(key)==0){ A.remove(key); } } static class Pair implements Comparable<Pair>{ int x, y; public Pair(int x, int y) { this.x=x;this.y=y; } public int compareTo(Pair p) { if(y==p.y) { return Integer.compare(x, p.x); } return Integer.compare(y, p.y); } } static class Triple{ int node, bus, walk; public Triple(int node, int bus, int walk) { this.node=node;this.bus=bus;this.walk=walk; } } static void sort(int a[]) { ArrayList<Integer>al=new ArrayList<>(); for(int i=0;i<a.length;i++) { al.add(a[i]); } Collections.sort(al); for(int i=0;i<a.length;i++) { a[i]=al.get(i); } } static class JS { public int BS = 1<<16; public char NC = (char)0; byte[] buf = new byte[BS]; int bId = 0, size = 0; char c = NC; double num = 1; BufferedInputStream in; public JS() { in = new BufferedInputStream(System.in, BS); } public JS(String s) throws FileNotFoundException { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } public char nextChar(){ while(bId==size) { try { size = in.read(buf); }catch(Exception e) { return NC; } if(size==-1)return NC; bId=0; } return (char)buf[bId++]; } public int nextInt() { return (int)nextLong(); } public long nextLong() { num=1; boolean neg = false; if(c==NC)c=nextChar(); for(;(c<'0' || c>'9'); c = nextChar()) { if(c=='-')neg=true; } long res = 0; for(; c>='0' && c <='9'; c=nextChar()) { res = (res<<3)+(res<<1)+c-'0'; num*=10; } return neg?-res:res; } public double nextDouble() { double cur = nextLong(); return c!='.' ? cur:cur+nextLong()/num; } public String next() { StringBuilder res = new StringBuilder(); while(c<=32)c=nextChar(); while(c>32) { res.append(c); c=nextChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while(c<=32)c=nextChar(); while(c!='\n') { res.append(c); c=nextChar(); } return res.toString(); } public boolean hasNext() { if(c>32)return true; while(true) { c=nextChar(); if(c==NC)return false; else if(c>32)return true; } } } }
2000G
wrong_submission
277,221,391
PyPy 3-64
TIME_LIMIT_EXCEEDED on test 18
# Created by Ketan_Raut # Copyright © 2024 iN_siDious. All rights reserved. import sys,os import random from math import * from string import ascii_lowercase,ascii_uppercase from collections import Counter, defaultdict, deque from itertools import accumulate, combinations, permutations from heapq import heappushpop, heapify, heappop, heappush from bisect import bisect_left,bisect_right from types import GeneratorType from random import randint RANDOM = randint(1, 10 ** 10) class op(int): def __init__(self, x): int.__init__(x) def __hash__(self): return super(op, self).__hash__() ^ RANDOM def bootstrap(f, stack=[]): def wrappedfunc(*args, **kwargs): if stack: return f(*args, **kwargs) else: to = f(*args, **kwargs) while True: if type(to) is GeneratorType: stack.append(to) to = next(to) else: stack.pop() if not stack: break to = stack[-1].send(to) return to return wrappedfunc inp = lambda: sys.stdin.buffer.readline().decode().strip() out=sys.stdout.write def S(): return inp() def I(): return int(inp()) def F(): return float(inp()) def MI(): return map(int, inp().split()) def MF(): return map(float, inp().split()) def MS(): return inp().split() def LS(): return list(inp().split()) def LI(): return list(map(int,inp().split())) def LF(): return list(map(float,inp().split())) def Query(i,j): print3('?', i, j) sys.stdout.flush() qi=I() return qi def print1(x): return out(str(x)+"\n") def print2(x,y): return out(str(x)+" "+str(y)+"\n") def print3(x,y,z): return out(str(x)+" "+str(y)+" "+str(z)+"\n") def print_arr(arr): for num in arr: out(str(num)+" ") out(str("\n")) for _ in range(I()): n,m=MI() t0,t1,t2=MI() graph=[[] for _ in range(n)] for _ in range(m): u,v,l1,l2=MI() u,v=u-1,v-1 graph[u].append((v,l1,l2)) graph[v].append((u,l1,l2)) heap,dist=[],[-sys.maxsize]*n dist[n-1]=t0 heappush(heap,(-t0,n-1)) while heap: time,node=heappop(heap) time=-time for nei,l1,l2 in graph[node]: new_time=time-l1 if not ((t1<new_time<t2) or (new_time<=t1 and time>=t2) or t1<time<t2): if new_time>dist[nei]: dist[nei]=new_time heappush(heap,(-new_time,nei)) else: new_time=max(time-l2,t1-l1) if new_time>dist[nei]: dist[nei]=new_time heappush(heap,(-new_time,nei)) print1(-1 if dist[0]<0 else dist[0])
2000G
wrong_submission
277,221,815
PyPy 3-64
TIME_LIMIT_EXCEEDED on test 18
# Created by Ketan_Raut # Copyright © 2024 iN_siDious. All rights reserved. import sys,os import random from math import * from string import ascii_lowercase,ascii_uppercase from collections import Counter, defaultdict, deque from itertools import accumulate, combinations, permutations from heapq import heappushpop, heapify, heappop, heappush from bisect import bisect_left,bisect_right from types import GeneratorType from random import randint RANDOM = randint(1, 10 ** 10) class op(int): def __init__(self, x): int.__init__(x) def __hash__(self): return super(op, self).__hash__() ^ RANDOM def bootstrap(f, stack=[]): def wrappedfunc(*args, **kwargs): if stack: return f(*args, **kwargs) else: to = f(*args, **kwargs) while True: if type(to) is GeneratorType: stack.append(to) to = next(to) else: stack.pop() if not stack: break to = stack[-1].send(to) return to return wrappedfunc inp = lambda: sys.stdin.buffer.readline().decode().strip() out=sys.stdout.write def S(): return inp() def I(): return int(inp()) def F(): return float(inp()) def MI(): return map(int, inp().split()) def MF(): return map(float, inp().split()) def MS(): return inp().split() def LS(): return list(inp().split()) def LI(): return list(map(int,inp().split())) def LF(): return list(map(float,inp().split())) def Query(i,j): print3('?', i, j) sys.stdout.flush() qi=I() return qi def print1(x): return out(str(x)+"\n") def print2(x,y): return out(str(x)+" "+str(y)+"\n") def print3(x,y,z): return out(str(x)+" "+str(y)+" "+str(z)+"\n") def print_arr(arr): for num in arr: out(str(num)+" ") out(str("\n")) for _ in range(I()): n,m=MI() t0,t1,t2=MI() graph=[[] for _ in range(n)] for _ in range(m): u,v,l1,l2=MI() u,v=u-1,v-1 graph[u].append((v,l1,l2)) graph[v].append((u,l1,l2)) heap,dist=[],[-sys.maxsize]*n dist[n-1]=t0 heappush(heap,(-t0,n-1)) while heap: time,node=heappop(heap) time=-time for nei,l1,l2 in graph[node]: new_time=time-l1 if new_time<0: continue if not ((t1<new_time<t2) or (new_time<=t1 and time>=t2) or t1<time<t2): if new_time>dist[nei]: dist[nei]=new_time heappush(heap,(-new_time,nei)) else: new_time=max(time-l2,t1-l1) if new_time<0: continue if new_time>dist[nei]: dist[nei]=new_time heappush(heap,(-new_time,nei)) print1(-1 if dist[0]<0 else dist[0])
2000G
wrong_submission
280,350,289
PyPy 3-64
TIME_LIMIT_EXCEEDED on test 18
from heapq import heappop, heappush for _ in range(int(input())): n, m = list(map(int, input().split())) t0, t1, t2 = list(map(int, input().split())) g = [[] for _ in range(n+1)] for _ in range(m): u, v, l1, l2 = list(map(int, input().split())) g[u].append((v, l1, l2)) g[v].append((u, l1, l2)) best = [float('inf')]*n + [0] fet = [False]*n + [True] heap = [(0, n)] while heap: t, u = heappop(heap) fet[u] = True if u == 1 or best[u] > t0: break for v, l1, l2 in g[u]: if fet[v]: continue best[v] = min(best[v], best[u] + l2) if best[u] + l1 <= t0-t2: best[v] = min(best[v], best[u] + l1) best[v] = min(best[v], max(t0 - t1, best[u]) + l1) heappush(heap, (best[v], v)) print(max(t0 - best[1], -1))
2000G
wrong_submission
276,543,672
C++20 (GCC 13-64)
TIME_LIMIT_EXCEEDED on test 18
#include<bits/stdc++.h> using namespace std; #define lli long long int #define pb push_back #define pi pair<lli, lli> #define vt vector #define ff first #define ss second #define rep(i, a, n) for(int i = a; i < n; i++) #define all(x) x.begin(), x.end() #define mod 1000000007 const lli N = 100005; int main(){ ios_base :: sync_with_stdio(false); cin.tie(NULL); int tt; cin >> tt; rep(t, 0, tt){ lli n, m; cin >> n >> m; lli t0, t1, t2; cin >> t0 >> t1 >> t2; vt<pair<lli, pi>> adj[n + 1]; //{bus, foot} rep(i, 0, m){ lli u, v, d1, d2; cin >> u >> v >> d1 >> d2; adj[u].pb({v, {d1, d2}}); adj[v].pb({u, {d1, d2}}); } vt<lli> dis(n + 1, -1e9); dis[n] = t0; priority_queue<pi> pq; pq.push({t0, n}); while(!pq.empty()){ auto [time, u] = pq.top(); pq.pop(); if(dis[u] < time) continue; for(auto [x, d]: adj[u]){ lli db = d.ff, df = d.ss; if(dis[x] < time - df){ dis[x] = time - df; pq.push({dis[x], x}); } if(time - db >= t2 || time <= t1){ if(dis[x] < time - db){ dis[x] = time - db; pq.push({dis[x], x}); } } else{ if(dis[x] < t1 - db){ dis[x] = t1 - db; pq.push({dis[x], x}); } } } } cout << (dis[1] < 0 ? -1 : dis[1]) << "\n"; } }
2000G
wrong_submission
276,535,678
C++17 (GCC 7-32)
TIME_LIMIT_EXCEEDED on test 18
#include <bits/stdc++.h> using namespace std; #define read(type) readInt<type>() // Fast read #define mod 1000000007 #define ll long long #define pb push_back #define ppb pop_back #define mk make_pair #define pii pair<int, int> #define pll pair<ll, ll> #define vi vector<int> #define vll vector<ll> #define vpii vector<pii> #define mii map<int, int> #define si set<int> #define sc set<char> #define umap unordered_map #define uset unordered_set #define umapii unordered_map<int, int> #define useti unordered_set<int> #define all(x) (x).begin(), (x).end() #define sz(x) (int((x).size())) #define fr(i, a, b) for (int i = a; i < b; i++) #define rfr(i, a, b) for (int i = a; i >= b; i--) // ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);} // ll expo(ll a, ll b, ll m) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % m; a = (a * a) % m; b = b >> 1;} return res;} // ll mminvprime(ll a, ll b) {return expo(a, b - 2, b);} // ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} // ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;} // ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return ((a - b+m) % m);} // ll mod_div(ll a, ll b, ll m) {a = a % m; b = b % m; return (mod_mul(a, mminvprime(b, m), m) + m) % m;} //only for prime m class Graph { public: ll n; ll m; ll dead; ll t1, t2; unordered_map<ll, vector<pair<ll, pair<ll, ll>>>> edges; void djikstra(ll source) { vector<ll> times(n + 1, LLONG_MIN); times[source] = dead; priority_queue<pair<ll, ll>> pq; pq.push({dead, source}); while (!pq.empty()) { pair<ll, ll> curr = pq.top(); pq.pop(); for (auto &j : edges[curr.second]) { // case 1: t1 t2 bus curr // case 2: t1 bus t2 curr // case 3: bus t1 t2 curr // case 4: t1 bus curr t2 // case 5: bus t1 curr t2 // case 6: bus curr t1 t2 ll bus = curr.first - j.second.first; ll walk = curr.first - j.second.second; // case 1: t1 t2 bus curr or bus curr t1 t2 if (t2 <= bus || t1 >= curr.first) { // walk if (times[j.first] < walk) { pq.push({walk, j.first}); } // take bus if (times[j.first] < bus) { pq.push({bus, j.first}); } times[j.first] = max(times[j.first], max(bus, walk)); } // case 2: t1 bus t2 curr or bus t1 t2 curr or t1 bus curr t2 or bus t1 curr t2 else { // wait till t1 and take bus if (times[j.first] < t1 - j.second.first) { pq.push({t1 - j.second.first, j.first}); } // walk if (times[j.first] < walk) { pq.push({walk, j.first}); } times[j.first] = max(times[j.first], max(t1 - j.second.first, walk)); } } } cout << ((times[1] >= 0) ? times[1] : -1) << endl; } }; void solve() { Graph *g = new Graph(); cin >> g->n >> g->m; cin >> g->dead >> g->t1 >> g->t2; for (ll i = 0; i < g->m; i++) { ll u, v, l1, l2; cin >> u >> v >> l1 >> l2; g->edges[u].push_back(mk(v, mk(l1, l2))); g->edges[v].push_back(mk(u, mk(l1, l2))); } g->djikstra(g->n); } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int ttt; cin >> ttt; while (ttt--) { solve(); } return 0; }
2000G
wrong_submission
277,989,923
Java 8
TIME_LIMIT_EXCEEDED on test 18
import java.io.*; import java.util.*; public class CallDuringTheJourney { public static PrintWriter out; public static void main(String[] args)throws IOException{ JS sc=new JS(); out=new PrintWriter(System.out); int t=sc.nextInt(); outer: while(t-->0) { int n=sc.nextInt(); int m=sc.nextInt(); int t0=sc.nextInt(); int t1=sc.nextInt(); int t2=sc.nextInt(); ArrayList<ArrayList<Triple>>al=new ArrayList<>(); int dist[]=new int[n]; for(int i=0;i<n;i++) { al.add(new ArrayList<Triple>()); dist[i]=(int)-1e9; } for(int i=0;i<m;i++) { int a=sc.nextInt()-1; int b=sc.nextInt()-1; int bus=sc.nextInt(); int walk=sc.nextInt(); al.get(a).add(new Triple(b, bus, walk)); al.get(b).add(new Triple(a, bus, walk)); } // int dist[]=new int[n]; // Arrays.fill(dist, (int) -1e9); dist[n-1]=t0; PriorityQueue<Integer>q=new PriorityQueue<>((q1, q2)->-Integer.compare(dist[q1], dist[q2])); // ArrayDeque<Integer>q=new ArrayDeque<>(); q.add(n-1); while(!q.isEmpty()) { int cur=q.poll(); for(Triple next:al.get(cur)) { int nexttime=dist[cur]-next.bus; if(nexttime>=t2||dist[cur]<=t1) { nexttime=dist[cur]-next.bus; }else { nexttime=dist[cur]-next.walk; nexttime=Math.max(nexttime, t1-next.bus); } if(dist[next.node]<nexttime) { dist[next.node]=nexttime; q.add(next.node); } } } out.println(dist[0]>=0?dist[0]:-1); } out.close(); } static void add(HashMap<Integer,Integer> A, int key){ A.put(key,A.getOrDefault(key,0)+1); } static void remove(HashMap<Integer,Integer>A, int key){ if(!A.containsKey(key))return; A.put(key,A.get(key)-1); if(A.get(key)==0){ A.remove(key); } } static class Pair implements Comparable<Pair>{ int x, y; public Pair(int x, int y) { this.x=x;this.y=y; } public int compareTo(Pair p) { if(y==p.y) { return Integer.compare(x, p.x); } return Integer.compare(y, p.y); } } static class Triple{ int node, bus, walk; public Triple(int node, int bus, int walk) { this.node=node;this.bus=bus;this.walk=walk; } } static void sort(int a[]) { ArrayList<Integer>al=new ArrayList<>(); for(int i=0;i<a.length;i++) { al.add(a[i]); } Collections.sort(al); for(int i=0;i<a.length;i++) { a[i]=al.get(i); } } static class JS { public int BS = 1<<16; public char NC = (char)0; byte[] buf = new byte[BS]; int bId = 0, size = 0; char c = NC; double num = 1; BufferedInputStream in; public JS() { in = new BufferedInputStream(System.in, BS); } public JS(String s) throws FileNotFoundException { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } public char nextChar(){ while(bId==size) { try { size = in.read(buf); }catch(Exception e) { return NC; } if(size==-1)return NC; bId=0; } return (char)buf[bId++]; } public int nextInt() { return (int)nextLong(); } public long nextLong() { num=1; boolean neg = false; if(c==NC)c=nextChar(); for(;(c<'0' || c>'9'); c = nextChar()) { if(c=='-')neg=true; } long res = 0; for(; c>='0' && c <='9'; c=nextChar()) { res = (res<<3)+(res<<1)+c-'0'; num*=10; } return neg?-res:res; } public double nextDouble() { double cur = nextLong(); return c!='.' ? cur:cur+nextLong()/num; } public String next() { StringBuilder res = new StringBuilder(); while(c<=32)c=nextChar(); while(c>32) { res.append(c); c=nextChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while(c<=32)c=nextChar(); while(c!='\n') { res.append(c); c=nextChar(); } return res.toString(); } public boolean hasNext() { if(c>32)return true; while(true) { c=nextChar(); if(c==NC)return false; else if(c>32)return true; } } } }
2000G
wrong_submission
276,399,793
Java 8
TIME_LIMIT_EXCEEDED on test 18
// package Round966; import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.LinkedList; import java.util.StringTokenizer; import java.util.TreeSet; public class G { public static LinkedList<Edge>[] adj; public static long doDjiktras(int t0, int t1, int t2) { int n = adj.length; TreeSet<Pair> tree = new TreeSet<Pair>(); tree.add(new Pair(n - 1, t0)); long[] values = new long[n]; Arrays.fill(values, Long.MIN_VALUE); values[n - 1] = t0; while (!tree.isEmpty()) { Pair topMostNode = tree.pollLast(); for (Edge x: adj[topMostNode.node]) { if (topMostNode.value > t1 && topMostNode.value < t2) { // either wait for the remaining time and take bus // or continue walking to the next node long firstOption = t1 - x.bus; long secondOption = topMostNode.value - x.walk; long bestOption = Long.max(firstOption, secondOption); if (bestOption > values[x.v]) { values[x.v] = bestOption; tree.add(new Pair(x.v, values[x.v])); } } else { long startTime = topMostNode.value - x.bus; long endTime = topMostNode.value; if (doOverlap(startTime, endTime, t1, t2)) { // either walk till next node // or wait till t2 and then start walking long firstOption = topMostNode.value - x.walk; long secondOption = t1 - x.bus; long bestOption = Long.max(firstOption, secondOption); if (bestOption > values[x.v]) { values[x.v] = bestOption; tree.add(new Pair(x.v, values[x.v])); } } else { if (topMostNode.value - x.bus > values[x.v]) { values[x.v] = topMostNode.value - x.bus; tree.add(new Pair(x.v, values[x.v])); } } } } } return values[0] < 0 ? -1 : values[0]; } public static boolean doOverlap(long s1, long e1, long s2, long e2) { return Long.min(e1, e2) > Long.max(s1, s2); } public static void solve() { int t = s.nextInt(); while (t-- > 0) { int n = s.nextInt(); int m = s.nextInt(); adj = new LinkedList[n]; for (int i = 0; i < n; i++) { adj[i] = new LinkedList<Edge>(); } int t1 = s.nextInt(); int t2 = s.nextInt(); int t3 = s.nextInt(); for (int i = 0; i < m; i++) { int u = s.nextInt() - 1; int v = s.nextInt() - 1; long bus = s.nextLong(); long walk = s.nextLong(); adj[u].add(new Edge(v, bus, walk)); adj[v].add(new Edge(u, bus, walk)); } out.println(doDjiktras(t1, t2, t3)); } } public static class Pair implements Comparable<Pair> { int node; long value; public Pair (int node, long value) { this.node = node; this.value = value; } public int compareTo(Pair x) { return this.value - x.value > 0 ? 1 : -1; } } public static class Edge { int v; long bus; long walk; public Edge(int v, long bus, long walk) { this.v = v; this.bus = bus; this.walk = walk; } } public static void main(String[] args) { new Thread (null, null, "Thread", 1<<27) { public void run() { try { s = new FastReader(); out = new PrintWriter(new BufferedOutputStream(System.out)); solve(); out.close(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } } }.start(); } public static FastReader s; public static PrintWriter out; public static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } double nextDouble() { return Double.parseDouble(next()); } long nextLong() { return Long.parseLong(next()); } int[] nextIntArray(int n) { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = nextInt(); } return arr; } long[] nextLongArray(int n) { long[] arr = new long[n]; for (int i = 0; i < n; i++) { arr[i] = nextLong(); } return arr; } String nextLine() { String str = ""; try { str = br.readLine(); } catch (Exception e) { e.printStackTrace(); } return str; } } }
2000G
wrong_submission
287,352,314
PyPy 3-64
TIME_LIMIT_EXCEEDED on test 18
import sys input = sys.stdin.readline from heapq import heappop, heappush for _ in range(int(input())): n, m = map(int, input().split()) t0, t1, t2 = map(int, input().split()) d = [[] for _ in range(n+1)] q = [] for i in range(m): a, b, l1, l2 = map(int, input().split()) d[a].append((b, i)) d[b].append((a, i)) q.append((l1, l2)) h = [(~t0, n)] x = [-1]*(n+1) y = [1]*m while h: a, b = heappop(h) a = ~a for i, j in d[b]: if y[j]: y[j] = 0 a1 = a l1, l2 = q[j] if t1 < a <= t2 or (t2 <= a and a-l1 < t2): a1 = t1 a2 = max(a-l2, a1-l1) if a2 > -1 and a2 > x[i]: x[i] = a2 heappush(h, (~a2, i)) print(x[1])
2000G
wrong_submission
276,330,025
C++20 (GCC 13-64)
TIME_LIMIT_EXCEEDED on test 18
#include <bits/stdc++.h> using namespace std; using ll = long long; #ifdef debug_local #include "debug.h" #else #define pr(...) /* Nothing */ #define prs(...) /* Nothing */ #endif struct edge { ll to, l1, l2; }; void solve(int tc = 0) { ll n, m; cin >> n >> m; ll t0, t1, t2; cin >> t0 >> t1 >> t2; vector<vector<edge>> g(n); for (int i = 0; i < m; i++) { ll u, v, l1, l2; cin >> u >> v >> l1 >> l2; --u; --v; g[u].push_back(edge(v, l1, l2)); g[v].push_back(edge(u, l1, l2)); } ll l = 0; ll r = t0; ll ans = -1; auto check = [&](ll start) -> bool { priority_queue<pair<ll, ll>> pq; pq.push({start, 0}); vector<ll> dist(n, (ll)1e18); vector<bool> vis(n, 0); while (pq.size()) { auto [time, now] = pq.top(); pq.pop(); if (vis[now] || (dist[now] > t0 && dist[now] != (ll)1e18)) { continue; } dist[now] = min(dist[now], time); for (auto& [to, l1, l2] : g[now]) { ll bus = dist[now] + l1; if (dist[now] < t2 && bus > t1) { bus = t2 + l1; } ll feet = dist[now] + l2; if (min(bus, feet) < dist[to]) { if (!vis[to]) { pq.push({min(bus, feet), to}); } dist[to] = min(bus, feet); } } } return dist[n - 1] <= t0; }; while (l <= r) { ll mid = midpoint(l, r); if (check(mid)) { l = mid + 1; ans = mid; } else { r = mid - 1; } } cout << ans << '\n'; return; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int tc = 1; cin >> tc; for (int t = 1; t <= tc; t++) { solve(t); } }
2000G
wrong_submission
276,454,818
C++14 (GCC 6-32)
TIME_LIMIT_EXCEEDED on test 18
// Problem: G. Call During the Journey // Contest: Codeforces - Codeforces Round 966 (Div. 3) // URL: https://codeforces.com/contest/2000/problem/G // Memory Limit: 256 MB // Time Limit: 4000 ms //tw911 #include<bits/stdc++.h> #include<iostream> #include<algorithm> #include<numeric> #include<map> #include<set> #include<queue> using namespace std; #define int long long #define fi(i,a,b) for(int i=a;i<b;i++) #define fii(i,a,b,c) for(int i=a;i<b;i+=c) #define fd(i,a,b) for(int i=a;i>=b;i--) #define fdd(i,a,b,c) for(int i=a;i>=b;i-=c) #define tr(it,a) for(auto& it:a) #define min(a,b) ((a<b)?a:b) #define max(a,b) ((a<b)?b:a) #define all(a) a.begin(),a.end() #define sz(a) (int)(a.size()) #define reset(a,n) a.clear(),a.resize(n) #define resetv(a,n,v) a.clear(),a.resize(n,v) #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char* name, Arg1&& arg1) {cerr<<name<<" : "<<arg1<<endl;} template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma=strchr(names+1,','); cerr.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1,args...);} #define gcd __gcd #define popc __builtin_popcount #define INF INT_MAX #define INFL LLONG_MAX #define endl '\n' #define spc ' ' #define pb emplace_back #define mp make_pair #define ins insert #define bgn begin #define rev reverse #define clr clear #define ers erase #define ass assign #define F first #define S second #define grt greater #define accu accumulate #define lo_bo lower_bound #define up_bo upper_bound #define max_el max_element #define min_el min_element #define nxt_prm next_permutation #define p_sum partial_sum #define mult multiplies<int>() #define PQ priority_queue typedef long double D; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<bool> VB; typedef vector<string> VS; typedef pair<int,int> PII; typedef vector<PII> VPII; typedef map<int,int> MII; typedef set<int> SI; typedef multiset<int> MSI; typedef queue<int> QI; void FastIO() {ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);cout.precision(15);} int power(int a, int p) {int ret=1;while(p){if(p&1)ret=(ret*a);a=(a*a);p/=2;}return ret;} // ___________________________Template Ends Here_________________________________ int n,m,t0,t1,t2,u,v,l1,l2; VVI g; VI dbeg,dend; map<PII,int> bus,walk; VI dijk(VPII &src, map<PII,int> &typ) { VI d(n,INFL); VB vis(n,0); set<PII> pq; for(auto vtx:src) pq.ins(vtx), d[vtx.S]=vtx.F; while(!pq.empty()) { int v=pq.bgn()->S, x=pq.bgn()->F; pq.ers(pq.bgn()); vis[v]=1; for(auto ch:g[v]) { int l=typ[mp(v,ch)]; if(not vis[ch] and d[v]+l<d[ch]) d[ch]=d[v]+l, pq.ins(mp(d[ch],ch)); } } return d; } int zoom() { VPII end; end.pb(mp(0,n-1)); VI dend=dijk(end,bus); if(dend[0]<=t0-t2) return t0-dend[0]; VPII mid; fi(i,0,n) if(dend[i]<=t0-t2) mid.pb(mp(dend[i],i)); VI dmid=dijk(mid,walk); if(dmid[0]<=t0-t1) return t0-dmid[0]; VPII beg; fi(i,0,n) if(dmid[i]<=t0) { if(dmid[i]>=t0-t1) beg.pb(mp(dmid[i],i)); else beg.pb(mp(t0-t1,i)); } VI dbeg=dijk(beg,bus); if(dbeg[0]<=t0) return t0-dbeg[0]; return -1; } int stroll() { VPII end; end.pb(mp(0,n-1)); VI dend=dijk(end,walk); VPII beg; fi(i,0,n) if(dend[i]<=t0) { if(dend[i]>=t0-t1) beg.pb(mp(dend[i],i)); else beg.pb(mp(t0-t1,i)); } VI dbeg=dijk(beg,bus); if(dbeg[0]<=t0) return t0-dbeg[0]; return -1; } void solve() { cin>>n>>m; cin>>t0>>t1>>t2; reset(g,n); bus.clr(); walk.clr(); fi(i,0,m) { cin>>u>>v>>l1>>l2; u--, v--; g[u].pb(v), g[v].pb(u); bus[mp(u,v)]=bus[mp(v,u)]=l1; walk[mp(u,v)]=walk[mp(v,u)]=l2; } cout<<max(zoom(),stroll())<<endl; } int32_t main() { FastIO(); int T; cin>>T; while(T--) solve(); return 0; }
2000G
wrong_submission
277,988,511
Java 8
TIME_LIMIT_EXCEEDED on test 18
import java.io.*; import java.util.*; public class CallDuringTheJourney { public static PrintWriter out; public static void main(String[] args)throws IOException{ JS sc=new JS(); out=new PrintWriter(System.out); int t=sc.nextInt(); outer: while(t-->0) { int n=sc.nextInt(); int m=sc.nextInt(); int t0=sc.nextInt(); int t1=sc.nextInt(); int t2=sc.nextInt(); ArrayList<ArrayList<int[]>>al=new ArrayList<>(); for(int i=0;i<n;i++) { al.add(new ArrayList<int[]>()); } for(int i=0;i<m;i++) { int a=sc.nextInt()-1; int b=sc.nextInt()-1; int bus=sc.nextInt(); int walk=sc.nextInt(); al.get(a).add(new int[] {b, bus, walk}); al.get(b).add(new int[] {a, bus, walk}); } int dist[]=new int[n]; Arrays.fill(dist, (int) -1e9); dist[n-1]=t0; PriorityQueue<Integer>q=new PriorityQueue<>((Integer p1,Integer p2)->-(dist[p1]-dist[p2])); // ArrayDeque<Integer>q=new ArrayDeque<>(); q.add(n-1); while(!q.isEmpty()) { int cur=q.poll(); for(int[] next:al.get(cur)) { int nexttime=dist[cur]-next[1]; if(nexttime>=t2||dist[cur]<=t1) { nexttime=dist[cur]-next[1]; }else { nexttime=dist[cur]-next[2]; nexttime=Math.max(nexttime, t1-next[1]); } if(dist[next[0]]<nexttime&&nexttime>=-20) { dist[next[0]]=nexttime; q.add(next[0]); } } } out.println(dist[0]>=0?dist[0]:-1); } out.close(); } static void add(HashMap<Integer,Integer> A, int key){ A.put(key,A.getOrDefault(key,0)+1); } static void remove(HashMap<Integer,Integer>A, int key){ if(!A.containsKey(key))return; A.put(key,A.get(key)-1); if(A.get(key)==0){ A.remove(key); } } static class Pair implements Comparable<Pair>{ int x, y; public Pair(int x, int y) { this.x=x;this.y=y; } public int compareTo(Pair p) { if(y==p.y) { return Integer.compare(x, p.x); } return Integer.compare(y, p.y); } } // static class Triple{ // int node, bus, walk; // public Triple(int node, int bus, int walk) { // this.node=node;this.bus=bus;this.walk=walk; // } // } static void sort(int a[]) { ArrayList<Integer>al=new ArrayList<>(); for(int i=0;i<a.length;i++) { al.add(a[i]); } Collections.sort(al); for(int i=0;i<a.length;i++) { a[i]=al.get(i); } } static class JS { public int BS = 1<<16; public char NC = (char)0; byte[] buf = new byte[BS]; int bId = 0, size = 0; char c = NC; double num = 1; BufferedInputStream in; public JS() { in = new BufferedInputStream(System.in, BS); } public JS(String s) throws FileNotFoundException { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } public char nextChar(){ while(bId==size) { try { size = in.read(buf); }catch(Exception e) { return NC; } if(size==-1)return NC; bId=0; } return (char)buf[bId++]; } public int nextInt() { return (int)nextLong(); } public long nextLong() { num=1; boolean neg = false; if(c==NC)c=nextChar(); for(;(c<'0' || c>'9'); c = nextChar()) { if(c=='-')neg=true; } long res = 0; for(; c>='0' && c <='9'; c=nextChar()) { res = (res<<3)+(res<<1)+c-'0'; num*=10; } return neg?-res:res; } public double nextDouble() { double cur = nextLong(); return c!='.' ? cur:cur+nextLong()/num; } public String next() { StringBuilder res = new StringBuilder(); while(c<=32)c=nextChar(); while(c>32) { res.append(c); c=nextChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while(c<=32)c=nextChar(); while(c!='\n') { res.append(c); c=nextChar(); } return res.toString(); } public boolean hasNext() { if(c>32)return true; while(true) { c=nextChar(); if(c==NC)return false; else if(c>32)return true; } } } }
2000G
wrong_submission
277,977,577
Java 8
TIME_LIMIT_EXCEEDED on test 18
import java.io.*; import java.util.*; public class CallDuringTheJourney { public static PrintWriter out; public static void main(String[] args)throws IOException{ JS sc=new JS(); out=new PrintWriter(System.out); int t=sc.nextInt(); outer: while(t-->0) { int n=sc.nextInt(); int m=sc.nextInt(); int t0=sc.nextInt(); int t1=sc.nextInt(); int t2=sc.nextInt(); ArrayList<ArrayList<Triple>>al=new ArrayList<>(); for(int i=0;i<n;i++) { al.add(new ArrayList<Triple>()); } for(int i=0;i<m;i++) { int a=sc.nextInt()-1; int b=sc.nextInt()-1; int bus=sc.nextInt(); int walk=sc.nextInt(); al.get(a).add(new Triple(b, bus, walk)); al.get(b).add(new Triple(a, bus, walk)); } int dist[]=new int[n]; Arrays.fill(dist, (int) -1e9); dist[n-1]=t0; PriorityQueue<Integer>q=new PriorityQueue<>((q1, q2)->-Integer.compare(dist[q1], dist[q2])); q.add(n-1); while(!q.isEmpty()) { int cur=q.poll(); for(Triple next:al.get(cur)) { int nexttime=dist[cur]-next.bus; if(nexttime>=t2||dist[cur]<=t1) { nexttime=dist[cur]-next.bus; }else { nexttime=dist[cur]-next.walk; nexttime=Math.max(nexttime, t1-next.bus); } if(dist[next.node]<nexttime) { dist[next.node]=nexttime; q.add(next.node); } } } out.println(dist[0]>=0?dist[0]:-1); } out.close(); } static void add(HashMap<Integer,Integer> A, int key){ A.put(key,A.getOrDefault(key,0)+1); } static void remove(HashMap<Integer,Integer>A, int key){ if(!A.containsKey(key))return; A.put(key,A.get(key)-1); if(A.get(key)==0){ A.remove(key); } } static class Pair implements Comparable<Pair>{ int x, y; public Pair(int x, int y) { this.x=x;this.y=y; } public int compareTo(Pair p) { if(y==p.y) { return Integer.compare(x, p.x); } return Integer.compare(y, p.y); } } static class Triple{ int node, bus, walk; public Triple(int node, int bus, int walk) { this.node=node;this.bus=bus;this.walk=walk; } } static void sort(int a[]) { ArrayList<Integer>al=new ArrayList<>(); for(int i=0;i<a.length;i++) { al.add(a[i]); } Collections.sort(al); for(int i=0;i<a.length;i++) { a[i]=al.get(i); } } static class JS { public int BS = 1<<16; public char NC = (char)0; byte[] buf = new byte[BS]; int bId = 0, size = 0; char c = NC; double num = 1; BufferedInputStream in; public JS() { in = new BufferedInputStream(System.in, BS); } public JS(String s) throws FileNotFoundException { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } public char nextChar(){ while(bId==size) { try { size = in.read(buf); }catch(Exception e) { return NC; } if(size==-1)return NC; bId=0; } return (char)buf[bId++]; } public int nextInt() { return (int)nextLong(); } public long nextLong() { num=1; boolean neg = false; if(c==NC)c=nextChar(); for(;(c<'0' || c>'9'); c = nextChar()) { if(c=='-')neg=true; } long res = 0; for(; c>='0' && c <='9'; c=nextChar()) { res = (res<<3)+(res<<1)+c-'0'; num*=10; } return neg?-res:res; } public double nextDouble() { double cur = nextLong(); return c!='.' ? cur:cur+nextLong()/num; } public String next() { StringBuilder res = new StringBuilder(); while(c<=32)c=nextChar(); while(c>32) { res.append(c); c=nextChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while(c<=32)c=nextChar(); while(c!='\n') { res.append(c); c=nextChar(); } return res.toString(); } public boolean hasNext() { if(c>32)return true; while(true) { c=nextChar(); if(c==NC)return false; else if(c>32)return true; } } } }
2000G
wrong_submission
276,281,765
PyPy 3-64
TIME_LIMIT_EXCEEDED on test 18
from collections import defaultdict from heapq import heapify, heappush, heappop for _ in range(int(input())): n, m = map(int, input().split()) t0, t1, t2 = map(int, input().split()) streets = [list(map(int, input().split())) for _ in range(m)] graph = defaultdict(dict) for u, v, w, z in streets: graph[u][v] = [w, z] graph[v][u] = [w, z] q = [[-t0, n]] maxtime = {n: t0} while q: time, node = heappop(q) time = -time for ne, (bus, st) in graph[node].items(): streetime = time-st if ne not in maxtime or maxtime[ne] < streetime: maxtime[ne] = streetime heappush(q, [-streetime, ne]) if time > t1 and time - bus < t2: bustime = t1 - bus else: bustime = time-bus if ne not in maxtime or maxtime[ne] < bustime: maxtime[ne] = bustime heappush(q, [-bustime, ne]) if 1 not in maxtime or maxtime[1] < 0: print(-1) else: print(maxtime[1])
2000G
wrong_submission
276,923,622
C++20 (GCC 13-64)
TIME_LIMIT_EXCEEDED on test 18
#include <vector> #include <iostream> #include <cmath> #include <map> #include <algorithm> #include <set> #include <queue> #define int long long using namespace std; typedef pair<int, int> pr; typedef pair<pair<int, int>, int> tpl; int inf = 1e15; int mod = 1e9 + 7; struct Edge{ int to, tm1, tm2; }; signed main() { int tt; cin >> tt; while(tt--){ int n, m; cin >> n >> m; Edge cur1, cur2; int t0, t1, t2; cin >> t0 >> t1 >> t2; vector<vector<Edge>> graph(n); int a, b, l1, l2; for(int i = 0; i < m; i++){ cin >> a >> b >> l1 >> l2; a--; b--; cur1 = {b, l1, l2}; cur2 = {a, l1, l2}; graph[a].push_back(cur1); graph[b].push_back(cur2); } //Дейкстра, нам нужно получить путь из vector<int> dists(n, -inf); vector<bool> used(n, false); set<pr> heap; // первое значение - время, второе пункт heap.insert({t0, n - 1}); pr cur; used[n - 1] = true; int time; int x1, y1, x2, y2, f, s; dists[n - 1] = t0; while(!used[0]){ auto it = heap.end(); it--; cur = *it; heap.erase(it); used[cur.second] = true; for(Edge x : graph[cur.second]){ if(used[x.to]) continue; //нужна проверка, что мы не попадаем если путешествуем на автобусе на телефонный звонок time = cur.first - x.tm1; x1 = time; y1 = cur.first; x2 = t1; y2 = t2; if(x2 < x1){ int c = x1; x1 = x2; x2 = c; c = y1; y1 = y2; y2 = c; } if(!(x2 >= y1)){ //то есть если пересекаются //первый вариант - мы стоим на остановке до окончания звонка f = t1 - x.tm1; //второй - идем пешком s = cur.first - x.tm2; //берем максимум if(max(f, s) > dists[x.to]){ dists[x.to] = max(f, s); heap.insert({dists[x.to], x.to}); } } else{ if(time > dists[x.to]){ dists[x.to] = time; heap.insert({dists[x.to], x.to}); } } } } if(dists[0] < 0){ cout << -1 << '\n'; } else{ cout << dists[0] << '\n'; } } return 0; }
2000G
wrong_submission
293,704,653
C++17 (GCC 7-32)
TIME_LIMIT_EXCEEDED on test 18
#include <bits/stdc++.h> using namespace std; #define ll long long void jawaab() { int n,m; cin>>n>>m; vector<vector<vector<ll>>>graph(n); ll t0, t2, t1; cin>>t0>>t2>>t1; ll u,v,c1,c2; for(int i=0; i<m; i++) { cin>>u>>v>>c1>>c2; graph[u-1].push_back({v-1,c1,c2}); graph[v-1].push_back({u-1,c1,c2}); } // ll ans = -1; // ll start = 0, end = t0; // while(start <= end) { t1 = t0 - t1; t2 = t0 - t2; priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>>pq; vector<ll>dis(n,1e18); dis[n-1] = 0; pq.push({0,n-1}); while(!pq.empty()) { ll x = pq.top().first; int y = pq.top().second; pq.pop(); if(x > t0) continue; for(auto j: graph[y]) { ll bus = j[1]; ll walk = j[2]; ll final; if((x >= t1) && (x < t2)) { final = min(x+walk, t2+bus); } else if((x < t1) && ((x+bus) > t1)) { final = min(x+walk, t2+bus); } else { final = x+min(walk,bus); } // cout<<j[0]<<" "<<final<<endl; if(dis[j[0]] > final) { dis[j[0]] = final; pq.push({dis[j[0]],j[0]}); } } // if(dis[n-1] <= t0) { // ans = mid; // start = mid+1; // } // else { // end = mid-1; // } // for(int i=0; i<n; i++) cout<<dis[i]<<" "; // cout<<endl; } cout<<max(-1*1LL,t0-dis[0])<<endl; } int main() { int t; cin>>t; while(t--) { jawaab(); } return 0; }
2000G
wrong_submission
277,987,892
Java 8
TIME_LIMIT_EXCEEDED on test 18
import java.io.*; import java.util.*; public class CallDuringTheJourney { public static PrintWriter out; public static void main(String[] args)throws IOException{ JS sc=new JS(); out=new PrintWriter(System.out); int t=sc.nextInt(); outer: while(t-->0) { int n=sc.nextInt(); int m=sc.nextInt(); int t0=sc.nextInt(); int t1=sc.nextInt(); int t2=sc.nextInt(); ArrayList<ArrayList<int[]>>al=new ArrayList<>(); for(int i=0;i<n;i++) { al.add(new ArrayList<int[]>()); } for(int i=0;i<m;i++) { int a=sc.nextInt()-1; int b=sc.nextInt()-1; int bus=sc.nextInt(); int walk=sc.nextInt(); al.get(a).add(new int[] {b, bus, walk}); al.get(b).add(new int[] {a, bus, walk}); } int dist[]=new int[n]; Arrays.fill(dist, (int) -1e9); dist[n-1]=t0; PriorityQueue<Integer>q=new PriorityQueue<>((Integer p1,Integer p2)->-Integer.compare(dist[p1],dist[p2])); // ArrayDeque<Integer>q=new ArrayDeque<>(); q.add(n-1); while(!q.isEmpty()) { int cur=q.poll(); for(int[] next:al.get(cur)) { int nexttime=dist[cur]-next[1]; if(nexttime>=t2||dist[cur]<=t1) { nexttime=dist[cur]-next[1]; }else { nexttime=dist[cur]-next[2]; nexttime=Math.max(nexttime, t1-next[1]); } if(dist[next[0]]<nexttime&&nexttime>=-20) { dist[next[0]]=nexttime; q.add(next[0]); } } } out.println(dist[0]>=0?dist[0]:-1); } out.close(); } static void add(HashMap<Integer,Integer> A, int key){ A.put(key,A.getOrDefault(key,0)+1); } static void remove(HashMap<Integer,Integer>A, int key){ if(!A.containsKey(key))return; A.put(key,A.get(key)-1); if(A.get(key)==0){ A.remove(key); } } static class Pair implements Comparable<Pair>{ int x, y; public Pair(int x, int y) { this.x=x;this.y=y; } public int compareTo(Pair p) { if(y==p.y) { return Integer.compare(x, p.x); } return Integer.compare(y, p.y); } } // static class Triple{ // int node, bus, walk; // public Triple(int node, int bus, int walk) { // this.node=node;this.bus=bus;this.walk=walk; // } // } static void sort(int a[]) { ArrayList<Integer>al=new ArrayList<>(); for(int i=0;i<a.length;i++) { al.add(a[i]); } Collections.sort(al); for(int i=0;i<a.length;i++) { a[i]=al.get(i); } } static class JS { public int BS = 1<<16; public char NC = (char)0; byte[] buf = new byte[BS]; int bId = 0, size = 0; char c = NC; double num = 1; BufferedInputStream in; public JS() { in = new BufferedInputStream(System.in, BS); } public JS(String s) throws FileNotFoundException { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } public char nextChar(){ while(bId==size) { try { size = in.read(buf); }catch(Exception e) { return NC; } if(size==-1)return NC; bId=0; } return (char)buf[bId++]; } public int nextInt() { return (int)nextLong(); } public long nextLong() { num=1; boolean neg = false; if(c==NC)c=nextChar(); for(;(c<'0' || c>'9'); c = nextChar()) { if(c=='-')neg=true; } long res = 0; for(; c>='0' && c <='9'; c=nextChar()) { res = (res<<3)+(res<<1)+c-'0'; num*=10; } return neg?-res:res; } public double nextDouble() { double cur = nextLong(); return c!='.' ? cur:cur+nextLong()/num; } public String next() { StringBuilder res = new StringBuilder(); while(c<=32)c=nextChar(); while(c>32) { res.append(c); c=nextChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while(c<=32)c=nextChar(); while(c!='\n') { res.append(c); c=nextChar(); } return res.toString(); } public boolean hasNext() { if(c>32)return true; while(true) { c=nextChar(); if(c==NC)return false; else if(c>32)return true; } } } }
2000G
wrong_submission
277,987,686
Java 8
TIME_LIMIT_EXCEEDED on test 18
import java.io.*; import java.util.*; public class CallDuringTheJourney { public static PrintWriter out; public static void main(String[] args)throws IOException{ JS sc=new JS(); out=new PrintWriter(System.out); int t=sc.nextInt(); outer: while(t-->0) { int n=sc.nextInt(); int m=sc.nextInt(); int t0=sc.nextInt(); int t1=sc.nextInt(); int t2=sc.nextInt(); ArrayList<ArrayList<Triple>>al=new ArrayList<>(); for(int i=0;i<n;i++) { al.add(new ArrayList<Triple>()); } for(int i=0;i<m;i++) { int a=sc.nextInt()-1; int b=sc.nextInt()-1; int bus=sc.nextInt(); int walk=sc.nextInt(); al.get(a).add(new Triple(b, bus, walk)); al.get(b).add(new Triple(a, bus, walk)); } int dist[]=new int[n]; Arrays.fill(dist, (int) -1e9); dist[n-1]=t0; PriorityQueue<Integer>q=new PriorityQueue<>((Integer p1,Integer p2)->-Integer.compare(dist[p1],dist[p2])); // ArrayDeque<Integer>q=new ArrayDeque<>(); q.add(n-1); while(!q.isEmpty()) { int cur=q.poll(); for(Triple next:al.get(cur)) { int nexttime=dist[cur]-next.bus; if(nexttime>=t2||dist[cur]<=t1) { nexttime=dist[cur]-next.bus; }else { nexttime=dist[cur]-next.walk; nexttime=Math.max(nexttime, t1-next.bus); } if(dist[next.node]<nexttime&&nexttime>=-20) { dist[next.node]=nexttime; q.add(next.node); } } } out.println(dist[0]>=0?dist[0]:-1); } out.close(); } static void add(HashMap<Integer,Integer> A, int key){ A.put(key,A.getOrDefault(key,0)+1); } static void remove(HashMap<Integer,Integer>A, int key){ if(!A.containsKey(key))return; A.put(key,A.get(key)-1); if(A.get(key)==0){ A.remove(key); } } static class Pair implements Comparable<Pair>{ int x, y; public Pair(int x, int y) { this.x=x;this.y=y; } public int compareTo(Pair p) { if(y==p.y) { return Integer.compare(x, p.x); } return Integer.compare(y, p.y); } } static class Triple{ int node, bus, walk; public Triple(int node, int bus, int walk) { this.node=node;this.bus=bus;this.walk=walk; } } static void sort(int a[]) { ArrayList<Integer>al=new ArrayList<>(); for(int i=0;i<a.length;i++) { al.add(a[i]); } Collections.sort(al); for(int i=0;i<a.length;i++) { a[i]=al.get(i); } } static class JS { public int BS = 1<<16; public char NC = (char)0; byte[] buf = new byte[BS]; int bId = 0, size = 0; char c = NC; double num = 1; BufferedInputStream in; public JS() { in = new BufferedInputStream(System.in, BS); } public JS(String s) throws FileNotFoundException { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } public char nextChar(){ while(bId==size) { try { size = in.read(buf); }catch(Exception e) { return NC; } if(size==-1)return NC; bId=0; } return (char)buf[bId++]; } public int nextInt() { return (int)nextLong(); } public long nextLong() { num=1; boolean neg = false; if(c==NC)c=nextChar(); for(;(c<'0' || c>'9'); c = nextChar()) { if(c=='-')neg=true; } long res = 0; for(; c>='0' && c <='9'; c=nextChar()) { res = (res<<3)+(res<<1)+c-'0'; num*=10; } return neg?-res:res; } public double nextDouble() { double cur = nextLong(); return c!='.' ? cur:cur+nextLong()/num; } public String next() { StringBuilder res = new StringBuilder(); while(c<=32)c=nextChar(); while(c>32) { res.append(c); c=nextChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while(c<=32)c=nextChar(); while(c!='\n') { res.append(c); c=nextChar(); } return res.toString(); } public boolean hasNext() { if(c>32)return true; while(true) { c=nextChar(); if(c==NC)return false; else if(c>32)return true; } } } }
2000G
wrong_submission
276,831,885
Java 21
TIME_LIMIT_EXCEEDED on test 18
//package Codeforces; import java.util.*; public class CallDuringTheJourney { final static Scanner sc = new Scanner(System.in); public static void main(String[] args) { int testcases = sc.nextInt(); for (int test = 0; test<testcases; ++test) { int n = sc.nextInt(); int m = sc.nextInt(); Graph g = new Graph(n, m); int t0 = sc.nextInt(); int t1 = sc.nextInt(); int t2 = sc.nextInt(); for(int i=0; i<m; ++i){ int u = sc.nextInt(); int v = sc.nextInt(); int bussTime = sc.nextInt(); int walkTime = sc.nextInt(); g.createEdge(u, v, bussTime, walkTime); } int result = findTimeToReach(g, t0, t1, t2); System.out.println(result); } } private static int findTimeToReach(Graph g, int t0, int t1, int t2){ g.populateMaxTimeToReach(t0, t1, t2); return g.nodes.get(0).maxTimeTorReach; } private static boolean isOverlappingInterval(int busTime, int maxTimeTorReach, int t1, int t2) { return (t2 > busTime && t1 < maxTimeTorReach); } public static class Graph{ List<Node> nodes; List<Edge> edges; Map<Node, List<Edge>> adjacencyList; static int edgeid = 0; int N; int M; Graph(int N, int M){ this.N = N; this.M = M; nodes = new ArrayList<Node>(); edges = new ArrayList<>(); adjacencyList = new HashMap<>(); for(int i = 0; i < N; i++){ Node u = new Node(i); nodes.add(u); adjacencyList.put(u, new ArrayList<>()); } } void populateMaxTimeToReach(int t0, int t1, int t2){ nodes.get(N-1).maxTimeTorReach = t0; PriorityQueue<Graph.Node> pq = new PriorityQueue<>(); pq.add(nodes.get(N-1)); Set<Integer> visited = new HashSet<>(); while(!pq.isEmpty()){ Graph.Node node = pq.poll(); visited.add(node.id); for(Graph.Edge edge: adjacencyList.get(node)){ Graph.Node neib = edge.u; if(edge.u.id == node.id){ neib = edge.v; } int walkTime = node.maxTimeTorReach - edge.walkTime; int busTime = node.maxTimeTorReach - edge.busTime; if(isOverlappingInterval(busTime, node.maxTimeTorReach, t1, t2)){ busTime = t1 - edge.busTime; } int mx = Math.max(walkTime, busTime); if(neib.maxTimeTorReach < mx){ pq.add(neib); neib.maxTimeTorReach = mx; } } } } public static class Node implements Comparable<Node>{ int id; int maxTimeTorReach; Node(int id){ this.id = id; this.maxTimeTorReach = -1; } @Override public int compareTo(Node o) { return o.maxTimeTorReach - this.maxTimeTorReach; } } public static class Edge{ int id; Node u; Node v; int walkTime; int busTime; public Edge(Node u, Node v, int walkTime, int busTime) { this.u = u; this.v = v; this.walkTime = walkTime; this.busTime = busTime; this.id = edgeid; edgeid++; } } void createEdge(int u, int v, int busTime, int walkTime){ u--; v--; Node uNode = nodes.get(u); Node vNode = nodes.get(v); Edge edge = new Edge(uNode, vNode, walkTime, busTime); adjacencyList.get(uNode).add(edge); adjacencyList.get(vNode).add(edge); } } }
2000G
wrong_submission
276,725,989
PyPy 3-64
TIME_LIMIT_EXCEEDED on test 18
import sys from math import inf from collections import Counter, deque from itertools import accumulate li = lambda: sys.stdin.readline().rstrip() lli = lambda: sys.stdin.readline().rstrip().split() Q = lambda: list(map(int, lli())) from heapq import heappush, heappop for _ in range(int(li())): n,m = Q() t0,t1,t2 = Q() res = [[] for i in range(n+1)] res1 = [[] for i in range(n+1)] for i in range(m): u,v,l,r = Q() res[u].append([v, l]) res[v].append([u, l]) res1[u].append([v, r]) res1[v].append([u, r]) h = [] heappush(h, [-t0, n]) ans = [-inf] * (n+1) # print(res) while h: t, node = heappop(h) # print(-t, node, ans) if node == 1: break t = -t for j,k in res[node]: if t <= t1 or t-k >= t2: if t-k > ans[j]: ans[j] = t-k heappush(h, [-(t-k), j]) elif t-k < t2 and t > t1: # 可以早点出发 多接一会手机 再坐车 if t1-k > ans[j]: ans[j] = t1-k heappush(h, [-(t1-k), j]) for j,k in res1[node]: if t-k > ans[j]: ans[j] = t-k heappush(h, [-(t-k), j]) print(-1 if ans[1]<0 else ans[1])
2000G
wrong_submission
278,733,087
PyPy 3-64
TIME_LIMIT_EXCEEDED on test 18
def solve(): n, m = [int(i) for i in input().split()] t0, t1, t2 = [int(i) for i in input().split()] G = dict() for i in range(m): #made graph start, end, bus, walk = [int(i) for i in input().split()] if start not in G: G[start] = [[end,(bus,walk)]] else: G[start].append([end,(bus,walk)]) if end not in G: G[end] = [[start,(bus,walk)]] else: G[end].append([start,(bus,walk)]) #Djikstras from the end (node n) to start (node 1) using latest, latest[n]=t0 #if he can ride bus (not on call), ride bus #else choose max (starting time) of walking and waiting for call to end then ride bus latest = [-1]*(n)+[t0] cur = n; vis = []; frontier = [n] while True: #if cur=k, then we have the shortest path to k cur = frontier[0] #pick largest time for i in frontier: if latest[i] > latest[cur]: cur = i if cur == 1: break frontier.remove(cur) vis.append(cur) for prev, time in G[cur]: if prev in vis: continue bus = time[0]; walk = time[1] a = latest[cur] if (t2 <= a - bus) or (t1 >= a): #can ride bus latest[prev] = max(latest[prev], a - bus) else: latest[prev] = max(latest[prev], t1 - bus, a - walk) if prev not in frontier: frontier.append(prev) print(latest[1]) for test in range(int(input())): solve()
2000G
wrong_submission
280,349,670
PyPy 3-64
TIME_LIMIT_EXCEEDED on test 18
from heapq import heappop, heappush for _ in range(int(input())): n, m = list(map(int, input().split())) t0, t1, t2 = list(map(int, input().split())) g = [[] for _ in range(n+1)] for _ in range(m): u, v, l1, l2 = list(map(int, input().split())) g[u].append((v, l1, l2)) g[v].append((u, l1, l2)) best = [float('inf')]*n + [0] fet = [False]*n + [True] heap = [(0, n)] while heap: t, u = heappop(heap) fet[u] = True if u == 1: break for v, l1, l2 in g[u]: if fet[v]: continue best[v] = min(best[v], best[u] + l2) if best[u] + l1 <= t0-t2: best[v] = min(best[v], best[u] + l1) best[v] = min(best[v], max(t0 - t1, best[u]) + l1) heappush(heap, (best[v], v)) print(max(t0-best[1], -1))
2000G
wrong_submission
279,375,476
PyPy 3-64
TIME_LIMIT_EXCEEDED on test 19
import heapq, math from collections import Counter, defaultdict, deque from functools import cache import io,os import sys # input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline t = int(input()) ret = [] MOD = 1_000_000_007 for _ in range(t): # n = int(input()) n, m = list(map(int, input().split())) deadline, pstart, pend = list(map(int, input().split())) # m = int(input()) # s = input() adj = defaultdict(list) for _ in range(m): u, v, c1, c2 = list(map(int, input().split())) u -= 1 v -= 1 adj[u].append((v, c1, c2)) adj[v].append((u, c1, c2)) def overlap(a, b, x, y): return not (b < x or y < a) def check(start): h = [(start, 0)] vis = [math.inf] * n vis[0] = h[0][0] # print('--------------START---------------') while h: # print(h) time, curr = heapq.heappop(h) if time > vis[curr]: continue if time > deadline: return False if curr == n - 1: return True for j, c1, c2 in adj[curr]: if not overlap(time, time + c1, pstart + 1, pend - 1) and vis[j] > time + c1 and time + c1 <= deadline: vis[j] = time + c1 heapq.heappush(h, (time + c1, j)) if time <= pend and vis[j] > pend + c1 and pend + c1 <= deadline: vis[j] = pend + c1 heapq.heappush(h, (pend + c1, j)) if vis[j] > time + c2 and time + c2 <= deadline: vis[j] = time + c2 heapq.heappush(h, (time + c2, j)) def bins(start, end): if start >= end: return -math.inf if start + 1 == end: return start if check(start) else -math.inf mid = (start + end) // 2 if not check(mid): return bins(start, mid) else: return max(mid, bins(mid + 1, end)) l = 0 r = deadline + 1 res = -1 while l < r: mid = (l + r) // 2 if check(mid): res = mid l = mid + 1 else: r = mid # res = bins(0, deadline + 1) # ret.append((res if res != -math.inf else -1)) print((res if res != -math.inf else -1)) # print(ret) # 1 # 4 4 # 100 40 60 # 1 2 30 100 # 2 4 30 100 # 1 3 20 50 # 3 4 20 50 # 1 # 2 1 # 12 9 10 # 2 1 6 10 # 1 # 5 5 # 100 20 80 # 1 5 30 100 # 1 2 20 50 # 2 3 20 50 # 3 4 20 50 # 4 5 20 50
2000G
wrong_submission
276,338,110
PyPy 3-64
TIME_LIMIT_EXCEEDED on test 20
import sys input = sys.stdin.readline import heapq def check(x): q = [(x, 0)] D[0] = x while q: a,b = heapq.heappop(q) if D[b] == a: for c,l1,l2 in G[b]: if a+l1<=t1: if a+l1<D[c]: D[c]=a+l1 heapq.heappush(q,(a+l1,c)) elif max(a, t2)+l1<D[c]: D[c]=max(a,t2)+l1 heapq.heappush(q, (max(a, t2) + l1, c)) if a+l2 <= D[c]: D[c] = a+l2 heapq.heappush(q, (a + l2, c)) # print(a,b,D) # print(D,x) return D[-1] <= t0 for _ in range(int(input())): n, m = map(int, input().split()) t0, t1, t2 = map(int, input().split()) G = [[] for i in range(n)] for _ in range(m): a, b, l1, l2 = map(int, input().split()) a-=1;b-= 1 G[a].append((b,l1,l2)) G[b].append((a,l1,l2)) lo = -1 hi = t0 + 1 D = [int(1e15)] * n while hi - lo > 1: for i in range(n):D[i]=t0+1 mid = (lo + hi) // 2 if check(mid):lo = mid else:hi = mid print(lo)
2000G
wrong_submission