QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#649809 | #6845. Tax | N_z_ | WA | 0ms | 3788kb | C++23 | 7.0kb | 2024-10-18 10:38:02 | 2024-10-18 10:38:04 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
struct time_helper{
#ifdef LOCAL
clock_t time_last;time_helper(){time_last=clock();}void test(){auto time_now=clock();std::cerr<<"time:"<<1.*(time_now-time_last)/CLOCKS_PER_SEC<<";all_time:"<<1.*time_now/CLOCKS_PER_SEC<<std::endl;time_last=time_now;}~time_helper(){test();}
#else
void test(){}
#endif
}time_helper;
#ifdef LOCAL
#include"dbg.h"
#else
#define dbg(...) (__VA_ARGS__)
#endif
namespace Fread{const int SIZE=1<<16;char buf[SIZE],*S,*T;inline char getchar(){if(S==T){T=(S=buf)+fread(buf,1,SIZE,stdin);if(S==T)return'\n';}return *S++;}}namespace Fwrite{const int SIZE=1<<16;char buf[SIZE],*S=buf,*T=buf+SIZE;inline void flush(){fwrite(buf,1,S-buf,stdout);S=buf;}inline void putchar(char c){*S++=c;if(S==T)flush();}struct NTR{~NTR(){flush();}}ztr;}
#define getchar Fread::getchar
#define putchar Fwrite::putchar
int print_precision=10;bool print_T_endl=1;char print_between=' ';
template<typename T>struct is_char{static constexpr bool value=(std::is_same<T,char>::value||std::is_same<T,signed char>::value||std::is_same<T,unsigned char>::value);};template<typename T>struct is_integral_ex{static constexpr bool value=(std::is_integral<T>::value||std::is_same<T,__int128>::value)&&!is_char<T>::value;};template<typename T>struct is_floating_point_ex{static constexpr bool value=std::is_floating_point<T>::value||std::is_same<T,__float128>::value;};namespace Fastio{struct Reader;struct Writer;template<size_t id>struct read_tuple{template<typename...T>static void read(Reader&stream,std::tuple<T...>&x){read_tuple<id-1>::read(stream,x);stream>>get<id-1>(x);}};template<>struct read_tuple<0>{template<typename...T>static void read([[maybe_unused]]Reader&stream,[[maybe_unused]]std::tuple<T...>&x){}};template<size_t id>struct print_tuple{template<typename...T>static void print(Writer&stream,const std::tuple<T...>&x){print_tuple<id-1>::print(stream,x);putchar(print_between);stream<<get<id-1>(x);}};template<>struct print_tuple<1>{template<typename...T>static void print(Writer&stream,const std::tuple<T...>&x){stream<<get<0>(x);}};template<>struct print_tuple<0>{template<typename...T>static void print([[maybe_unused]]Writer&stream,[[maybe_unused]]const std::tuple<T...>&x){}};
struct Reader{template<typename T>typename std::enable_if_t<std::is_class<T>::value,Reader&>operator>>(T&x){for(auto &y:x)*this>>y;return *this;}template<typename...T>Reader&operator>>(std::tuple<T...>&x){read_tuple<sizeof...(T)>::read(*this,x);return *this;}template<typename T>typename std::enable_if_t<is_integral_ex<T>::value,Reader&>operator>>(T&x){char c=getchar();short f=1;while(c<'0'||c>'9'){if(c=='-')f*=-1;c=getchar();}x=0;while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=getchar();}x*=f;return *this;}template<typename T>typename std::enable_if_t<is_floating_point_ex<T>::value,Reader&>operator>>(T&x){char c=getchar();short f=1,s=0;x=0;T t=0;while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else return x*=f,*this;while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}template<typename T>typename std::enable_if_t<is_char<T>::value,Reader&>operator>>(T&c){c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();return *this;}Reader&operator>>(char*str){int len=0;char c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();while(c!='\n'&&c!=' '&&c!='\r')str[len++]=c,c=getchar();str[len]='\0';return*this;}template<typename T1,typename T2>Reader&operator>>(std::pair<T1,T2>&x){*this>>x.first>>x.second;return *this;}Reader&operator>>(std::string&str){str.clear();char c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();while(c!='\n'&&c!=' '&&c!='\r')str.push_back(c),c=getchar();return*this;}Reader(){}}cin;const char endl='\n';
struct Writer{typedef __int128 mxdouble;template<typename T>typename std::enable_if_t<std::is_class<T>::value,Writer&>operator<<(const T&x){for(auto q:x){*this<<q;if(!is_class<decltype(q)>::value)*this<<print_between;}if(!is_class<typename T::value_type>::value&&print_T_endl)*this<<'\n';return *this;}template<typename...T>Writer&operator<<(const std::tuple<T...>&x){print_tuple<sizeof...(T)>::print(*this,x);if(print_T_endl)*this<<'\n';return *this;}template<typename T>typename std::enable_if_t<is_integral_ex<T>::value,Writer&>operator<<(T x){if(x==0)return putchar('0'),*this;if(x<0)putchar('-'),x=-x;static int sta[45];int top=0;while(x)sta[++top]=x%10,x/=10;while(top)putchar(sta[top]+'0'),--top;return*this;}template<typename T>typename std::enable_if_t<is_floating_point_ex<T>::value,Writer&>operator<<(T x){if(x<0)putchar('-'),x=-x;x+=pow(10,-print_precision)/2;mxdouble _=x;x-=(T)_;static int sta[45];int top=0;while(_)sta[++top]=_%10,_/=10;if(!top)putchar('0');while(top)putchar(sta[top]+'0'),--top;putchar('.');for(int i=0;i<print_precision;i++)x*=10;_=x;while(_)sta[++top]=_%10,_/=10;for(int i=0;i<print_precision-top;i++)putchar('0');while(top)putchar(sta[top]+'0'),--top;return*this;}template<typename T>typename std::enable_if_t<is_char<T>::value,Writer&>operator<<(const T&c){putchar(c);return*this;}Writer&operator<<(char*str){int cur=0;while(str[cur])putchar(str[cur++]);return *this;}Writer&operator<<(const char*str){int cur=0;while(str[cur])putchar(str[cur++]);return*this;}template<typename T1,typename T2>Writer&operator<<(const std::pair<T1,T2>&x){*this<<x.first<<print_between<<x.second;if(print_T_endl)*this<<'\n';return *this;}Writer&operator<<(const std::string&str){int st=0,ed=str.size();while(st<ed)putchar(str[st++]);return*this;}Writer(){}}cout;}
#define cin Fastio::cin
#define cout Fastio::cout
#define endl Fastio::endl
template<class Fun>class y_combinator_result{Fun fun_;public:template<class T>explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}template<class ...Args>decltype(auto) operator()(Args &&...args){return fun_(std::ref(*this), std::forward<Args>(args)...);}};template<class Fun>decltype(auto) y_combinator(Fun &&fun){return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));}
void init();void solve(int tc);
main()
{
init();int t=1;
// cin>>t;
for(int tc=1;tc<=t;tc++)solve(tc);
}
void init()
{
}
void solve([[maybe_unused]]int tc)
{
int n,m;
cin>>n>>m;
vector<int>w(m+1);
for(int x=1;x<=m;x++)
cin>>w[x];
vector<vector<int>>e(n+1);
vector<vector<pair<int,int>>>e2(n+1);
vector<tuple<int,int,int>>E;
for(int x=1;x<=m;x++)
{
int u,v,c;
cin>>u>>v>>c;
e[u].emplace_back(v);
e[v].emplace_back(u);
E.emplace_back(u,v,c);
}
vector<int>dis(n+1,-1);
dis[1]=1;
queue<int>q;
q.push(1);
while(!q.empty())
{
int u=q.front();
q.pop();
for(auto v:e[u])
if(dis[v]==-1)dis[v]=dis[u]+1,q.push(v);
}
for(auto [u,v,c]:E)
{
if(dis[u]+1==dis[v])e2[u].emplace_back(v,c);
if(dis[v]+1==dis[u])e2[v].emplace_back(u,c);
}
vector<int>ans(n+1,1e9),cnt(n+1);
y_combinator([&](auto dfs,int u,int nc)->void
{
ans[u]=min(ans[u],nc);
for(auto [v,c]:e2[u])
{
cnt[c]++;
dfs(v,nc+w[c]*cnt[c]);
cnt[c]--;
}
})(1,0);
for(int x=2;x<=n;x++)
cout<<ans[x]<<endl;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3552kb
input:
5 6 1 8 2 1 3 9 1 2 1 2 3 2 1 4 1 3 4 6 3 5 4 4 5 1
output:
1 9 1 3
result:
ok 4 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3652kb
input:
10 15 730 2163 6818 4647 9699 1037 2034 8441 2619 6164 464 4369 4500 6675 1641 1 6 2 3 6 1 3 2 1 9 2 2 7 3 1 6 5 1 5 3 2 3 10 1 10 2 2 5 10 1 8 2 2 9 8 1 7 4 2 4 5 2 4 10 2
output:
4353 2893 7219 2893 2163 4353 8679 8679 4353
result:
ok 9 lines
Test #3:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
10 15 847 2302 8846 8055 585 6541 6493 7165 5376 8551 836 2993 2700 9323 5119 2 1 5 2 3 3 3 10 3 10 4 3 8 3 4 10 8 1 3 7 3 4 5 3 5 8 5 6 3 3 8 6 2 6 5 4 9 10 2 7 9 4 5 9 4
output:
585 9431 53661 18656 27123 27123 17486 29425 27123
result:
ok 9 lines
Test #4:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
20 30 4547 9278 5093 443 7292 7570 7138 9315 4114 723 9854 9584 294 1861 5478 2734 5967 7102 6137 9504 456 7980 9645 6571 336 5308 1035 8008 3128 4035 7 1 2 11 7 1 11 12 2 12 10 2 10 5 2 20 5 1 20 17 2 17 16 2 16 18 1 7 19 3 19 12 1 2 18 2 3 7 1 12 3 1 19 3 1 13 11 1 12 13 1 19 13 1 13 3 2 18 15 2 8...
output:
166078 13825 98229 41653 28012 9278 28012 38198 37474 13825 18918 18918 24557 166078 106231 78397 128966 14371 56754
result:
ok 19 lines
Test #5:
score: 0
Accepted
time: 0ms
memory: 3660kb
input:
20 30 2477 6652 1326 9801 9300 5132 8051 7482 5793 1154 4960 1452 2591 6386 6573 9726 7902 868 9089 6179 7249 2439 5355 8561 7168 3785 9180 2898 8103 5168 10 1 2 10 15 5 15 2 3 2 5 1 6 5 5 9 6 3 9 18 2 20 18 1 20 14 3 8 2 5 13 10 3 13 2 1 5 19 1 9 19 4 19 8 3 9 12 1 19 12 4 7 15 5 7 2 4 16 10 2 16 1...
output:
10455 13107 40665 15409 24709 29256 19755 27361 6652 67805 32208 7978 52074 15952 19956 34510 40665 22407 48096
result:
ok 19 lines
Test #6:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
20 30 3440 3226 6455 7629 6160 9354 1868 2631 4819 1142 7323 8166 4862 9851 7430 8785 3563 7421 2271 9637 6088 2754 4062 8932 7510 7797 9647 8657 4123 293 9 1 18 9 4 17 4 14 7 14 17 7 7 17 14 3 7 13 3 10 11 10 16 16 16 13 6 9 20 20 20 4 13 10 8 3 13 8 16 4 5 20 11 16 11 8 11 13 2 17 12 4 18 1 18 17 ...
output:
23732 30279 10984 15466 17730 25417 44057 7421 37602 53781 24185 52842 12852 20175 46387 15566 14424 12240 17058
result:
ok 19 lines
Test #7:
score: 0
Accepted
time: 0ms
memory: 3500kb
input:
30 50 7129 2843 1688 6915 6827 4756 6845 140 1403 8426 6939 8317 2320 9371 1611 8403 8356 3846 7594 9874 6888 5183 7945 6815 2910 3776 1550 2580 5566 5155 3505 1935 945 4665 3328 4162 9529 6486 7771 8357 471 354 7208 3344 8628 7321 4624 9058 3737 6828 1 10 3 10 17 1 17 5 1 21 5 1 21 9 3 30 9 3 30 8 ...
output:
4531 55325 85265 11660 10217 41067 32538 18657 1688 15036 161199 120867 20722 85265 73893 8817 89352 149383 85265 13593 99480 73893 75137 8817 7129 63765 55325 66697 25409
result:
ok 29 lines
Test #8:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
30 50 1816 811 3173 8236 9775 9764 9318 2725 3832 2365 5954 6959 72 3542 3353 6839 5277 3333 9313 3833 8198 1409 1669 7304 1094 5752 7393 9532 8997 6858 728 5391 1567 5803 2319 5231 8563 9045 1695 928 6021 4868 6246 1639 3132 6408 5335 1263 6884 6134 17 1 8 17 10 7 10 28 4 3 28 6 3 7 9 7 22 6 25 22 ...
output:
88680 11738 77782 107316 83230 19402 74150 59701 4643 7008 13961 61202 2365 38986 89353 2725 85975 83011 12489 49926 29166 79838 59386 36261 64375 48304 12879 3832 66652
result:
ok 29 lines
Test #9:
score: 0
Accepted
time: 0ms
memory: 3788kb
input:
30 50 9227 712 7087 3799 7334 2513 2685 8147 5727 415 5898 8487 1938 9946 6164 46 7086 5664 318 3545 840 7810 6397 4201 6297 6036 9036 3750 5708 3216 7705 8875 17 3620 1046 6055 6077 3839 4393 605 9048 6984 1692 6869 317 5863 3725 3897 1213 9498 23 1 5 29 23 1 30 29 14 24 30 19 24 14 15 14 16 15 16 ...
output:
58976 54062 20296 55016 25960 15302 55431 36391 48335 33210 58561 15523 21051 65140 19399 72869 25063 46194 29836 70356 18368 7334 14887 33625 1938 39108 23796 4623 14569
result:
ok 29 lines
Test #10:
score: -100
Wrong Answer
time: 0ms
memory: 3588kb
input:
30 50 5448 5807 3224 8952 8304 8530 5876 727 784 1901 7392 2903 8670 6927 1771 2274 4866 9258 794 9474 7772 5238 8948 2154 3691 4109 917 6173 1719 7485 3788 9957 8904 9705 6252 1773 8092 4024 8863 8888 5061 2373 9550 184 4905 4045 3114 6519 4400 9876 1 2 11 9 2 17 9 24 7 24 5 24 12 5 34 29 12 5 29 4...
output:
7392 50123 24002 12810 20902 31604 8119 12258 22068 41795 489319500 12442 53875 67331 31774 49567 62545 37777 489344467 29806 27116 63133 18134 26156 27693 59027 41001 23275 52561
result:
wrong answer 11th lines differ - expected: '22515', found: '489319500'