QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#138465#4357. School RoadAntekb#0 310ms70596kbC++141.5kb2023-08-11 19:21:002024-07-04 01:37:10

Judging History

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

  • [2024-07-04 01:37:10]
  • 评测
  • 测评结果:0
  • 用时:310ms
  • 内存:70596kb
  • [2023-08-11 19:21:00]
  • 提交

answer

#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define eb emplace_back
#define pp pop_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
using namespace std;
using vi = vector<int>;
using pii = pair<int, int>;
using vii = vector<pii>;
using ll = long long;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const int N=18;
vii E[N];
ll dp[N][1<<N], dist2[N];
int main(){
	int n, m;
	cin>>n>>m;
	for(int i=0; i<m; i++){
		int u, v, w;
		cin>>u>>v>>w;
		u--;
		v--;
		E[u].eb(v, w);
		E[v].eb(u, w);
	}
	vector<pii> dobre;
	for(int i=0; i<n; i++){
		for(int j=0; j<(1<<n); j++){
			if(j&(1<<i)){
				dobre.eb(i, j);
				dp[i][j]=-1e18;
			}
		}
	}
	dp[0][1]=0;
	ll L=0;
	for(int t=0; t<n; t++){
		for(pii i:dobre){
			int v=i.st, m=i.nd;
			for(pii u:E[v]){
				if(!((1<<u.st)&m)){
					dp[u.st][m|(1<<u.st)]=max(dp[u.st][m|(1<<u.st)], dp[v][m]+u.nd);
					if(u.st==n-1)L=max(L, dp[v][m]+u.nd);
				}
			}
		}
	}
	for(int i=0; i<n; i++){
		dist2[i]=1e18;
	}
	dist2[n-1]=0;
	priority_queue<pair<ll, int>> Q;
	for(int i=0; i<n; i++){
		Q.push(mp(-dist2[i], i));
	}
	while(Q.size()){
		ll d=-Q.top().st;
		int v=Q.top().nd;
		//cerr<<d<<" "<<v<<"\n";
		Q.pop();
		if(dist2[v]!=d)continue;
		for(pii u:E[v]){
			if(dist2[u.st]>d+u.nd){
				dist2[u.st]=d+u.nd;
				Q.push(mp(-dist2[u.st], u.st));
			}
		}
	}
	cerr<<L<<" "<<dist2[0]<<"\n";
	cout<<(L!=dist2[0]);
}

詳細信息

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 7
Accepted
time: 13ms
memory: 31040kb

input:

14 40
8 12 570429827
6 10 592780730
13 14 299807355
4 10 729771483
4 10 729771483
6 9 746405411
2 3 696576351
12 14 192640790
4 13 284900209
1 2 857968292
12 14 192640790
8 12 570429827
6 10 592780730
6 9 746405411
9 11 329648726
4 13 284900209
2 3 696576351
4 10 729771483
5 11 101819611
3 7 1824073...

output:

0

result:

ok single line: '0'

Test #2:

score: -7
Runtime Error

input:

41 40
12 19 102666211
30 32 10931929
8 34 88862177
11 29 37284876
6 35 24117284
6 11 24483138
10 35 11019124
4 22 509961847
20 39 77098829
25 33 563195350
22 24 781289886
2 17 238185039
21 27 288940653
3 31 62767763
18 21 350694322
2 40 228181439
3 33 109276182
31 36 203571934
28 34 64098677
14 24 3...

output:


result:


Subtask #2:

score: 0
Time Limit Exceeded

Test #11:

score: 15
Accepted
time: 281ms
memory: 70596kb

input:

18 40
3 10 26965732
5 15 67047331
3 17 42474964
13 15 129212204
9 18 142540287
2 14 27157962
5 15 67047331
5 15 67047331
5 15 67047331
4 16 212978971
6 12 51548223
4 18 192438222
13 16 60052417
16 17 162364835
6 17 55527270
9 11 58810843
3 7 95393586
13 15 129212204
2 17 67824762
5 15 67047331
15 16...

output:

0

result:

ok single line: '0'

Test #12:

score: 0
Accepted
time: 310ms
memory: 70096kb

input:

18 51
5 16 489370441
7 8 674383722
8 11 602435525
1 10 856666364
13 18 650829027
11 14 198398173
3 4 613940394
15 17 123758204
8 11 602435525
3 6 567757815
13 18 650829027
14 15 236674174
3 4 613940394
5 18 956980171
6 16 887883755
3 6 567757815
6 16 887883755
5 18 956980171
4 10 339471731
11 14 198...

output:

0

result:

ok single line: '0'

Test #13:

score: -15
Time Limit Exceeded

input:

18 200000
8 17 279042056
12 13 907447344
2 16 240997679
3 7 820773384
1 5 45712022
2 16 240997679
4 18 239293113
9 14 389857788
4 18 239293113
4 18 239293113
1 11 409366186
3 12 208134361
2 16 240997679
13 17 263089947
1 5 45712022
4 18 239293113
4 7 528521172
2 9 629050323
8 17 279042056
12 13 9074...

output:


result:


Subtask #3:

score: 0
Runtime Error

Test #18:

score: 0
Runtime Error

input:

100000 99999
42115 93495 19881095
21969 68351 161710
7405 86343 27129
37307 45676 320013
30388 71545 117761
22026 68957 65332
77949 81644 2281387
24865 95079 341488
9849 98496 2548159
53911 79572 4962105
24880 62622 1678564
15943 22168 1524688
67424 78323 2450655
32175 74893 1908332
35640 39305 1043...

output:


result:


Subtask #4:

score: 0
Time Limit Exceeded

Test #57:

score: 0
Time Limit Exceeded

input:

18 400
11 18 145314505
1 18 242896789
1 18 242896789
5 13 31030812
13 18 93451080
1 18 242896789
1 7 123378068
1 18 242896789
1 18 242896789
1 18 242896789
1 18 242896789
1 18 242896789
1 18 242896789
1 3 42183985
1 18 242896789
13 18 93451080
1 18 242896789
13 18 93451080
1 18 242896789
1 18 242896...

output:


result:


Subtask #5:

score: 0
Skipped

Dependency #1:

0%