#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x,y) ((x+y-1)/(y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rev(i,s,e) for(int i = s; i >= e; --i)
#define trav(i,a) for(auto &i : a)
template<typename T>
void amin(T &a, T b) {
a = min(a,b);
}
template<typename T>
void amax(T &a, T b) {
a = max(a,b);
}
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
/*
refs:
https://codeforces.com/blog/entry/127315?#comment-1131129
*/
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;
#include "Aoi.h"
namespace {
int variable_example = 0;
int function_example(int a, int b) { return a + b; }
} // namespace
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) {
// n = #of nodes, m = #of edges
// A,B,C = edges of graph
// q = #of query cities
// T = query cities
// k = #of deleted edges
// X = ids of deleted edges
vector<pll> adj[n];
map<pll,ll> mp;
rep(i,m){
ll u = A[i], v = B[i], w = C[i];
adj[u].pb({v,w}), adj[v].pb({u,w});
mp[{u,v}] = mp[{v,u}] = i;
}
priority_queue<array<ll,3>,vector<array<ll,3>>,greater<array<ll,3>>> pq;
pq.push({0,0,-1});
vector<ll> par(n,-1);
vector<bool> vis(n);
while(!pq.empty()){
auto [dis,u,p] = pq.top();
pq.pop();
if(vis[u]) conts;
vis[u] = 1;
par[u] = p;
// cout << p << " " << u << endl;
for(auto [v,w] : adj[u]){
pq.push({dis+w,v,u});
}
}
string s = "";
rep(i,q){
ll u = T[i];
vector<ll> path;
while(u){
path.pb(u);
u = par[u];
}
path.pb(0);
vector<ll> edges;
rep(j,sz(path)-1){
pll px = {path[j],path[j+1]};
edges.pb(mp[px]);
}
sort(all(edges));
rep(j,k){
ll id = X[j];
if(binary_search(all(edges),id)){
s.pb('1');
}
else{
s.pb('0');
}
}
}
return s;
// variable_example++;
// variable_example = function_example(1, 2);
// std::string s(100, '0');
// s[0] = '1';
// return s;
}
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x,y) ((x+y-1)/(y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rev(i,s,e) for(int i = s; i >= e; --i)
#define trav(i,a) for(auto &i : a)
template<typename T>
void amin(T &a, T b) {
a = min(a,b);
}
template<typename T>
void amax(T &a, T b) {
a = max(a,b);
}
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
/*
refs:
https://codeforces.com/blog/entry/127315?#comment-1131129
*/
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;
#include "Bitaro.h"
namespace {
int variable_example = 0;
int function_example(int a, int b) { return a + b; }
} // namespace
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) {
// n = #of nodes, m = #of edges
// A,B,C = edges of graph (edge weights of deleted edges = -1)
// q = #of query cities
// T = query cities
// k = #of deleted edges
// X = ids of deleted edges
// s = received string
vector<pll> adj[n];
map<pll,ll> mp;
rep(i,m){
ll u = A[i], v = B[i], w = C[i];
adj[u].pb({v,w}), adj[v].pb({u,w});
mp[{u,v}] = mp[{v,u}] = i;
}
ll ptr = 0;
rep(i,q){
vector<bool> spl(n);
vector<bool> on_path(m);
rep(j,k){
if(s[ptr] == '1'){
ll id = X[j];
on_path[id] = 1;
spl[A[id]] = spl[B[id]] = 1;
}
ptr++;
}
priority_queue<array<ll,3>,vector<array<ll,3>>,greater<array<ll,3>>> pq;
pq.push({0,0,-1});
vector<ll> par(n,-1);
vector<bool> vis(n);
while(!pq.empty()){
auto [dis,u,p] = pq.top();
pq.pop();
if(vis[u]) conts;
vis[u] = 1;
par[u] = p;
if(spl[u]){
ll cnt = 0;
for(auto [v,w] : adj[u]){
ll id = mp[{u,v}];
if(w == -1 and on_path[id]){
cnt++;
}
}
if(cnt){
while(!pq.empty()){
pq.pop();
}
for(auto [v,w] : adj[u]){
ll id = mp[{u,v}];
if(w == -1 and on_path[id]){
on_path[id] = 0;
pq.push({0,v,u});
}
}
conts;
}
}
for(auto [v,w] : adj[u]){
if(w == -1) conts;
pq.push({dis+w,v,u});
}
}
vector<ll> nodes;
ll u = T[i];
while(u){
assert(u != -1);
nodes.pb(u);
u = par[u];
}
nodes.pb(0);
reverse(all(nodes));
vector<int> ans;
rep(j,sz(nodes)-1){
pll px = {nodes[j],nodes[j+1]};
ans.pb(mp[px]);
}
answer(ans);
// trav(x,ans) cout << x << " ";
// cout << endl;
}
// variable_example++;
// variable_example = function_example(1, 2);
// for (int i = 0; i < q; i++) {
// std::vector<int> v(10);
// for (int j = 0; j < 10; j++) {
// v[j] = j;
// }
// answer(v);
// }
}
Compilation message
Aoi.cpp:67:9: warning: 'int {anonymous}::function_example(int, int)' defined but not used [-Wunused-function]
67 | int function_example(int a, int b) { return a + b; }
| ^~~~~~~~~~~~~~~~
Aoi.cpp:65:9: warning: '{anonymous}::variable_example' defined but not used [-Wunused-variable]
65 | int variable_example = 0;
| ^~~~~~~~~~~~~~~~
Bitaro.cpp:67:9: warning: 'int {anonymous}::function_example(int, int)' defined but not used [-Wunused-function]
67 | int function_example(int a, int b) { return a + b; }
| ^~~~~~~~~~~~~~~~
Bitaro.cpp:65:9: warning: '{anonymous}::variable_example' defined but not used [-Wunused-variable]
65 | int variable_example = 0;
| ^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
141 ms |
12588 KB |
Partially correct |
2 |
Correct |
1 ms |
776 KB |
Output is correct |
3 |
Partially correct |
87 ms |
9400 KB |
Partially correct |
4 |
Partially correct |
80 ms |
8608 KB |
Partially correct |
5 |
Partially correct |
102 ms |
9404 KB |
Partially correct |
6 |
Partially correct |
100 ms |
9452 KB |
Partially correct |
7 |
Partially correct |
90 ms |
9480 KB |
Partially correct |
8 |
Partially correct |
91 ms |
9160 KB |
Partially correct |
9 |
Partially correct |
71 ms |
8588 KB |
Partially correct |
10 |
Correct |
49 ms |
8800 KB |
Output is correct |
11 |
Partially correct |
91 ms |
9344 KB |
Partially correct |
12 |
Correct |
80 ms |
9452 KB |
Output is correct |
13 |
Partially correct |
87 ms |
9504 KB |
Partially correct |
14 |
Partially correct |
100 ms |
9492 KB |
Partially correct |
15 |
Correct |
83 ms |
8704 KB |
Output is correct |
16 |
Correct |
32 ms |
8372 KB |
Output is correct |
17 |
Partially correct |
99 ms |
8692 KB |
Partially correct |
18 |
Partially correct |
92 ms |
8696 KB |
Partially correct |
19 |
Partially correct |
117 ms |
11860 KB |
Partially correct |
20 |
Partially correct |
115 ms |
11908 KB |
Partially correct |
21 |
Partially correct |
138 ms |
11916 KB |
Partially correct |
22 |
Partially correct |
126 ms |
11804 KB |
Partially correct |
23 |
Partially correct |
100 ms |
11816 KB |
Partially correct |
24 |
Partially correct |
123 ms |
11804 KB |
Partially correct |
25 |
Partially correct |
131 ms |
9268 KB |
Partially correct |
26 |
Partially correct |
126 ms |
9276 KB |
Partially correct |
27 |
Correct |
0 ms |
784 KB |
Output is correct |
28 |
Partially correct |
102 ms |
9644 KB |
Partially correct |
29 |
Partially correct |
50 ms |
6428 KB |
Partially correct |
30 |
Correct |
95 ms |
10088 KB |
Output is correct |
31 |
Correct |
60 ms |
9988 KB |
Output is correct |
32 |
Partially correct |
105 ms |
10064 KB |
Partially correct |
33 |
Correct |
105 ms |
9400 KB |
Output is correct |
34 |
Partially correct |
103 ms |
10060 KB |
Partially correct |
35 |
Correct |
109 ms |
9952 KB |
Output is correct |
36 |
Partially correct |
103 ms |
10172 KB |
Partially correct |
37 |
Partially correct |
27 ms |
4868 KB |
Partially correct |
38 |
Partially correct |
59 ms |
6384 KB |
Partially correct |
39 |
Partially correct |
59 ms |
6468 KB |
Partially correct |
40 |
Correct |
23 ms |
5728 KB |
Output is correct |
41 |
Partially correct |
145 ms |
11884 KB |
Partially correct |
42 |
Partially correct |
87 ms |
11800 KB |
Partially correct |
43 |
Correct |
130 ms |
11960 KB |
Output is correct |
44 |
Correct |
46 ms |
11436 KB |
Output is correct |
45 |
Partially correct |
30 ms |
4788 KB |
Partially correct |
46 |
Partially correct |
38 ms |
5900 KB |
Partially correct |
47 |
Correct |
43 ms |
6008 KB |
Output is correct |
48 |
Correct |
1 ms |
776 KB |
Output is correct |
49 |
Correct |
0 ms |
776 KB |
Output is correct |
50 |
Partially correct |
87 ms |
12700 KB |
Partially correct |
51 |
Partially correct |
6 ms |
1292 KB |
Partially correct |
52 |
Partially correct |
1 ms |
776 KB |
Partially correct |
53 |
Partially correct |
143 ms |
13012 KB |
Partially correct |
54 |
Partially correct |
73 ms |
7872 KB |
Partially correct |
55 |
Partially correct |
90 ms |
7940 KB |
Partially correct |
56 |
Partially correct |
96 ms |
11848 KB |
Partially correct |
57 |
Partially correct |
122 ms |
11804 KB |
Partially correct |
58 |
Partially correct |
95 ms |
8544 KB |
Partially correct |
59 |
Partially correct |
149 ms |
11432 KB |
Partially correct |
60 |
Partially correct |
140 ms |
11084 KB |
Partially correct |
61 |
Partially correct |
155 ms |
11404 KB |
Partially correct |
62 |
Partially correct |
122 ms |
10236 KB |
Partially correct |
63 |
Partially correct |
148 ms |
11684 KB |
Partially correct |
64 |
Correct |
39 ms |
9368 KB |
Output is correct |
65 |
Partially correct |
64 ms |
6744 KB |
Partially correct |
66 |
Partially correct |
78 ms |
11768 KB |
Partially correct |
67 |
Partially correct |
59 ms |
6680 KB |
Partially correct |
68 |
Partially correct |
89 ms |
11724 KB |
Partially correct |
69 |
Correct |
0 ms |
776 KB |
Output is correct |
70 |
Correct |
1 ms |
776 KB |
Output is correct |
71 |
Correct |
1 ms |
784 KB |
Output is correct |
72 |
Partially correct |
22 ms |
4792 KB |
Partially correct |
73 |
Partially correct |
45 ms |
5912 KB |
Partially correct |
74 |
Partially correct |
51 ms |
5820 KB |
Partially correct |
75 |
Correct |
22 ms |
5900 KB |
Output is correct |
76 |
Correct |
0 ms |
776 KB |
Output is correct |
77 |
Correct |
109 ms |
9692 KB |
Output is correct |
78 |
Partially correct |
105 ms |
9660 KB |
Partially correct |
79 |
Correct |
101 ms |
9408 KB |
Output is correct |
80 |
Correct |
0 ms |
776 KB |
Output is correct |
81 |
Partially correct |
104 ms |
9492 KB |
Partially correct |
82 |
Partially correct |
107 ms |
9324 KB |
Partially correct |
83 |
Partially correct |
103 ms |
9388 KB |
Partially correct |