Submission #35205404
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,n) for (ll i=a;i<(ll)n;i++)
ll read(){ll r;scanf("%lld",&r);return r;}
template <typename T> using minPQ = priority_queue<T,vector<T>, greater<T>>;
vector<pair<int,ll> > g[200010]; // g[u] = {v,w};
int fa[200010]; // DSU
int find(int v){return v==fa[v]?v:(fa[v]=find(fa[v]));}
const ll INF = 0x3f3f3f3f3f3f3f3f;
int main() {
int n = read();
int m = read();
int k = read();
vector<tuple<ll,int,int> > e; // w,u,v 原图的边
rep(i,0,m){
int u = read()-1; // 0-index
int v = read()-1;
ll w = read();
e.push_back({w,u,v});
g[u].push_back({v, w});
g[v].push_back({u, w});
}
vector<ll> h(n); // 最近休息点
vector<ll> d(n,INF); // 到最近休息点的距离
minPQ<tuple<ll,int,int> > pq; // {dis, u, 休息点}
rep(i,0,k) pq.push({0,i,i});
for(int cnt = n;!pq.empty() && cnt > 0;) {
auto [c,u,x] = pq.top();
pq.pop();
if (d[u]!=INF) continue;
d[u] = c;
h[u] = x;
cnt --;
for(auto [v,w]:g[u])if(d[v]==INF)pq.push({c+w,v,x});
}
vector<tuple<ll,int,int> > e2; // w u v, 只有k个点的图的边
for(auto [w,u,v]:e) if(h[u] != h[v]) e2.push_back({d[u]+d[v]+w,h[u], h[v]}); // h[u]..u..v..h[v]
sort(e2.begin(), e2.end());
iota(fa,fa+k,0);
int q = read();
int i = 0;
while(q--){
int x = read()-1;
int y = read()-1;
ll t = read();
while(i<(int)e2.size()){
auto [w,u,v] = e2[i];
if(w > t)break;
fa[find(u)] = find(v);
i++;
}
printf("%s\n",find(x)==find(y) ? "Yes" : "No");
}
}
Submission Info
| Submission Time |
|
| Task |
Ex - Trespassing Takahashi |
| User |
cromarmot |
| Language |
C++ (GCC 9.2.1) |
| Score |
600 |
| Code Size |
1604 Byte |
| Status |
AC |
| Exec Time |
256 ms |
| Memory |
34312 KiB |
Compile Error
./Main.cpp: In function ‘ll read()’:
./Main.cpp:5:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
5 | ll read(){ll r;scanf("%lld",&r);return r;}
| ~~~~~^~~~~~~~~~~
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
600 / 600 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
00_sample_00.txt |
| All |
00_sample_00.txt, 01_small_00.txt, 01_small_01.txt, 01_small_02.txt, 01_small_03.txt, 01_small_04.txt, 01_small_05.txt, 01_small_06.txt, 01_small_07.txt, 01_small_08.txt, 02_large_00.txt, 02_large_01.txt, 02_large_02.txt, 02_large_03.txt, 02_large_04.txt, 02_large_05.txt, 02_large_06.txt, 02_large_07.txt, 03_bt_00.txt, 03_bt_01.txt, 03_bt_02.txt, 03_bt_03.txt, 03_bt_04.txt, 03_bt_05.txt, 03_bt_06.txt, 03_bt_07.txt, 04_killer_00.txt, 04_killer_01.txt, 04_killer_02.txt, 04_killer_03.txt, 05_largeK_00.txt, 05_largeK_01.txt, 05_largeK_02.txt, 05_largeK_03.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 00_sample_00.txt |
AC |
13 ms |
8364 KiB |
| 01_small_00.txt |
AC |
7 ms |
8340 KiB |
| 01_small_01.txt |
AC |
11 ms |
8576 KiB |
| 01_small_02.txt |
AC |
10 ms |
8344 KiB |
| 01_small_03.txt |
AC |
9 ms |
8372 KiB |
| 01_small_04.txt |
AC |
9 ms |
8176 KiB |
| 01_small_05.txt |
AC |
6 ms |
8244 KiB |
| 01_small_06.txt |
AC |
6 ms |
8240 KiB |
| 01_small_07.txt |
AC |
7 ms |
8600 KiB |
| 01_small_08.txt |
AC |
11 ms |
8388 KiB |
| 02_large_00.txt |
AC |
204 ms |
30588 KiB |
| 02_large_01.txt |
AC |
246 ms |
34120 KiB |
| 02_large_02.txt |
AC |
222 ms |
30660 KiB |
| 02_large_03.txt |
AC |
232 ms |
33300 KiB |
| 02_large_04.txt |
AC |
223 ms |
29772 KiB |
| 02_large_05.txt |
AC |
222 ms |
29156 KiB |
| 02_large_06.txt |
AC |
238 ms |
30572 KiB |
| 02_large_07.txt |
AC |
225 ms |
29544 KiB |
| 03_bt_00.txt |
AC |
126 ms |
22212 KiB |
| 03_bt_01.txt |
AC |
140 ms |
22296 KiB |
| 03_bt_02.txt |
AC |
150 ms |
22596 KiB |
| 03_bt_03.txt |
AC |
133 ms |
22352 KiB |
| 03_bt_04.txt |
AC |
141 ms |
22296 KiB |
| 03_bt_05.txt |
AC |
160 ms |
30488 KiB |
| 03_bt_06.txt |
AC |
203 ms |
34312 KiB |
| 03_bt_07.txt |
AC |
206 ms |
33884 KiB |
| 04_killer_00.txt |
AC |
130 ms |
23968 KiB |
| 04_killer_01.txt |
AC |
133 ms |
27004 KiB |
| 04_killer_02.txt |
AC |
128 ms |
23872 KiB |
| 04_killer_03.txt |
AC |
127 ms |
27244 KiB |
| 05_largeK_00.txt |
AC |
243 ms |
33980 KiB |
| 05_largeK_01.txt |
AC |
241 ms |
33336 KiB |
| 05_largeK_02.txt |
AC |
256 ms |
33764 KiB |
| 05_largeK_03.txt |
AC |
251 ms |
34280 KiB |