QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#272561#7883. Takeout Deliveringucup-team1074#WA 175ms40988kbC++233.2kb2023-12-02 17:49:262023-12-02 17:49:27

Judging History

你现在查看的是最新测评结果

  • [2023-12-02 17:49:27]
  • 评测
  • 测评结果:WA
  • 用时:175ms
  • 内存:40988kb
  • [2023-12-02 17:49:26]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
#define x first
#define y second 
#define endl '\n'
const LL maxn = 4e05+7;
const LL N = 5e05+10;
const LL mod = 1e09+7;
const int inf = 0x3f3f3f3f;
const LL llinf = 5e18;
typedef pair<int,int>pl;
priority_queue<LL , vector<LL>, greater<LL> >mi;//小根堆
priority_queue<LL> ma;//大根堆
LL gcd(LL a, LL b){
	return b > 0 ? gcd(b , a % b) : a;
}

LL lcm(LL a , LL b){
	return a / gcd(a , b) * b;
}
vector<int>a(N , 0);
void init(int n){
	for(int i = 0 ; i <= n ; i ++){
		a[i] = 0;
	}
}
struct node{
	int num;
	int dis;
	int dis_2;
	bool operator > (const node &t) const
	{	
		if(dis != t.dis)
		return dis > t.dis;
		else
			return dis_2 > t.dis_2;
	}
}tmp;
int dis[N];
int dis_2[N];
int dis2[N];
int dis2_2[N];
int isv[N];
int isv2[N];
int n,m;
vector<node>tr[N];
void dij(int s)
{
	memset(dis,0x3f3f3f3f,sizeof dis);
	priority_queue<node,vector<node> , greater<node> > q;
	q.push({s,0,0});
	dis[s] = 0;
	while(!q.empty())
	{
		tmp = q.top();
		int x = tmp.num;//起点
		q.pop();
		if(isv[x] == 1)
			continue;
		isv[x] = 1;
//		cout<<x<<endl;
		for(int i = 0 ; i < (int)tr[x].size() ; i ++ )
		{
			node now = tr[x][i];
			int len = tr[x][i].dis;//边长
			int e = tr[x][i].num;//	
			int len1 = max(dis[x] , len);
			int len2 = max(dis_2[x] , min(dis[x] , len));
			if(dis[e] > len1)
			{
				dis[e] = len1;
				dis_2[e] = len2;
				q.push({e,dis[e] , dis_2[e]});
			}
			else if(dis[e] == len1){
				dis_2[e] = min(dis_2[e] , len2);
				q.push({e , dis[e] , dis_2[e]});
			}
		}
	}
}
void dij2(int s)
{
	memset(dis2 , 0x3f3f3f3f , sizeof dis2); 
	priority_queue<node,vector<node> , greater<node> > q;
	q.push({s,0 ,0});
	dis2[s] = 0;
	while(!q.empty())
	{
		tmp = q.top();
		int x = tmp.num;//起点
		q.pop();
		if(isv2[x] == 1)
			continue;
		isv2[x] = 1;
//		cout<<x<<endl;
		for(int i = 0 ; i < (int)tr[x].size() ; i ++ )
		{
			node now = tr[x][i];
			int len = tr[x][i].dis;//边长
			int e = tr[x][i].num;//	
			int len1 = max(dis2[x] , len);
			int len2 = max(dis2_2[x] , min(dis2[x] , len));
			if(dis2[e] > len1)
			{
				dis2[e] = len1;
				dis2_2[e] = len2;
				q.push({e,dis2[e] , dis2_2[e]});
			}
			else if(dis2[e] == len1){
				dis2_2[e] = min(dis2_2[e] , len2);
				q.push({e , dis2[e] , dis2_2[e]});
			}
		}
	}
}
void solve() 
{
	cin >> n >> m;
	vector<array<int,3>>bian;
	for(int i = 0 ; i < m ; i ++){
		int u , v , dis;
		cin >> u >> v >> dis;
		tr[u].pb({v , dis});
		tr[v].pb({u , dis});
		bian.pb({u , v , dis});
	}
	dij(1);
	dij2(n);
	LL ans = 1e18;
	for(auto it: tr[1]){
		if(it.num == n){
			ans = it.dis;
		}
	}
	for(int i = 0 ; i < m ; i ++){
		int u = bian[i][0] , v = bian[i][1] , diss = bian[i][2];
		if(dis[u] <= diss && dis[v] <= diss){
			ans = min(ans , 1LL * diss + max(max(dis[u] , dis2[v]) , max(dis[v] , dis2[u])));
		}
	}
	cout << ans;
}            
int main() 
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(10);
    int t=1;
	//cin>>t;
    while(t--)
    {
    	solve();
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 23376kb

input:

4 6
1 2 2
1 3 4
1 4 7
2 3 1
2 4 3
3 4 9

output:

5

result:

ok 1 number(s): "5"

Test #2:

score: -100
Wrong Answer
time: 175ms
memory: 40988kb

input:

300000 299999
80516 80517 597830404
110190 110191 82173886
218008 218009 954561262
250110 250111 942489774
66540 66541 156425292
34947 34948 239499776
273789 273790 453201232
84428 84429 439418398
98599 98600 326095035
55636 55637 355015760
158611 158612 684292473
43331 43332 43265001
171621 171622 ...

output:

1356916107

result:

wrong answer 1st numbers differ - expected: '1999991697', found: '1356916107'