100142024-03-24 09:49:04111Autópálya inflációcpp17Time limit exceeded 0/1002.099s13284 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long

#define MOD 1000000007

bitset<3072> add(bitset<3072> a, bitset<3072> b) {
	bitset<3072> result;
	int carry = 0;
	for (int i = 0; i < 3072; i++) {
		int sum = a[i] + b[i] + carry;
		result[i] = sum & 1;
		carry = sum >> 1;
	}
	return result;
}

struct B{
	bitset<3072>b;
	B(bitset<3072>b):b(b){
	}
	B(int x,int p):b(bitset<3072>(x)<<p){
	}
	operator int(){
		int r=0;
		int p=1;
		for(int i=0;i<3072;i++){
			r+=b[i]*p;
			r%=MOD;
			p*=2;
			p%=MOD;
		}
		return r;
	}
	friend B operator+(B a,B b){
		return B(add(a.b,b.b));
	}
	friend B operator<<(B a,int h){
		return B(a.b<<h);
	}
	friend bool operator<(B a,B b){
		for(int i=3071;i>=0;i--){
			if(!a.b[i]&&b.b[i]){
				return true;
			}
			if(a.b[i]&&!b.b[i]){
				return false;
			}
		}
		return false;
	}
};

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N,M;
	cin>>N>>M;
	vector<vector<pair<int,B>>>g(N);
	for(int i=0;i<M;i++){
		int a,b,w;
		cin>>a>>b>>w;
		a--,b--;
		g[a].emplace_back(b,B(w,0));
		g[b].emplace_back(a,B(w,0));
	}
	vector<array<B,2>>dp(N,{B(1,N*2),B(1,N*2)});
	dp[0][0]=B(0,0);
	for(int i=0;i+1<N;i++){
		vector<int>v;
		for(int j=0;j<N;j++){
			if(i>0&&dp[j][i&1]>=dp[j][i&1^1]){
				dp[j][i&1]=dp[j][i&1^1];
				continue;
			}
			v.push_back(j);
		}
		for(int j:v){
			for(auto[k,w]:g[j]){
				auto c=dp[j][i&1]+(w<<i);
				if(c<dp[k][i&1^1]){
					dp[k][i&1^1]=c;
				}
			}
		}
	}
	for(int i=1;i<N;i++){
		cout<<(int)dp[i][(N-1)&1]<<'\n';
	}
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted4ms1708 KiB
2Time limit exceeded2.099s10096 KiB
subtask20/8
3Time limit exceeded2.082s6896 KiB
4Time limit exceeded2.069s6572 KiB
5Time limit exceeded2.062s6876 KiB
6Time limit exceeded2.099s7104 KiB
7Time limit exceeded2.062s6844 KiB
subtask30/15
8Wrong answer6ms3100 KiB
9Accepted7ms3044 KiB
10Wrong answer6ms3172 KiB
11Wrong answer6ms3240 KiB
12Wrong answer6ms3328 KiB
13Wrong answer7ms3656 KiB
14Wrong answer6ms3460 KiB
15Wrong answer6ms3652 KiB
16Wrong answer7ms3660 KiB
17Accepted4ms3868 KiB
18Wrong answer4ms3948 KiB
subtask40/34
19Time limit exceeded2.065s12036 KiB
20Time limit exceeded2.069s12076 KiB
21Time limit exceeded2.046s12036 KiB
22Time limit exceeded2.062s11972 KiB
23Time limit exceeded2.069s12036 KiB
24Time limit exceeded2.062s11960 KiB
25Time limit exceeded2.042s11868 KiB
26Time limit exceeded2.062s11332 KiB
27Time limit exceeded2.062s10312 KiB
28Time limit exceeded2.055s8320 KiB
29Time limit exceeded2.069s8440 KiB
30Time limit exceeded2.071s8344 KiB
31Time limit exceeded2.082s8432 KiB
32Time limit exceeded2.082s12000 KiB
33Time limit exceeded2.069s12016 KiB
subtask50/21
34Time limit exceeded2.062s5228 KiB
35Time limit exceeded2.066s6464 KiB
36Time limit exceeded2.082s6592 KiB
37Time limit exceeded2.055s6796 KiB
38Time limit exceeded2.038s6540 KiB
39Time limit exceeded2.066s6904 KiB
40Time limit exceeded2.078s6388 KiB
41Time limit exceeded2.078s6060 KiB
42Time limit exceeded2.082s4948 KiB
43Time limit exceeded2.042s4936 KiB
44Time limit exceeded2.072s4960 KiB
45Time limit exceeded2.049s4868 KiB
46Time limit exceeded2.065s4992 KiB
47Time limit exceeded2.059s4964 KiB
48Time limit exceeded2.069s5444 KiB
49Time limit exceeded2.069s5596 KiB
subtask60/22
50Time limit exceeded2.062s13040 KiB
51Time limit exceeded2.069s13052 KiB
52Time limit exceeded2.046s12928 KiB
53Time limit exceeded2.046s13284 KiB
54Time limit exceeded2.078s12600 KiB
55Time limit exceeded2.082s12388 KiB
56Time limit exceeded2.065s11156 KiB
57Time limit exceeded2.073s11268 KiB
58Time limit exceeded2.069s5772 KiB
59Time limit exceeded2.049s9040 KiB
60Time limit exceeded2.065s9076 KiB
61Time limit exceeded2.058s9148 KiB
62Time limit exceeded2.069s9028 KiB
63Time limit exceeded2.03s9060 KiB
64Time limit exceeded2.099s12384 KiB
65Time limit exceeded2.075s12320 KiB
66Time limit exceeded2.062s11476 KiB