#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
#include "stations.h"
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
#define rrep(i,a,b) for(int i=int(a);i>int(b);i--)
#define trav(a,v) for(auto& a: v)
#define sz(v) v.size()
#define all(v) v.begin(),v.end()
#define vi vector<int>
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const long long inf = 2e9;
using namespace std;
vector<vector<ll>> children;
vector<ll> visited2;
int dfs(ll cur) {
if (visited2[cur])return visited2[cur];
if (children[cur].size() == 0)return 1 << cur;
ll ans = 1 << cur;
trav(a, children[cur])ans |= dfs(a);
return visited2[cur]=ans;
}
vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
ll counter = 0;
vector<vector<ll>> g(n);
rep(i, 0, n - 1) {
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
}
vector<int> ans(n);
children.resize(n);
visited2.resize(n);
vector<int> visited(n);
queue<ll> q;
q.push(0);
visited[0] = 1;
while (!q.empty()) {
ll cur = q.front();
q.pop();
trav(a, g[cur]) {
if (!visited[a]) {
visited[a] = 1;
q.push(a);
children[cur].push_back(a);
}
}
}
rep(i, 0, n)ans[i] = dfs(i);
return ans;
}
int find_next_station(int s, int t, vector<int> c) {
trav(a, c)if ((t & a))return a;
return c.back();
}
Compilation message
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:28:5: warning: unused variable 'counter' [-Wunused-variable]
28 | ll counter = 0;
| ^~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
424 KB |
Invalid labels (values out of range). scenario=0, k=1000, vertex=0, label=1023 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
524 KB |
Invalid labels (values out of range). scenario=0, k=1000, vertex=0, label=-1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
528 KB |
Invalid labels (values out of range). scenario=1, k=1000000, vertex=1, label=-1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1079 ms |
468 KB |
Output is correct |
2 |
Incorrect |
1 ms |
288 KB |
Invalid labels (duplicates values). scenario=4, label=6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
456 KB |
Invalid labels (values out of range). scenario=1, k=1000000000, vertex=2, label=-904862737 |
2 |
Halted |
0 ms |
0 KB |
- |