# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
408760 |
2021-05-19T15:26:07 Z |
Cantfindme |
Robot (JOI21_ho_t4) |
C++17 |
|
3000 ms |
52916 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pi;
#define f first
#define s second
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);
#define all(x) x.begin(),x.end()
const int maxn = 100010;
const int INF = LLONG_MAX/2;
const int mod = 1e9+7;
typedef pair<int, pi> pii;
//struct edge {
//int v, c, p;
//};
vector <pii> adjlist[maxn];
map <int, int> dp[maxn], sum[maxn];
int dist[maxn];
int n, e;
int32_t main() {
FAST
cin >> n >> e;
for (int i =0;i<e;i++) {
int a,b, c, p;
cin >> a >> b >> c >> p;
adjlist[a].push_back(pii(b,pi(c,p)));
adjlist[b].push_back(pii(a,pi(c,p)));
sum[a][c] += p;
sum[b][c] += p;
}
//(1) Only change edge i to completely unique colour (guaranteed to exist)
//(2) Change rest of edges with same colour as edge i
memset(dist,-1,sizeof dist);
priority_queue<pii, vector<pii>,greater<pii>> pq;
pq.push(pii(0,pi(1,0)));
dist[1] = 0;
while (!pq.empty()) {
auto [d, cur] = pq.top(); pq.pop();
auto [x, c] = cur;
if (c != 0) {
//We must take a (2) here if not void
if (d != dp[x][c]) continue;
for (auto [v,xx] : adjlist[x]) {
auto [cc, p] = xx;
if (cc != c) continue;
int nd = d + sum[x][c] - p;
if (dist[v] == -1 or dist[v] > nd) {
pq.push(pii(nd,pi(v,0)));
dist[v] = nd;
}
}
} else {
if (d != dist[x]) continue;
for (auto [v, xx]: adjlist[x]) {
auto [cc, p] = xx;
int nd = d + p;
//Take a (1)
//Straight to dist
if (dist[v] == -1 or dist[v] > nd) {
dist[v] = nd;
pq.push(pii(nd,pi(v,0)));
}
//Do a suspension
nd = d;
if (dp[v].count(cc) == 0 or dp[v][cc] > nd) {
dp[v][cc] = nd;
pq.push(pii(nd,pi(v,cc)));
}
//Take a (2)
nd = d + sum[x][cc] - p;
if (dist[v] == -1 or dist[v] > nd) {
dist[v] = nd;
pq.push(pii(nd,pi(v,0)));
}
}
}
}
cout << dist[n];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
12748 KB |
Output is correct |
2 |
Correct |
7 ms |
12748 KB |
Output is correct |
3 |
Correct |
7 ms |
12748 KB |
Output is correct |
4 |
Correct |
7 ms |
12748 KB |
Output is correct |
5 |
Correct |
8 ms |
12876 KB |
Output is correct |
6 |
Correct |
7 ms |
12748 KB |
Output is correct |
7 |
Correct |
9 ms |
12876 KB |
Output is correct |
8 |
Correct |
8 ms |
12876 KB |
Output is correct |
9 |
Correct |
12 ms |
13280 KB |
Output is correct |
10 |
Correct |
11 ms |
13260 KB |
Output is correct |
11 |
Correct |
9 ms |
13132 KB |
Output is correct |
12 |
Correct |
9 ms |
13084 KB |
Output is correct |
13 |
Correct |
9 ms |
13132 KB |
Output is correct |
14 |
Correct |
9 ms |
13132 KB |
Output is correct |
15 |
Correct |
10 ms |
13004 KB |
Output is correct |
16 |
Correct |
10 ms |
13116 KB |
Output is correct |
17 |
Correct |
10 ms |
13004 KB |
Output is correct |
18 |
Correct |
8 ms |
12888 KB |
Output is correct |
19 |
Correct |
9 ms |
13004 KB |
Output is correct |
20 |
Correct |
9 ms |
13004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
159 ms |
27616 KB |
Output is correct |
2 |
Correct |
69 ms |
20092 KB |
Output is correct |
3 |
Correct |
170 ms |
27948 KB |
Output is correct |
4 |
Correct |
104 ms |
22476 KB |
Output is correct |
5 |
Execution timed out |
3083 ms |
52916 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
12748 KB |
Output is correct |
2 |
Correct |
7 ms |
12748 KB |
Output is correct |
3 |
Correct |
7 ms |
12748 KB |
Output is correct |
4 |
Correct |
7 ms |
12748 KB |
Output is correct |
5 |
Correct |
8 ms |
12876 KB |
Output is correct |
6 |
Correct |
7 ms |
12748 KB |
Output is correct |
7 |
Correct |
9 ms |
12876 KB |
Output is correct |
8 |
Correct |
8 ms |
12876 KB |
Output is correct |
9 |
Correct |
12 ms |
13280 KB |
Output is correct |
10 |
Correct |
11 ms |
13260 KB |
Output is correct |
11 |
Correct |
9 ms |
13132 KB |
Output is correct |
12 |
Correct |
9 ms |
13084 KB |
Output is correct |
13 |
Correct |
9 ms |
13132 KB |
Output is correct |
14 |
Correct |
9 ms |
13132 KB |
Output is correct |
15 |
Correct |
10 ms |
13004 KB |
Output is correct |
16 |
Correct |
10 ms |
13116 KB |
Output is correct |
17 |
Correct |
10 ms |
13004 KB |
Output is correct |
18 |
Correct |
8 ms |
12888 KB |
Output is correct |
19 |
Correct |
9 ms |
13004 KB |
Output is correct |
20 |
Correct |
9 ms |
13004 KB |
Output is correct |
21 |
Correct |
159 ms |
27616 KB |
Output is correct |
22 |
Correct |
69 ms |
20092 KB |
Output is correct |
23 |
Correct |
170 ms |
27948 KB |
Output is correct |
24 |
Correct |
104 ms |
22476 KB |
Output is correct |
25 |
Execution timed out |
3083 ms |
52916 KB |
Time limit exceeded |
26 |
Halted |
0 ms |
0 KB |
- |