ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#205092 | #3645. 单调图 | tkswls | 100 | 5991ms | 16808kb | C++11 | 2.9kb | 2024-06-23 10:18:17 | 2024-06-23 13:03:09 |
answer
#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
int n, m, cnt, ccnt, head[100005], nxt[400005], to[400005], w[400005], d[100005];
map<pair<int, pair<int, int>>, int> ma;
struct node {
int a, b, c, num, ans;
} b[100005], c[100005];
int ans[200005];
bool comp1(node p, node q) {
return (p.a == q.a) ? (p.b == q.b ? p.c < q.c : p.b < q.b) : (p.a < q.a);
}
bool comp2(node p, node q) {
return (p.b == q.b ? p.c < q.c : p.b < q.b);
}
int a[10000007];
inline int lowbit(int p) {
return p & -p;
}
inline void add(int p, int q) {
while (p <= m) {
a[p] += q;
p += lowbit(p);
}
}
inline int query(int p) {
int ccnt = 0;
while (p >= 1) {
ccnt += a[p];
p -= lowbit(p);
}
return ccnt;
}
void solve(int l, int r) {
if (l == r) return;
int mid = (l + r) >> 1;
solve(l, mid);
solve(mid + 1, r);
sort(c + l, c + mid + 1, comp2);
sort(c + mid + 1, c + r + 1, comp2);
int ll = l, rr = mid + 1;
for (rr = mid + 1; rr <= r; rr++) {
while (ll <= mid && c[ll].b <= c[rr].b) {
add(c[ll].c, c[ll].num);
ll++;
}
c[rr].ans += query(c[rr].c);
}
for (int i = l; i <= ll - 1; i++) {
add(c[i].c, -c[i].num);
}
}
inline void dijkstra(int s) {
memset(d, 0x3f, sizeof(d));
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> que;
que.push(make_pair(0, s));
d[s] = 0;
int ct = 0;
while (que.size()) {
pair<int, int> u = que.top();
que.pop();
if (d[u.second] != u.first) continue;
// cout << u.first << " " << u.second << " " << (++ct) << "\n";
for (int i = head[u.second]; i; i = nxt[i]) {
if (d[to[i]] > u.first + w[i]) {
d[to[i]] = u.first + w[i];
que.push(make_pair(d[to[i]], to[i]));
}
}
}
}
inline void add(int p, int q, int ww) {
nxt[++ccnt] = head[p];
to[ccnt] = q;
head[p] = ccnt;
w[ccnt] = ww;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
int p, q, ww;
for (int i = 1; i <= m; i++) {
cin >> p >> q >> ww;
add(p, q, ww), add(q, p, ww);
}
dijkstra(1);
int maxn = 0;
for (int i = 1; i <= n; i++) {
b[i].a = d[i] + 1;
maxn = max(maxn, d[i] + 1);
}
dijkstra(2);
for (int i = 1; i <= n; i++) {
b[i].b = d[i] + 1;
maxn = max(maxn, d[i] + 1);
}
dijkstra(3);
for (int i = 1; i <= n; i++) {
b[i].c = d[i] + 1;
maxn = max(maxn, d[i] + 1);
ma[make_pair(b[i].a, make_pair(b[i].b, b[i].c))]++;
// cout << i << " " << b[i].a << " " << b[i].b << ' ' << b[i].c << "\n";
}
sort(b + 1, b + n + 1, comp1);
m = 10000001;
int op = 1;
for (int i = 2; i <= n + 1; i++) {
if (b[i].a != b[i - 1].a || b[i].b != b[i - 1].b || b[i].c != b[i - 1].c) {
c[++cnt] = b[i - 1];
c[cnt].num = op;
op = 1;
} else {
op++;
}
}
solve(1, cnt);
int aans = 0;
for (int i = 1; i <= n; i++) {
if (c[i].ans == 0) aans += c[i].num;
}
cout << aans;
}
Details
小提示:点击横条可展开更详细的信息
Test #1:
score: 5
Accepted
time: 0ms
memory: 1780kb
input:
250 300 224 221 81 7 224 11 19 221 40 186 7 96 149 19 86 143 149 75 111 221 47 4 221 84 87 224 28 24...
output:
33
result:
ok single line: '33'
Test #2:
score: 5
Accepted
time: 0ms
memory: 1784kb
input:
250 300 15 55 47 44 15 29 36 44 39 147 15 76 114 55 20 47 15 99 5 36 44 185 55 37 224 5 67 113 147 4...
output:
27
result:
ok single line: '27'
Test #3:
score: 5
Accepted
time: 0ms
memory: 1784kb
input:
250 300 145 60 26 26 145 19 131 26 62 73 131 66 228 26 4 250 60 32 30 73 32 210 26 33 161 131 68 70 ...
output:
33
result:
ok single line: '33'
Test #4:
score: 5
Accepted
time: 1ms
memory: 1784kb
input:
250 300 212 227 26 70 227 83 122 70 31 245 122 1 162 122 18 89 212 45 233 89 78 159 162 49 87 70 89 ...
output:
37
result:
ok single line: '37'
Test #5:
score: 5
Accepted
time: 6ms
memory: 1988kb
input:
1800 2000 481 73 36 1145 481 90 899 481 12 855 899 71 117 1145 87 17 855 51 1223 17 13 1708 1145 55 ...
output:
43
result:
ok single line: '43'
Test #6:
score: 5
Accepted
time: 5ms
memory: 1988kb
input:
1800 2000 1533 1556 16 1551 1556 96 1076 1556 37 31 1551 83 40 1076 18 1648 1551 97 1760 1533 89 141...
output:
58
result:
ok single line: '58'
Test #7:
score: 5
Accepted
time: 5ms
memory: 1992kb
input:
1800 2000 554 498 60 442 554 18 54 498 9 1798 54 33 422 1798 14 1696 54 41 201 1798 40 297 1798 63 8...
output:
49
result:
ok single line: '49'
Test #8:
score: 5
Accepted
time: 285ms
memory: 15872kb
input:
100000 99999 5092 35397 69 59669 5092 13 66060 5092 45 45290 66060 57 86709 5092 79 37616 86709 66 7...
output:
5616
result:
ok single line: '5616'
Test #9:
score: 5
Accepted
time: 243ms
memory: 15332kb
input:
100000 99999 76853 94 59 27726 94 13 90492 76853 33 97933 90492 71 46476 97933 18 6568 90492 37 3242...
output:
3202
result:
ok single line: '3202'
Test #10:
score: 5
Accepted
time: 270ms
memory: 15304kb
input:
100000 99999 20874 85984 48 8458 20874 88 50743 8458 100 41101 8458 84 8267 20874 86 30201 8458 55 3...
output:
4659
result:
ok single line: '4659'
Test #11:
score: 5
Accepted
time: 311ms
memory: 12848kb
input:
100000 200000 53018 80768 61 5832 80768 43 2997 80768 91 66393 80768 56 81366 5832 59 85664 5832 16 ...
output:
40
result:
ok single line: '40'
Test #12:
score: 5
Accepted
time: 599ms
memory: 16120kb
input:
100000 200000 28908 36036 66 91872 36036 84 1622 28908 74 60237 1622 1 17200 28908 44 89734 28908 82...
output:
39
result:
ok single line: '39'
Test #13:
score: 5
Accepted
time: 471ms
memory: 14128kb
input:
100000 200000 80169 49117 81 59533 80169 11 38687 80169 66 73361 49117 69 86848 80169 39 97609 73361...
output:
37
result:
ok single line: '37'
Test #14:
score: 5
Accepted
time: 594ms
memory: 15100kb
input:
100000 200000 8518 10111 89 80152 8518 82 28398 8518 42 64281 8518 89 79057 10111 31 67454 64281 64 ...
output:
52
result:
ok single line: '52'
Test #15:
score: 5
Accepted
time: 638ms
memory: 16796kb
input:
100000 200000 63008 51968 67 14619 63008 33 38273 63008 86 30436 51968 98 95240 30436 21 44387 51968...
output:
118
result:
ok single line: '118'
Test #16:
score: 5
Accepted
time: 501ms
memory: 16804kb
input:
100000 200000 38428 6838 6 57875 38428 62 23341 6838 42 77486 57875 67 36886 57875 99 35263 6838 58 ...
output:
106
result:
ok single line: '106'
Test #17:
score: 5
Accepted
time: 582ms
memory: 16788kb
input:
100000 200000 29745 3984 50 23260 3984 62 53496 23260 79 81207 53496 13 79920 81207 44 90071 53496 1...
output:
99
result:
ok single line: '99'
Test #18:
score: 5
Accepted
time: 473ms
memory: 16776kb
input:
100000 200000 46691 643 96 325 46691 74 74789 325 7 65177 46691 54 98613 46691 46 69449 643 77 60913...
output:
62
result:
ok single line: '62'
Test #19:
score: 5
Accepted
time: 477ms
memory: 16804kb
input:
100000 200000 33629 97358 73 44862 33629 12 25151 33629 46 87268 25151 34 81508 25151 83 45636 81508...
output:
160
result:
ok single line: '160'
Test #20:
score: 5
Accepted
time: 530ms
memory: 16808kb
input:
100000 200000 68252 47666 98 62764 68252 87 84831 68252 91 49616 68252 73 58627 68252 71 33313 68252...
output:
166
result:
ok single line: '166'
Extra Test:
score: 0
Extra Test Passed