| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 683286 | yogesh_sane | Commuter Pass (JOI18_commuter_pass) | C++17 | 857 ms | 262144 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <climits>
using namespace std;
int n, m, s, t, u, v;
vector<vector<int>>parents;
vector<vector<int>>paths;
vector<int>path;
void dfs(int node){
path.push_back(node);
if(node == s){
paths.push_back(path);
}else{
for(auto p : parents[node]){
dfs(p);
}
}
path.pop_back();
}
int main() {
cin >> n >> m >> s >> t >> u >> v;
vector<vector<pair<int, int>>> adj(n+1);
for(int i = 0; i < m; i++){
int a, b, c;
cin >> a >> b >> c;
adj[a].push_back({b,c});
adj[b].push_back({a,c});
}
priority_queue<pair<long long,int>> q;
vector<long long> dist(n+1, LONG_LONG_MAX);
parents = vector<vector<int>>(n+1);
vector<bool> visited(n+1);
parents[s].push_back(s);
dist[s] = 0;
q.push({0,s});
while(!q.empty()){
pair<long long, int> a = q.top();
q.pop();
if(visited[a.second])
continue;
visited[a.second] = true;
for(auto edge : adj[a.second]){
int b = edge.first;
int weight = edge.second;
if(dist[a.second] + weight < dist[b]){
dist[b] = dist[a.second] + weight;
parents[b].clear();
parents[b].push_back(a.second);
q.push({-dist[b],b});
}else if(-a.first + weight == dist[b]){
parents[b].push_back(a.second);
}
}
}
dfs(t);
long long ans = LONG_LONG_MAX;
for(int i = 0; i < paths.size(); i++){
vector<int> sp = paths[i];
vector<vector<pair<int,int>>> adj2 = adj;
for(int j = 1; j < sp.size(); j++){
for(int k = 0; k < adj2[sp[j]].size(); k++){
if(adj2[sp[j]][k].first == sp[j-1])
adj2[sp[j]][k].second = 0;
}
for(int k = 0; k < adj2[sp[j-1]].size(); k++){
if(adj2[sp[j-1]][k].first == sp[j])
adj2[sp[j-1]][k].second = 0;
}
}
vector<long long> dist2(n+1, LONG_LONG_MAX);
vector<bool> visited2(n+1, false);
dist2[u] = 0;
q.push({0,u});
while(!q.empty()){
pair<long long, int> a = q.top();
q.pop();
if(visited2[a.second])
continue;
visited2[a.second] = true;
for(auto edge : adj2[a.second]){
int b = edge.first;
int weight = edge.second;
if(dist2[a.second] + weight < dist2[b]){
dist2[b] = dist2[a.second] + weight;
q.push({-dist2[b],b});
}
}
}
ans = min(ans,dist2[v]);
}
cout << ans << '\n';
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... | ||||
