제출 #1128438

#제출 시각아이디문제언어결과실행 시간메모리
1128438AgageldiToll (BOI17_toll)C++20
7 / 100
335 ms12280 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define N 400005 #define ff first #define ss second #define pb push_back #define sz(s) (int)s.size() #define rep(c, a, b) for(c = a; c <= b; c++) ll n, m, K, p[N], o, par[N]; vector <pair<int,int>> v[N]; int main () { ios::sync_with_stdio(0);cin.tie(0); cin >> K >> n >> m >> o; for(int i = 1; i <= m; i++) { int x, y, t; cin >> x >> y >> t; x++; y++; v[x].pb({y,t}); par[x] = y; } for(int i = 1; i <= n; i++) { if(!sz(v[i])) continue; p[i] = p[i - 1]; p[i] += v[i][0].ss; } for(int i = 1; i <= o; i++) { int x, y; cin >> x >> y; x++; y++; int l = x; while(par[l] != 0) { if(l == y) break; l = par[l]; } if(l!=y) { cout << "-1\n"; continue;; } cout << p[y - 1] - p[x - 1] << '\n'; } }
#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...