QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#384121 | #3704. Travel | ucup-team1251 | TL | 2ms | 14808kb | C++17 | 2.3kb | 2024-04-09 20:52:27 | 2024-04-09 20:52:27 |
Judging History
answer
#include<iostream>
#include<string.h>
#include<stdio.h>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<math.h>
#include<set>
#include<unordered_map>
#include<deque>
//#define int long long
//__builtin_popcount();
//next_permutation(start,end)和prev_permutation(start,end)
using namespace std;
typedef pair<int, int>PII;
const int N = 1e6+ 10, M = 5e2 + 10;
int n,m,t1,t2;
int h[N],ne[N],e[N],idx,d[N],st[N];
inline int read()
{
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-')
f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9')
{
x=(x<<1)+(x<<3)+(ch^48);
ch=getchar();
}
return x*f;
}
void add(int x,int y)
{
ne[idx]=h[x];
e[idx]=y;
h[x]=idx++;
}
void dd()
{
for(int i=1;i<=n;i++)
{
d[i]=0x3f3f3f3f;
st[i]=0;
}
d[1]=0;
queue<PII>q;
q.push({1,0});
while(q.empty()==0)
{
PII tt=q.front();
q.pop();
int x=tt.first;
int y=tt.second;
if(x==n)break;
if(st[x])continue;
st[x]=1;
for(int i=h[x];i!=-1;i=ne[i])
{
int j=e[i];
if(d[j]>y+1)
{
d[j]=y+1;
q.push({j,d[j]});
}
}
}
long long int tt=d[n]*t1;
long long int ans=min(tt,(long long int)t2);
printf("%lld\n",ans);
}
void ff()
{
for(int i=1;i<=n;i++)d[i]=0x3f3f3f3f;
d[1]=0;
set<int>st,op;
set<int>::iterator it;
for(int i=2;i<=n;i++)st.insert(i);
queue<int>q;
q.push(1);
while(q.empty()==0)
{
int x=q.front();
q.pop();
for(int i=h[x];i!=-1;i=ne[i])
{
int j=e[i];//当前有边的
st.erase(j);//当前不能用,但是后面能用
op.insert(j);//下次用
}
for(it=st.begin();it!=st.end();it++)
{
q.push(*it);
d[*it]=d[x]+1;//在前面的基础上加上;
}
st.swap(op);
op.clear();
}
long long int tt=d[n]*t2;
long long int ans=min((long long int)t1,tt);
printf("%lld\n",ans);
}
void df()
{
while(scanf("%d",&n)!=EOF)
{
m=read();
t1=read();
t2=read();
int flag=0;
memset(h,-1,sizeof(h));
idx=0;
while(m--)
{
int x,y;
x=read();
y=read();
if(x>y)swap(x,y);
if(x==1&&y==n)flag=1;
add(x,y);
add(y,x);
}
if(flag==0)
{
if(t2<=t1)printf("%d\n",t2);
else
dd();
}
else
{
if(t1<=t2)printf("%d\n",t1);
else ff();
}
}
}
signed main() {
// ios::sync_with_stdio(false);
// cin.tie(0);
// cout.tie(0);
int t = 1;
// cin >> t;
while (t--) {
df();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 14128kb
input:
3 2 1 3 1 2 2 3
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 0ms
memory: 14644kb
input:
3 2 2 3 1 2 2 3
output:
3
result:
ok 1 number(s): "3"
Test #3:
score: 0
Accepted
time: 2ms
memory: 11224kb
input:
2 0 1 1
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 12980kb
input:
2 0 1 1000000000
output:
1000000000
result:
ok 1 number(s): "1000000000"
Test #5:
score: 0
Accepted
time: 2ms
memory: 12512kb
input:
100 2000 348125329 153783443 72 45 79 6 13 64 27 3 22 13 1 76 33 87 72 41 41 30 10 3 43 46 12 40 40 86 38 34 92 96 16 70 11 95 26 78 54 43 50 49 55 82 18 67 49 58 85 41 34 94 57 13 40 44 34 49 95 77 30 74 77 2 90 76 51 98 5 78 5 43 8 96 66 43 74 23 47 25 7 28 77 86 96 4 99 53 80 88 13 29 9 44 51 44 ...
output:
153783443
result:
ok 1 number(s): "153783443"
Test #6:
score: 0
Accepted
time: 1ms
memory: 12300kb
input:
100 2000 231241457 727332287 93 57 38 67 83 11 37 23 90 1 63 91 98 40 48 68 49 83 2 72 57 65 48 94 10 55 71 34 9 50 43 97 62 34 38 10 62 91 2 86 47 74 59 47 62 84 85 81 51 27 6 43 87 21 56 34 48 79 19 54 46 37 98 13 63 48 79 99 38 23 15 48 7 46 13 12 12 31 36 14 35 44 89 60 97 19 80 55 92 70 88 70 2...
output:
231241457
result:
ok 1 number(s): "231241457"
Test #7:
score: 0
Accepted
time: 0ms
memory: 14808kb
input:
100 2000 409324881 595848427 30 6 45 83 92 65 90 4 64 48 5 10 83 85 89 32 6 40 22 54 9 27 51 84 87 55 85 19 37 38 95 75 6 24 53 78 16 28 16 4 33 8 9 32 2 86 70 29 41 12 21 33 24 39 52 22 65 8 36 31 36 81 82 91 81 77 79 21 54 21 57 58 92 8 7 54 2 89 75 49 83 91 74 70 31 57 64 24 34 14 48 68 56 59 52 ...
output:
595848427
result:
ok 1 number(s): "595848427"
Test #8:
score: -100
Time Limit Exceeded
input:
100 2000 292441009 24173080 45 35 76 39 54 47 69 8 86 14 16 76 65 48 18 7 32 46 56 91 22 32 66 74 68 59 63 59 21 80 85 67 4 38 37 96 4 1 90 20 43 2 13 45 49 28 86 36 22 10 44 64 95 9 64 91 35 61 16 2 49 13 72 85 45 65 78 22 44 59 58 22 44 48 7 13 42 97 21 15 41 45 59 30 98 97 86 7 31 60 94 19 61 66 ...