제출 #1207437

#제출 시각아이디문제언어결과실행 시간메모리
1207437dksnfjkfnwkfwToll (BOI17_toll)C++20
7 / 100
80 ms51404 KiB
#include <bits/stdc++.h> using namespace std; #define sonic ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0) #define IO(main) if(fopen(main".inp","r")){freopen(main".inp","r",stdin);freopen(main".out","w",stdout);} #define pb push_back #define fi first #define se second #define mp make_pair #define ins insert #define pb push_back #define el cout << endl #define SZ(x) ((int)(x).size()) #define ALL(x) (x).begin(), (x).end() #define MASK(i) ((1LL)<<(i)) #define BIT(x,i) (((x)>>(i))&(1LL)) #define FOR(i, a, b) for(int (i)=(a);(i)<=(b); i++) #define FORD(i, a, b) for(int (i)=(a);(i)>=(b); i--) using ll = long long; #define int ll using ull = unsigned long long; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vii = vector<pii>; const int N = 1e6 + 9; const int mod = 1e9 + 7; const ll INF = 1e15 + 7; const int base = 31; const int LOG = 20; const ll MOD = 1e9 + 7; int mul(int x, int y) {return 1LL * x * y % mod;} int calPw(int x, int y) { int ans = 1; while(y) { if (y&1) ans = 1LL * ans * x % mod; x = 1LL * x * x % mod; y >>= 1; } return ans; } int d4x[4] = {1, 0, -1, 0}; int d4y[4] = {0, 1, 0, -1}; int dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}; int dy[8] = {1, 1, 0, -1, -1, -1, 0, 1}; ///Author: Le Chi Thien Luong The Vinh high school 2008 ///code template<class X, class Y> bool minimize(X &x , Y y){ if(x > y){ x = y; return true; } return false; } template<class X, class Y> bool maximize(X &x , Y y){ if(x < y){ x = y; return true; } return false; } template<class X, class Y> bool add(X &x , Y y){ if((x + y ) >= mod){ ll tmp = x + y; x = tmp - mod; return true; } return false; } void Solve(){ } int k, n, m, q; vector<pii>adj[N]; ll dp[N]; pii edge[N]; vector<pii>V[N]; int mx[N]; int ans[N]; int cnt[N]; void Read(){ cin >> k >> n >> m >> q; FOR(i, 0, n)mx[i] = INF; FOR(i, 1, m){ int u, v, w; cin >> u >> v >> w; mx[u] = min(mx[u], w); adj[u].push_back({v, w}); cnt[u]++; } if(k == 1){ /// FOR(i, 0, n - 1)cout << mx[i] << " ";el;el; FOR(i, 0, n - 1)mx[i] += mx[i - 1]; FOR(i, 1, q){ int u, v; cin >> u >> v; int ans = mx[v - 1] - mx[u - 1]; // FOR(j, u, v - 1){ // ans += mx[j]; // if(mx[j] == INF){ // ans =-1; // break; // } // } if(ans > 1e9 || ans <= 0)ans = -1; cout << ans << endl; }return; } set<int>st; FOR(i, 1, q){ int u, v; cin >> u >> v; st.insert(u); mx[u] = max(mx[u], v); V[u].push_back({v, i}); } for(int u : st){ if(cnt[u] == 0){ for(pii v : V[u]){ ans[v.se] = -1; continue; } continue; } FOR(i, 0, mx[u])dp[i] = INF; dp[u] =0; FOR(i, 1, mx[u]){ for(pii v : adj[i]){ dp[v.fi] = min(dp[v.fi], dp[i] + v.se); } } for(pii v : V[u]){ ans[v.se] = dp[v.fi]; } } FOR(i, 1, q){ if(ans[i] >= INF)ans[i] = -1; cout << ans[i] << endl; } /// cout << (3/4 + 1) * k + k - 1<< endl; } signed main() { sonic; int TEST = 1; // cin >> TEST; while(TEST--) { Read(); Solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...