#include <bits/stdc++.h>
#include "crocodile.h"
using namespace std;
typedef long long ll;
mt19937 rng((long long) (new char));
const int N = 100000 + 7;
const int INF = (int) 1e9 + 7;
int n, m, k, best[N];
multiset<int> adj[N];
vector<pair<int, int>> g[N];
queue<int> q;
bool inside[N];
void push(int i, int value) {
if (!inside[i]) {
q.push(i);
inside[i] = 1;
}
for (auto &it : g[i]) {
assert(adj[it.first].find(min(INF, best[i] + it.second)) != adj[it.first].end());
adj[it.first].erase(adj[it.first].find(min(INF, best[i] + it.second)));
}
best[i] = value;
for (auto &it : g[i]) {
/**if (i == 3) {
cout << "aici : " << best[i] << " and " << it.first << ", " << it.second << "\n";
}**/
adj[it.first].insert(min(INF, best[i] + it.second));
}
}
int get_second(int a) {
///cout << " # " << a << "\n";
if ((int) adj[a].size() < 2) {
return INF;
}
auto it = adj[a].begin();
it++;
assert(it != adj[a].end());
return *it;
}
int travel_plan(int nn, int mm, int r[][2], int len[], int kk, int ch[]) {
n = nn;
m = mm;
k = kk;
/// cout << "# " << n << " " << m << " " << k << "\n";
for (int i = 0; i < n; i++) {
g[i].clear();
adj[i].clear();
best[i] = INF;
inside[i] = 0;
}
assert(q.empty());
for (int i = 0; i < m; i++) {
/// cout << r[i][0] << " " << r[i][1] << " and " << len[i] << "\n";
g[r[i][0]].push_back({r[i][1], len[i]});
g[r[i][1]].push_back({r[i][0], len[i]});
adj[r[i][0]].insert(INF);
adj[r[i][1]].insert(INF);
}
///shuffle(ch, ch + k, rng);
for (int i = 0; i < n; i++) {
///shuffle(g[i].begin(), g[i].end(), rng);
}
for (int i = 0; i < k; i++) {
/// cout << i << " : " << ch[i] << "\n";
push(ch[i], 0);
/** if (ch[i] == 2) {
cout << "wtf : " << i << " and " << ch[i] << "\n";
}**/
}
/// cout << "kolrabi\n";
int cnt = 0;
/// cout << " o " << n << " " << m << " " << k << "\n";
while (!q.empty()) {
int a = q.front();
inside[a] = 0;
q.pop();
for (auto &it : g[a]) {
int node = it.first, relax = get_second(node);
if (node == 2 && relax == 0) {
///cout << "what ? " << node << ", " << relax << "\n";
}
if (relax < best[node]) {
push(node, relax);
}
}
}
/**
cout << "print : ";
for (auto &x : adj[2]) {
cout << x << " ";
}
cout << "\n";
exit(0);**/
/// cout << "done\n";
if (best[0] == INF) {
best[0] = -1;
}
return best[0];
}
Compilation message
crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:77:7: warning: unused variable 'cnt' [-Wunused-variable]
77 | int cnt = 0;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7372 KB |
Output is correct |
2 |
Correct |
4 ms |
7356 KB |
Output is correct |
3 |
Correct |
5 ms |
7372 KB |
Output is correct |
4 |
Correct |
5 ms |
7500 KB |
Output is correct |
5 |
Correct |
7 ms |
7504 KB |
Output is correct |
6 |
Correct |
5 ms |
7492 KB |
Output is correct |
7 |
Correct |
5 ms |
7500 KB |
Output is correct |
8 |
Correct |
5 ms |
7500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7372 KB |
Output is correct |
2 |
Correct |
4 ms |
7356 KB |
Output is correct |
3 |
Correct |
5 ms |
7372 KB |
Output is correct |
4 |
Correct |
5 ms |
7500 KB |
Output is correct |
5 |
Correct |
7 ms |
7504 KB |
Output is correct |
6 |
Correct |
5 ms |
7492 KB |
Output is correct |
7 |
Correct |
5 ms |
7500 KB |
Output is correct |
8 |
Correct |
5 ms |
7500 KB |
Output is correct |
9 |
Correct |
11 ms |
8012 KB |
Output is correct |
10 |
Correct |
5 ms |
7360 KB |
Output is correct |
11 |
Correct |
7 ms |
7628 KB |
Output is correct |
12 |
Correct |
29 ms |
8652 KB |
Output is correct |
13 |
Correct |
15 ms |
8708 KB |
Output is correct |
14 |
Correct |
6 ms |
7372 KB |
Output is correct |
15 |
Correct |
7 ms |
7628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7372 KB |
Output is correct |
2 |
Correct |
4 ms |
7356 KB |
Output is correct |
3 |
Correct |
5 ms |
7372 KB |
Output is correct |
4 |
Correct |
5 ms |
7500 KB |
Output is correct |
5 |
Correct |
7 ms |
7504 KB |
Output is correct |
6 |
Correct |
5 ms |
7492 KB |
Output is correct |
7 |
Correct |
5 ms |
7500 KB |
Output is correct |
8 |
Correct |
5 ms |
7500 KB |
Output is correct |
9 |
Correct |
11 ms |
8012 KB |
Output is correct |
10 |
Correct |
5 ms |
7360 KB |
Output is correct |
11 |
Correct |
7 ms |
7628 KB |
Output is correct |
12 |
Correct |
29 ms |
8652 KB |
Output is correct |
13 |
Correct |
15 ms |
8708 KB |
Output is correct |
14 |
Correct |
6 ms |
7372 KB |
Output is correct |
15 |
Correct |
7 ms |
7628 KB |
Output is correct |
16 |
Execution timed out |
2106 ms |
144000 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |