#include "Aoi.h"
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pli pair<ll,int>
#define pii pair<int,int>
#define fi first
#define se second
namespace Aoi{
const int maxn = 10005;
const int maxm = 20005;
const ll inf = 1e18;
pli dist[maxn];
vector<pii> edge[maxn];
bool vis[maxn],del[maxm];
int lst[maxn],f[maxm];
string aoi(int N, int M, int Q, int K, vector<int> A, vector<int> B,
vector<ll> C, vector<int> T, vector<int> X){
for(int i=0;i<K;i++) del[X[i]]=true;
for(int i=0;i<M;i++){
edge[A[i]].push_back({B[i],i});
edge[B[i]].push_back({A[i],i});
}
for(int i=0;i<N;i++) dist[i]={inf,-1};
priority_queue<pli,vector<pli>,greater<pli>> pq;
dist[0]={0,-1};pq.push({0,0});
while(!pq.empty()){
auto [d,u]=pq.top();pq.pop();
if(dist[u].fi!=d) continue;
for(auto [v,id]:edge[u]){
pli nd={d+C[id],id};
if(nd.fi<dist[v].fi) pq.push({nd.fi,v});
dist[v]=min(dist[v],nd);
}
}
vis[0]=true;
for(int i=0;i<Q;i++){
int u=T[i];
while(!vis[u]){
int id=dist[u].se;
vis[u]=true;
if(del[id]) f[id]=i+1;
//cout << "dist " << u << ' ' << id << '\n';
u^=A[id]^B[id];
}
lst[i]=u;
}
string S;
for(int i=0;i<K;i+=10){
ll num=0;
for(int j=i;j<min(i+10,K);j++) num=num*(Q+1)+f[X[j]];
for(int j=0;j<=40;j++) S+=char('0'+(num>>j&1));
}
for(int i=0;i<Q;i++){
for(int j=0;j<14;j++) S+=char('0'+(lst[i]>>j&1));
}
return S;
}
}
std::string aoi(int N, int M, int Q, int K, std::vector<int> A,
std::vector<int> B, std::vector<long long> C,
std::vector<int> T, std::vector<int> X) {
return Aoi::aoi(N,M,Q,K,A,B,C,T,X);
}
#include "Bitaro.h"
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pli pair<ll,int>
#define pii pair<int,int>
#define fi first
#define se second
namespace Bitaro{
const ll inf=1e18;
const int maxn = 10005;
const int maxm = 20005;
int lst[maxn],f[maxm],up[maxn];
pli dist[maxn];
vector<pii> edge[maxn];
void bitaro(int N, int M, int Q, int K,vector<int> A, vector<int> B,
vector<ll> C, std::vector<int> T, std::vector<int> X,
string S){
for(int i=0;i<M;i++){
edge[A[i]].push_back({B[i],i});
edge[B[i]].push_back({A[i],i});
}
int P=0;
for(int i=0;i<K;i+=10){
ll num=0;
for(int j=0;j<=40;j++) num+=(S[P++]-'0')*(1LL<<j);
for(int j=min(i+10,K)-1;j>=i;j--){
f[j]=num%(Q+1),num/=(Q+1);
//cout << '*' << j << ' ' << f[j] << '\n';
}
}
for(int i=0;i<N;i++) up[i]=-1;
for(int i=0;i<Q;i++){
for(int j=0;j<14;j++) lst[i]+=(S[P++]-'0')*(1<<j);
for(int j=0;j<K;j++) C[X[j]]=(f[j]==i+1?1:inf);
priority_queue<pli,vector<pli>,greater<pli>> pq;
for(int j=0;j<N;j++) dist[j]={inf,-1};
dist[lst[i]]={0,-1};
pq.push({0,lst[i]});
while(!pq.empty()){
auto [d,u]=pq.top();pq.pop();
if(dist[u].fi!=d) continue;
//if(i==2) cout << "pq " << d << ' ' << u << '\n';
for(auto [v,id]:edge[u]){
pli nd={d+C[id],id};
if(nd.fi<dist[v].fi) pq.push({nd.fi,v});
dist[v]=min(dist[v],nd);
}
}
//if(i==2){
//cout << T[i] << ' ' << lst[i] << '\n';
//for(int j=0;j<N;j++) cout << dist[j].fi << ' ' << dist[j].se << '\n';
//}
//if(i!=2){
int u=T[i];
vector<int> ans;
while(u!=0){
if(up[u]==-1) up[u]=dist[u].se;
ans.push_back(up[u]);
//cout << '*' << u << ' ' << up[u] << '\n';
u^=A[up[u]]^B[up[u]];
}
reverse(ans.begin(),ans.end());
answer(ans);
//}
}
}
}
void bitaro(int N, int M, int Q, int K, std::vector<int> A, std::vector<int> B,
std::vector<long long> C, std::vector<int> T, std::vector<int> X,
std::string s) {
Bitaro::bitaro(N,M,Q,K,A,B,C,T,X,s);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
4372 KB |
Output is correct |
2 |
Correct |
0 ms |
1292 KB |
Output is correct |
3 |
Correct |
31 ms |
4884 KB |
Output is correct |
4 |
Correct |
26 ms |
4536 KB |
Output is correct |
5 |
Correct |
36 ms |
4888 KB |
Output is correct |
6 |
Correct |
39 ms |
4864 KB |
Output is correct |
7 |
Correct |
33 ms |
4828 KB |
Output is correct |
8 |
Correct |
32 ms |
4648 KB |
Output is correct |
9 |
Correct |
22 ms |
4580 KB |
Output is correct |
10 |
Correct |
17 ms |
4352 KB |
Output is correct |
11 |
Correct |
39 ms |
5148 KB |
Output is correct |
12 |
Correct |
32 ms |
4788 KB |
Output is correct |
13 |
Correct |
38 ms |
4888 KB |
Output is correct |
14 |
Correct |
32 ms |
4788 KB |
Output is correct |
15 |
Correct |
30 ms |
4748 KB |
Output is correct |
16 |
Correct |
14 ms |
4288 KB |
Output is correct |
17 |
Correct |
26 ms |
4596 KB |
Output is correct |
18 |
Correct |
26 ms |
4788 KB |
Output is correct |
19 |
Correct |
58 ms |
5468 KB |
Output is correct |
20 |
Correct |
39 ms |
5328 KB |
Output is correct |
21 |
Correct |
51 ms |
5316 KB |
Output is correct |
22 |
Correct |
39 ms |
5432 KB |
Output is correct |
23 |
Correct |
28 ms |
5428 KB |
Output is correct |
24 |
Correct |
40 ms |
5508 KB |
Output is correct |
25 |
Correct |
19 ms |
4792 KB |
Output is correct |
26 |
Correct |
20 ms |
4568 KB |
Output is correct |
27 |
Correct |
0 ms |
1292 KB |
Output is correct |
28 |
Correct |
31 ms |
4896 KB |
Output is correct |
29 |
Correct |
11 ms |
3596 KB |
Output is correct |
30 |
Correct |
35 ms |
4924 KB |
Output is correct |
31 |
Correct |
23 ms |
4960 KB |
Output is correct |
32 |
Correct |
39 ms |
4820 KB |
Output is correct |
33 |
Correct |
40 ms |
4816 KB |
Output is correct |
34 |
Correct |
32 ms |
5048 KB |
Output is correct |
35 |
Correct |
31 ms |
4948 KB |
Output is correct |
36 |
Correct |
32 ms |
4792 KB |
Output is correct |
37 |
Correct |
8 ms |
3084 KB |
Output is correct |
38 |
Correct |
14 ms |
3852 KB |
Output is correct |
39 |
Correct |
14 ms |
3764 KB |
Output is correct |
40 |
Correct |
8 ms |
3320 KB |
Output is correct |
41 |
Correct |
48 ms |
5336 KB |
Output is correct |
42 |
Correct |
34 ms |
5404 KB |
Output is correct |
43 |
Correct |
52 ms |
5284 KB |
Output is correct |
44 |
Correct |
19 ms |
5304 KB |
Output is correct |
45 |
Correct |
8 ms |
3084 KB |
Output is correct |
46 |
Correct |
10 ms |
3372 KB |
Output is correct |
47 |
Correct |
12 ms |
3552 KB |
Output is correct |
48 |
Correct |
1 ms |
1292 KB |
Output is correct |
49 |
Correct |
0 ms |
1544 KB |
Output is correct |
50 |
Correct |
11 ms |
4096 KB |
Output is correct |
51 |
Correct |
2 ms |
1292 KB |
Output is correct |
52 |
Correct |
0 ms |
1300 KB |
Output is correct |
53 |
Correct |
13 ms |
4348 KB |
Output is correct |
54 |
Correct |
11 ms |
3340 KB |
Output is correct |
55 |
Correct |
24 ms |
4020 KB |
Output is correct |
56 |
Correct |
24 ms |
4868 KB |
Output is correct |
57 |
Correct |
42 ms |
5088 KB |
Output is correct |
58 |
Correct |
32 ms |
4368 KB |
Output is correct |
59 |
Correct |
44 ms |
5372 KB |
Output is correct |
60 |
Correct |
37 ms |
5300 KB |
Output is correct |
61 |
Correct |
52 ms |
5492 KB |
Output is correct |
62 |
Correct |
41 ms |
4892 KB |
Output is correct |
63 |
Correct |
50 ms |
5300 KB |
Output is correct |
64 |
Correct |
15 ms |
4856 KB |
Output is correct |
65 |
Correct |
34 ms |
4192 KB |
Output is correct |
66 |
Correct |
22 ms |
5520 KB |
Output is correct |
67 |
Correct |
25 ms |
4256 KB |
Output is correct |
68 |
Correct |
23 ms |
5532 KB |
Output is correct |
69 |
Correct |
0 ms |
1292 KB |
Output is correct |
70 |
Correct |
1 ms |
1292 KB |
Output is correct |
71 |
Correct |
2 ms |
1300 KB |
Output is correct |
72 |
Correct |
10 ms |
2836 KB |
Output is correct |
73 |
Correct |
22 ms |
3344 KB |
Output is correct |
74 |
Correct |
24 ms |
3344 KB |
Output is correct |
75 |
Correct |
9 ms |
3464 KB |
Output is correct |
76 |
Correct |
0 ms |
1296 KB |
Output is correct |
77 |
Correct |
30 ms |
4420 KB |
Output is correct |
78 |
Correct |
27 ms |
4480 KB |
Output is correct |
79 |
Correct |
31 ms |
4512 KB |
Output is correct |
80 |
Correct |
0 ms |
1292 KB |
Output is correct |
81 |
Correct |
39 ms |
4880 KB |
Output is correct |
82 |
Correct |
36 ms |
4864 KB |
Output is correct |
83 |
Correct |
36 ms |
5040 KB |
Output is correct |