# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
537344 |
2022-03-15T02:47:04 Z |
ac2hu |
Hotspot (NOI17_hotspot) |
C++14 |
|
8 ms |
596 KB |
#include <bits/stdc++.h>
#ifdef DEBUG
#include "../templates/debug.h"
#else
#define deb(x...)
#endif
using namespace std;
#define ll long long
#define ld long double
const int N = 5001;
int n,m,k;
vector<int> adj[N];
int d1[N], d2[N] ,p1[N], p2[N];
ld e[N];
signed main() {
iostream::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
cin >> n >> m;
for(int _ = 0;_<m;_++){
int a,b;cin >> a >> b;
// a--;b--;
adj[a].push_back(b);
adj[b].push_back(a);
}
cin >> k;
for(int _ = 0;_<k;_++){
int s,t;cin >> s >> t;
for(int i = 0;i<n;i++){
d1[i] = 1e9;
d2[i] = 1e9;
p1[i] = 0;
p2[i] = 0;
}
list<int> q;
d1[s] = 0;
p1[s] = 1;
q.push_back(s);
while(!q.empty()){
int x = q.front();
q.pop_front();
// cout << x << "--> : ";
for(int e : adj[x]){
if(d1[e] > d1[x]){
p1[e] += p1[x];
}
if(d1[e] > d1[x] + 1){
d1[e] = d1[x] + 1;
// cout << e << " ";
q.push_back(e);
}
}
// cout << "\n";
}
// cout << "\n";
// p2 shortest paths to t
d2[t] = 0;
p2[t] = 1;
q.push_back(t);
while(!q.empty()){
int x = q.front();
q.pop_front();
for(int e : adj[x]){
if(d2[e] > d2[x])
p2[e] += p2[x];
if(d2[e] > d2[x] + 1){
d2[e] = d2[x] + 1;
q.push_back(e);
}
}
}
ll total = p1[t];
// assert(p1[t] == p2[s]);
for(int i = 0;i<n;i++){
ll paths = p1[i]*p2[i];
if(d1[i] + d2[i] == d1[t])
e[i] += (ld)(paths/total);
}
// cout << s << " " << t << "\n";
// cout << "distance from " << s << " to i: \n";
// for(int i = 0;i<n;i++)
// cout << d1[i] << " ";
// cout << "\n";
// cout << "distance from " << t << " to i: \n";
// for(int i = 0;i<n;i++)
// cout << d2[i] << " ";
// cout << "\n";
// cout << "paths from " << s << " to i: \n";
// for(int i = 0;i<n;i++)
// cout << p1[i] << " ";
// cout << "\n";
// cout << "paths from " << t << " to i: \n";
// for(int i = 0;i<n;i++)
// cout << p2[i] << " ";
// cout << "\n";
// cout << "------------\n";
}
// for(int i = 0;i<n;i++)
// cout << e[i] << " ";
// cout << "\n";
cout << max_element(e, e + n) - e << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
448 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
448 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
448 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
448 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
428 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
448 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
448 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
428 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
3 ms |
468 KB |
Output is correct |
10 |
Correct |
3 ms |
468 KB |
Output is correct |
11 |
Correct |
5 ms |
448 KB |
Output is correct |
12 |
Correct |
2 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
4 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
448 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
448 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
428 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
3 ms |
468 KB |
Output is correct |
17 |
Correct |
3 ms |
468 KB |
Output is correct |
18 |
Correct |
5 ms |
448 KB |
Output is correct |
19 |
Correct |
2 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
4 ms |
468 KB |
Output is correct |
22 |
Correct |
3 ms |
480 KB |
Output is correct |
23 |
Correct |
2 ms |
468 KB |
Output is correct |
24 |
Correct |
5 ms |
468 KB |
Output is correct |
25 |
Correct |
8 ms |
468 KB |
Output is correct |
26 |
Correct |
8 ms |
452 KB |
Output is correct |
27 |
Correct |
3 ms |
444 KB |
Output is correct |
28 |
Correct |
7 ms |
508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
448 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
448 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
428 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
2 ms |
580 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
6 ms |
596 KB |
Output is correct |
18 |
Correct |
3 ms |
468 KB |
Output is correct |
19 |
Correct |
5 ms |
596 KB |
Output is correct |
20 |
Incorrect |
2 ms |
588 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
448 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
448 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
428 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
3 ms |
468 KB |
Output is correct |
17 |
Correct |
3 ms |
468 KB |
Output is correct |
18 |
Correct |
5 ms |
448 KB |
Output is correct |
19 |
Correct |
2 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
4 ms |
468 KB |
Output is correct |
22 |
Correct |
3 ms |
480 KB |
Output is correct |
23 |
Correct |
2 ms |
468 KB |
Output is correct |
24 |
Correct |
5 ms |
468 KB |
Output is correct |
25 |
Correct |
8 ms |
468 KB |
Output is correct |
26 |
Correct |
8 ms |
452 KB |
Output is correct |
27 |
Correct |
3 ms |
444 KB |
Output is correct |
28 |
Correct |
7 ms |
508 KB |
Output is correct |
29 |
Correct |
2 ms |
580 KB |
Output is correct |
30 |
Correct |
2 ms |
468 KB |
Output is correct |
31 |
Correct |
6 ms |
596 KB |
Output is correct |
32 |
Correct |
3 ms |
468 KB |
Output is correct |
33 |
Correct |
5 ms |
596 KB |
Output is correct |
34 |
Incorrect |
2 ms |
588 KB |
Output isn't correct |
35 |
Halted |
0 ms |
0 KB |
- |