## 답안 #479973

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
479973 2021-10-14T04:03:58 Z Yuisuyuno Robot (JOI21_ho_t4) C++14
100 / 100
1076 ms 82596 KB
//Nguyen Huu Hoang Minh
#include <bits/stdc++.h>
#define sz(x) int(x.size())
#define all(x) x.begin(),x.end()
#define reset(x) memset(x, 0,sizeof(x))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define N 2005
#define remain(x) if (x > MOD) x -= MOD
#define ii pair<int, int>
#define iiii pair< ii , ii >
#define viiii vector< iiii >
#define vi vector<int>
#define vii vector< ii >
#define bit(x, i) (((x) >> (i)) & 1)
#define int long long

using namespace std;

typedef long double ld;
const int inf = 1e10;
const int minf = -1e10;

int n, m;
struct edge{
int v, z, p;
};
map<int, vector<edge>> g[100005];
int d[100005];
map<int,int> d2[100005], psum[100005];

{
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
{
}
cin >> n >> m;
for(int i=1; i<=m; i++){
int u, v, z, p;
cin >> u >> v >> z >> p;
g[u][z].pb({v,z,p});
g[v][z].pb({u,z,p});
psum[u][z]+=p;
psum[v][z]+=p;
}
}

void proc()
{
memset(d, 0x3f, sizeof d);
d[1]=0;
priority_queue<tuple<int,int,int>> q;
q.push({0,1,0});
while (q.size()){
int cost, node, c;
tie(cost,node,c) = q.top();
q.pop();
if (c){
if (d2[node][c]!=-cost) continue;
for(edge i : g[node][c]){
int case1 = psum[node][c]-i.p-cost;
if (case1 < d[i.v]){
d[i.v] = case1;
q.push({-d[i.v],i.v,0});
}
}
}
else{
if (d[node]!=-cost) continue;

for(auto &i : g[node]){
for(auto j : i.se){

int case1 = psum[node][j.z]-j.p-cost;
if (case1 < d[j.v]){
d[j.v] = case1;
q.push({-d[j.v],j.v,0});
}

int case2 = j.p-cost;
if (case2 < d[j.v]){
d[j.v] = case2;
q.push({-d[j.v],j.v,0});
}

int case3 = -cost;
if (!d2[j.v].count(j.z) || case3 < d2[j.v][j.z]){
d2[j.v][j.z] = case3;
q.push({-d2[j.v][j.z],j.v,j.z});
}
}
}
}
}
cout << (d[n] > 1e18 ? -1 : d[n]);
}

signed main()
{
proc();
return 0;
}

### Compilation message

Main.cpp:41:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
|         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~

#### Subtask #1 34.0 / 34.0

# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 15180 KB Output is correct
2 Correct 8 ms 15084 KB Output is correct
3 Correct 9 ms 15180 KB Output is correct
4 Correct 8 ms 15116 KB Output is correct
5 Correct 9 ms 15180 KB Output is correct
6 Correct 9 ms 15176 KB Output is correct
7 Correct 10 ms 15312 KB Output is correct
8 Correct 10 ms 15180 KB Output is correct
9 Correct 13 ms 15820 KB Output is correct
10 Correct 14 ms 15692 KB Output is correct
11 Correct 11 ms 15628 KB Output is correct
12 Correct 10 ms 15436 KB Output is correct
13 Correct 13 ms 15564 KB Output is correct
14 Correct 12 ms 15564 KB Output is correct
15 Correct 12 ms 15364 KB Output is correct
16 Correct 10 ms 15436 KB Output is correct
17 Correct 10 ms 15492 KB Output is correct
18 Correct 9 ms 15308 KB Output is correct
19 Correct 14 ms 15472 KB Output is correct
20 Correct 10 ms 15436 KB Output is correct

#### Subtask #2 24.0 / 24.0

# 결과 실행 시간 메모리 Grader output
1 Correct 210 ms 35148 KB Output is correct
2 Correct 114 ms 25288 KB Output is correct
3 Correct 214 ms 32920 KB Output is correct
4 Correct 129 ms 28392 KB Output is correct
5 Correct 1070 ms 82068 KB Output is correct
6 Correct 752 ms 71616 KB Output is correct
7 Correct 372 ms 59540 KB Output is correct
8 Correct 427 ms 50080 KB Output is correct
9 Correct 499 ms 50276 KB Output is correct
10 Correct 362 ms 47852 KB Output is correct
11 Correct 138 ms 32452 KB Output is correct

#### Subtask #3 42.0 / 42.0

# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 15180 KB Output is correct
2 Correct 8 ms 15084 KB Output is correct
3 Correct 9 ms 15180 KB Output is correct
4 Correct 8 ms 15116 KB Output is correct
5 Correct 9 ms 15180 KB Output is correct
6 Correct 9 ms 15176 KB Output is correct
7 Correct 10 ms 15312 KB Output is correct
8 Correct 10 ms 15180 KB Output is correct
9 Correct 13 ms 15820 KB Output is correct
10 Correct 14 ms 15692 KB Output is correct
11 Correct 11 ms 15628 KB Output is correct
12 Correct 10 ms 15436 KB Output is correct
13 Correct 13 ms 15564 KB Output is correct
14 Correct 12 ms 15564 KB Output is correct
15 Correct 12 ms 15364 KB Output is correct
16 Correct 10 ms 15436 KB Output is correct
17 Correct 10 ms 15492 KB Output is correct
18 Correct 9 ms 15308 KB Output is correct
19 Correct 14 ms 15472 KB Output is correct
20 Correct 10 ms 15436 KB Output is correct
21 Correct 210 ms 35148 KB Output is correct
22 Correct 114 ms 25288 KB Output is correct
23 Correct 214 ms 32920 KB Output is correct
24 Correct 129 ms 28392 KB Output is correct
25 Correct 1070 ms 82068 KB Output is correct
26 Correct 752 ms 71616 KB Output is correct
27 Correct 372 ms 59540 KB Output is correct
28 Correct 427 ms 50080 KB Output is correct
29 Correct 499 ms 50276 KB Output is correct
30 Correct 362 ms 47852 KB Output is correct
31 Correct 138 ms 32452 KB Output is correct
32 Correct 147 ms 29588 KB Output is correct
33 Correct 171 ms 30528 KB Output is correct
34 Correct 441 ms 49836 KB Output is correct
35 Correct 336 ms 41308 KB Output is correct
36 Correct 342 ms 46864 KB Output is correct
37 Correct 401 ms 50132 KB Output is correct
38 Correct 384 ms 59152 KB Output is correct
39 Correct 161 ms 33120 KB Output is correct
40 Correct 462 ms 50140 KB Output is correct
41 Correct 495 ms 50256 KB Output is correct
42 Correct 542 ms 59596 KB Output is correct
43 Correct 233 ms 36856 KB Output is correct
44 Correct 464 ms 42792 KB Output is correct
45 Correct 341 ms 46128 KB Output is correct
46 Correct 289 ms 46328 KB Output is correct
47 Correct 362 ms 49276 KB Output is correct
48 Correct 1076 ms 82596 KB Output is correct