ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#205107 | #3645. 单调图 | wosile | 100 | 2658ms | 18768kb | C++11 | 2.9kb | 2024-06-23 12:47:05 | 2024-06-23 13:05:23 |
answer
#include<bits/stdc++.h>
using namespace std;
int n,m;
vector<pair<int,int> >G[100005];
int dis[4][100005],vis[100005];
priority_queue<pair<int,int> >pq;
struct node{
int a,b,c,ok;
bool operator <(const node &o)const{
return a<o.a;
}
}d[100005];
int dc[100005];
vector<node>v[100005];
int mx[400005];
void update(int l,int r,int x,int pos,int val){
if(l==r){
mx[x]=min(mx[x],val);
return;
}
int mid=(l+r)/2;
if(pos<=mid)update(l,mid,x<<1,pos,val);
else update(mid+1,r,x<<1|1,pos,val);
mx[x]=min(mx[x<<1],mx[x<<1|1]);
}
int query(int l,int r,int x,int L,int R){
if(L>R)return 0x3f3f3f3f;
if(L<=l && r<=R)return mx[x];
int mid=(l+r)/2,ans=0x3f3f3f3f;
if(L<=mid)ans=min(ans,query(l,mid,x<<1,L,R));
if(R>mid)ans=min(ans,query(mid+1,r,x<<1|1,L,R));
return ans;
}
void build(int l,int r,int x){
mx[x]=0x3f3f3f3f;
if(l==r)return;
int mid=(l+r)/2;
build(l,mid,x<<1);
build(mid+1,r,x<<1|1);
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++){
int u,v,w;
scanf("%d%d%d",&u,&v,&w);
G[u].push_back({v,w});
G[v].push_back({u,w});
}
memset(dis,0x3f,sizeof(dis));
for(int s=1;s<=3;s++){
dis[s][s]=0;
memset(vis,0,sizeof(vis));
pq.push({0,s});
while(!pq.empty()){
int f=pq.top().second;
pq.pop();
if(vis[f])continue;
vis[f]=1;
for(auto p:G[f]){
int v=p.first,w=p.second;
if(dis[s][f]+w<dis[s][v]){
dis[s][v]=dis[s][f]+w;
pq.push({-dis[s][v],v});
}
}
}
}
for(int i=1;i<=n;i++){
d[i].a=dis[1][i];
d[i].b=dis[2][i];
d[i].c=dis[3][i];
// scanf("%d%d%d",&d[i].a,&d[i].b,&d[i].c);
d[i].ok=1;
}
sort(d+1,d+n+1);
for(int i=1;i<=n;i++)dc[i]=d[i].a;
sort(dc+1,dc+n+1);
int lena=unique(dc+1,dc+n+1)-dc-1;
for(int i=1;i<=n;i++)d[i].a=lower_bound(dc+1,dc+lena+1,d[i].a)-dc;
for(int i=1;i<=n;i++)dc[i]=d[i].b;
sort(dc+1,dc+n+1);
int lenb=unique(dc+1,dc+n+1)-dc-1;
for(int i=1;i<=n;i++)d[i].b=lower_bound(dc+1,dc+lenb+1,d[i].b)-dc;
for(int i=1;i<=n;i++)dc[i]=d[i].c;
sort(dc+1,dc+n+1);
int lenc=unique(dc+1,dc+n+1)-dc-1;
for(int i=1;i<=n;i++)d[i].c=lower_bound(dc+1,dc+lenc+1,d[i].c)-dc;
for(int i=1;i<=n;i++)v[d[i].a].push_back(d[i]);
int ans=0;
build(1,lenb,1);
for(int i=1;i<=lena;i++){
for(node &x:v[i]){
// printf("%d %d %d\n",x.a,x.b,x.c);
if(query(1,lenb,1,1,x.b)<=x.c)x.ok=0;
}
for(node &x:v[i])update(1,lenb,1,x.b,x.c);
for(node &x:v[i]){
if(query(1,lenb,1,1,x.b)<x.c || query(1,lenb,1,1,x.b-1)<=x.c)x.ok=0;
ans+=x.ok;
}
}
printf("%d",ans);
return 0;
}
Details
小提示:点击横条可展开更详细的信息
Test #1:
score: 5
Accepted
time: 0ms
memory: 7924kb
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: 7920kb
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: 7924kb
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: 0ms
memory: 7924kb
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: 0ms
memory: 8064kb
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: 0ms
memory: 8064kb
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: 6ms
memory: 8060kb
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: 148ms
memory: 17368kb
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: 150ms
memory: 17384kb
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: 139ms
memory: 17392kb
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: 202ms
memory: 18744kb
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: 218ms
memory: 18760kb
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: 231ms
memory: 18768kb
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: 207ms
memory: 18760kb
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: 232ms
memory: 18760kb
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: 218ms
memory: 18756kb
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: 231ms
memory: 18760kb
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: 211ms
memory: 18748kb
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: 232ms
memory: 18756kb
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: 233ms
memory: 18756kb
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