| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1122385 | qrn | Autobus (COCI22_autobus) | C++14 | 1054 ms | 1876 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define SPEED \
ios_base::sync_with_stdio(0); \
cin.tie(NULL); \
cout.tie(NULL);
#define pb push_back
#define endl "\n"
#define ALL(x) x.begin(), x.end()
#define intt long long
const intt mxN = 2e5 + 5, L = 20, mxA = 1e6 + 35;
struct edge{
intt l, r;
};
vector<vector<intt>>graph;
vector<intt>visited(mxN);
vector<intt>path;
map<pair<intt,intt>,intt>vals;
intt ans = mxA;
void dfs(intt u, intt end, intt k) {
visited[u] = true;
path.pb(u);
if (u == end) {
if(path.size()-1 <= k) {
intt sum = 0;
for(int i = 1; i < path.size(); i++) {
// cout << path[i] << " ";
sum += vals[{min(path[i-1],path[i]),max(path[i-1],path[i])}];
}
ans = min(ans, sum);
// cout << endl;
} else {
// for(auto u : path) cout << u << " ";
// cout << endl;
}
} else {
for (auto v : graph[u]) {
if (!visited[v]) {
dfs(v, end, k);
}
}
}
path.pop_back();
visited[u] = false;
}
void solve() {
intt n, m;
cin >> n >> m;
graph.resize(n + 1);
for(intt i = 1; i <= m; i++) {
intt a, b, w;
cin >> a >> b >> w;
graph[a].pb(b);
vals[{min(a,b), max(a,b)}] = w;
}
intt k, q;
cin >> k >> q;
while(q--) {
intt l, r;
cin >> l >> r;
dfs(l, r, k);
if(ans == mxA) cout << -1 << endl;
else
cout << ans << endl;
ans = mxA;
}
}
int main() {
SPEED;
int tst = 1;
// cin >> tst;
while (tst--) {
solve();
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
