QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#168070#6807. Travel DreamkkioWA 548ms14328kbC++176.7kb2023-09-07 20:51:102023-09-07 20:51:11

Judging History

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

  • [2023-09-07 20:51:11]
  • 评测
  • 测评结果:WA
  • 用时:548ms
  • 内存:14328kb
  • [2023-09-07 20:51:10]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
namespace FastIO {
	struct IO {
	    char ibuf[(1 << 20) + 1], *iS, *iT, obuf[(1 << 20) + 1], *oS;
	    IO() : iS(ibuf), iT(ibuf), oS(obuf) {} ~IO() { fwrite(obuf, 1, oS - obuf, stdout); }
		#if ONLINE_JUDGE
		#define gh() (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, (1 << 20) + 1, stdin), (iS == iT ? EOF : *iS++) : *iS++)
		#else
		#define gh() getchar()
		#endif
		inline bool eof (const char &ch) { return ch == ' ' || ch == '\n' || ch == '\r' || ch == 't' || ch == EOF; }
	    inline long long read() {
	        char ch = gh();
	        long long x = 0;
	        bool t = 0;
	        while (ch < '0' || ch > '9') t |= ch == '-', ch = gh();
	        while (ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = gh();
	        return t ? ~(x - 1) : x;
	    }
	    inline void read (char *s) {
	    	char ch = gh(); int l = 0;
	    	while (eof(ch)) ch = gh();
	    	while (!eof(ch)) s[l++] = ch, ch = gh();
	    }
	    inline void read (double &x) {
	    	char ch = gh(); bool t = 0;
	    	while (ch < '0' || ch > '9') t |= ch == '-', ch = gh();
	    	while (ch >= '0' && ch <= '9') x = x * 10 + (ch ^ 48), ch = gh();
	    	if (ch != '.') return t && (x = -x), void(); ch = gh();
	    	for (double cf = 0.1; '0' <= ch && ch <= '9'; ch = gh(), cf *= 0.1) x += cf * (ch ^ 48);
	    	t && (x = -x);
	    }
	    inline void pc (char ch) {
	    	#ifdef ONLINE_JUDGE
	    	if (oS == obuf + (1 << 20) + 1) fwrite(obuf, 1, oS - obuf, stdout), oS = obuf; 
	    	*oS++ = ch;
	    	#else
	    	putchar(ch);
	    	#endif
		}
		template<typename _Tp>
	    inline void write (_Tp x) {
	    	static char stk[64], *tp = stk;
	    	if (x < 0) x = ~(x - 1), pc('-');
			do *tp++ = x % 10, x /= 10;
			while (x);
			while (tp != stk) pc((*--tp) | 48);
	    }
	    inline void write (char *s) {
	    	int n = strlen(s);
	    	for (int i = 0; i < n; i++) pc(s[i]);
	    }
	} io;
	inline long long read () { return io.read(); }
	template<typename Tp>
	inline void read (Tp &x) { io.read(x); }
	template<typename _Tp>
	inline void write (_Tp x) { io.write(x); }
}
using namespace FastIO;
#define int long long 
const int maxn=305,inf=1e18;
int n,m,k;
vector< tuple<int,int,int> > G[maxn];
bool col[maxn];
int f[6][maxn][maxn],up[maxn],vp[maxn],wp[maxn],h[maxn][maxn][3],idh[maxn][maxn][3];
mt19937 rnd(231232134);
void init1()
{
    for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)f[1][i][j]=-inf;
    for(int i=1;i<=n;i++)f[1][i][i]=0;
}
void init2()
{
    for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)f[2][i][j]=-inf;
    for(int i=1;i<=m;i++)
        if(col[up[i]]==col[vp[i]])f[2][up[i]][vp[i]]=f[2][vp[i]][up[i]]=max(f[2][up[i]][vp[i]],wp[i]);
}
inline void init3()
{
    for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)f[3][i][j]=-inf;
    for(int i=1;i<=n;i++)
        for(auto [j,w1,id1]:G[i])
            for(auto [k,w2,id2]:G[i])
                if(col[i]==col[j]&&col[i]==col[k]&&j!=k)
                    f[3][k][j]=f[3][j][k]=max(f[3][j][k],w1+w2);
}
inline void init4()
{
    for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)f[4][i][j]=-inf;
    for(int i=1;i<=m;i++)
    {
        if(col[up[i]]!=col[vp[i]])continue;
        for(auto [j,w1,id1]:G[up[i]])
            for(auto [k,w2,id2]:G[vp[i]])
                if(col[up[i]]==col[j]&&col[vp[i]]==col[k]&&up[i]!=k&&vp[i]!=j&&k!=j)
                    f[4][j][k]=f[4][k][j]=max(f[4][j][k],w1+w2+wp[i]);
    }
}
inline void upd(int v,int id,int i,int j)
{for(int t=0;t<3;t++)if(v>h[i][j][t]){swap(v,h[i][j][t]);swap(id,idh[i][j][t]);}}
inline int findminsec(int idn1,int idn2,int i,int j)
{for(int t=0;t<3;t++)if(idn1!=h[i][j][t]&&idn2!=h[i][j][t])return h[i][j][t];return -inf;}
inline void init5()
{
    for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)f[5][i][j]=h[i][j][0]=h[i][j][1]=h[i][j][2]=-inf;
    for(int i=1;i<=n;i++)
        for(auto [j,w1,id1]:G[i])
            for(auto [k,w2,id2]:G[i])
                if(col[i]==col[j]&&col[i]==col[k]&&j!=k)
                {
                    upd(w1+w2,i,j,k);
                    upd(w1+w2,i,k,j);
                }
    for(int i=1;i<=m;i++)
        for(int j=1;j<=m;j++)
        {
            if(col[up[i]]!=col[vp[i]]||col[up[i]]!=col[up[j]]||col[up[i]]!=col[vp[j]]||col[up[j]]!=col[vp[j]]||up[i]==up[j]||up[i]==vp[j]||vp[i]==up[j]||vp[i]==vp[j])continue;
            f[5][up[i]][vp[j]]=max(f[5][up[i]][vp[j]],wp[i]+wp[j]+findminsec(up[i],vp[j],vp[i],up[j]));
            f[5][up[i]][up[j]]=max(f[5][up[i]][up[j]],wp[i]+wp[j]+findminsec(up[i],up[j],vp[i],vp[j]));
            f[5][vp[i]][vp[j]]=max(f[5][vp[i]][vp[j]],wp[i]+wp[j]+findminsec(vp[i],vp[j],up[i],up[j]));
            f[5][vp[i]][up[j]]=max(f[5][vp[i]][up[j]],wp[i]+wp[j]+findminsec(vp[i],up[j],up[i],vp[j]));
        }
}
signed main()
{
    n=read(),m=read(),k=read();
    for(int i=1;i<=m;i++)
        up[i]=read(),vp[i]=read(),wp[i]=read();
    for(int i=1;i<=m;i++)
    {
        G[up[i]].push_back({vp[i],wp[i],i});
        G[vp[i]].push_back({up[i],wp[i],i});
    }
    int t1=k/2,t2=k-t1,ans=-inf;
    if(k==3)
    {
        init2();
        for(int i=1;i<=m;i++)
            for(int j=1;j<=n;j++)
                if(j!=up[i]&&j!=vp[i])
                    ans=max(ans,wp[i]+f[2][up[i]][j]+f[2][vp[i]][j]);
    }
    else
    for(int sr=1;sr<=1000;sr++)
    {
        for(int i=1;i<=n;i++)col[i]=rnd()%2;
        if(t1==1||t2==1)init1();
        if(t1==2||t2==2)init2();
        if(t1==3||t2==3)init3();
        if(t1==4||t2==4)init4();
        if(t1==5||t2==5)init5();
        for(int i=1;i<=m;i++)
            for(int j=1;j<=m;j++)
            {
                if(up[i]!=up[j]&&up[i]!=vp[j]&&vp[i]!=up[j]&&vp[i]!=vp[j])
                {
                    
                    if(col[up[i]]==0&&col[vp[i]]==1&&col[up[j]]==0&&col[vp[j]]==1)
                        ans=max(ans,f[t1][up[i]][up[j]]+f[t2][vp[i]][vp[j]]+wp[i]+wp[j]);
                    if(col[up[i]]==0&&col[vp[i]]==1&&col[vp[j]]==0&&col[up[j]]==1)
                        ans=max(ans,f[t1][up[i]][vp[j]]+f[t2][vp[i]][up[j]]+wp[i]+wp[j]);
                    if(col[vp[i]]==0&&col[up[i]]==1&&col[up[j]]==0&&col[vp[j]]==1)
                        ans=max(ans,f[t1][vp[i]][up[j]]+f[t2][up[i]][vp[j]]+wp[i]+wp[j]);
                    if(col[vp[i]]==0&&col[up[i]]==1&&col[vp[j]]==0&&col[up[j]]==1)
                        ans=max(ans,f[t1][vp[i]][vp[j]]+f[t2][up[i]][up[j]]+wp[i]+wp[j]);
                }
            }
    }
    if(ans>0)printf("%lld\n",ans);
    else puts("impossible");
}
/*
6 13 3
2 1 99999998
3 1 99999998
3 2 100000000
4 1 99999998
4 2 100000000
4 3 99999998
5 1 99999999
5 2 99999998
5 3 99999998
5 4 99999998
6 1 99999998
6 2 99999998
6 3 99999998
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 10000kb

input:

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

output:

21

result:

ok single line: '21'

Test #2:

score: 0
Accepted
time: 2ms
memory: 9800kb

input:

5 4 5
1 2 1
2 3 6
3 1 5
4 5 2

output:

impossible

result:

ok single line: 'impossible'

Test #3:

score: 0
Accepted
time: 0ms
memory: 10028kb

input:

25 300 3
2 1 99999998
3 1 99999998
3 2 100000000
4 1 99999998
4 2 100000000
4 3 99999998
5 1 99999999
5 2 99999998
5 3 99999998
5 4 99999998
6 1 99999998
6 2 99999998
6 3 99999998
6 4 100000000
6 5 100000000
7 1 100000000
7 2 99999998
7 3 99999998
7 4 100000000
7 5 99999999
7 6 100000000
8 1 1000000...

output:

300000000

result:

ok single line: '300000000'

Test #4:

score: 0
Accepted
time: 240ms
memory: 7968kb

input:

25 300 4
2 1 99999998
3 1 99999999
3 2 100000000
4 1 100000000
4 2 99999999
4 3 100000000
5 1 100000000
5 2 99999998
5 3 100000000
5 4 99999998
6 1 100000000
6 2 100000000
6 3 100000000
6 4 99999999
6 5 99999999
7 1 99999998
7 2 99999999
7 3 99999998
7 4 100000000
7 5 99999998
7 6 100000000
8 1 1000...

output:

400000000

result:

ok single line: '400000000'

Test #5:

score: 0
Accepted
time: 258ms
memory: 12004kb

input:

25 300 5
2 1 100000000
3 1 100000000
3 2 99999999
4 1 99999998
4 2 99999999
4 3 100000000
5 1 100000000
5 2 100000000
5 3 99999999
5 4 99999999
6 1 99999998
6 2 100000000
6 3 99999998
6 4 100000000
6 5 100000000
7 1 99999999
7 2 99999998
7 3 100000000
7 4 99999999
7 5 99999998
7 6 100000000
8 1 1000...

output:

500000000

result:

ok single line: '500000000'

Test #6:

score: 0
Accepted
time: 259ms
memory: 9952kb

input:

25 300 6
2 1 99999998
3 1 99999999
3 2 99999998
4 1 100000000
4 2 99999998
4 3 100000000
5 1 99999998
5 2 99999999
5 3 100000000
5 4 99999999
6 1 100000000
6 2 99999998
6 3 99999998
6 4 99999998
6 5 99999998
7 1 100000000
7 2 99999998
7 3 99999998
7 4 99999998
7 5 99999999
7 6 99999999
8 1 99999999
...

output:

600000000

result:

ok single line: '600000000'

Test #7:

score: 0
Accepted
time: 368ms
memory: 10044kb

input:

25 300 7
2 1 99999999
3 1 99999998
3 2 100000000
4 1 100000000
4 2 99999998
4 3 100000000
5 1 99999999
5 2 99999999
5 3 99999998
5 4 99999998
6 1 99999998
6 2 99999999
6 3 99999998
6 4 99999999
6 5 99999998
7 1 99999999
7 2 100000000
7 3 99999999
7 4 100000000
7 5 99999999
7 6 100000000
8 1 99999998...

output:

700000000

result:

ok single line: '700000000'

Test #8:

score: 0
Accepted
time: 357ms
memory: 10016kb

input:

25 300 8
2 1 100000000
3 1 99999999
3 2 99999999
4 1 99999999
4 2 99999999
4 3 99999998
5 1 99999999
5 2 99999998
5 3 99999998
5 4 99999999
6 1 99999999
6 2 100000000
6 3 100000000
6 4 100000000
6 5 100000000
7 1 100000000
7 2 99999998
7 3 100000000
7 4 100000000
7 5 99999998
7 6 100000000
8 1 99999...

output:

800000000

result:

ok single line: '800000000'

Test #9:

score: 0
Accepted
time: 548ms
memory: 12132kb

input:

25 300 9
2 1 100000000
3 1 100000000
3 2 99999998
4 1 100000000
4 2 99999999
4 3 100000000
5 1 100000000
5 2 99999998
5 3 99999999
5 4 100000000
6 1 99999999
6 2 99999998
6 3 99999998
6 4 100000000
6 5 99999999
7 1 99999999
7 2 99999998
7 3 99999999
7 4 99999999
7 5 99999998
7 6 100000000
8 1 100000...

output:

900000000

result:

ok single line: '900000000'

Test #10:

score: 0
Accepted
time: 439ms
memory: 10152kb

input:

25 300 10
2 1 100000000
3 1 100000000
3 2 99999998
4 1 99999998
4 2 99999998
4 3 100000000
5 1 99999999
5 2 99999999
5 3 100000000
5 4 100000000
6 1 99999999
6 2 99999999
6 3 100000000
6 4 99999999
6 5 99999998
7 1 99999999
7 2 100000000
7 3 99999998
7 4 99999999
7 5 100000000
7 6 99999999
8 1 99999...

output:

1000000000

result:

ok single line: '1000000000'

Test #11:

score: 0
Accepted
time: 437ms
memory: 10136kb

input:

25 300 10
2 1 99999998
3 1 99999999
3 2 100000000
4 1 99999998
4 2 100000000
4 3 100000000
5 1 99999999
5 2 99999999
5 3 100000000
5 4 100000000
6 1 100000000
6 2 99999998
6 3 99999999
6 4 100000000
6 5 99999999
7 1 99999999
7 2 100000000
7 3 99999999
7 4 99999998
7 5 99999998
7 6 99999999
8 1 99999...

output:

1000000000

result:

ok single line: '1000000000'

Test #12:

score: 0
Accepted
time: 444ms
memory: 10144kb

input:

25 300 10
2 1 99999998
3 1 99999999
3 2 99999999
4 1 99999999
4 2 99999999
4 3 100000000
5 1 99999999
5 2 99999999
5 3 99999998
5 4 99999998
6 1 99999999
6 2 100000000
6 3 100000000
6 4 99999998
6 5 99999998
7 1 99999998
7 2 99999999
7 3 100000000
7 4 100000000
7 5 100000000
7 6 99999999
8 1 9999999...

output:

1000000000

result:

ok single line: '1000000000'

Test #13:

score: 0
Accepted
time: 449ms
memory: 14224kb

input:

25 300 10
2 1 100000000
3 1 99999998
3 2 99999998
4 1 99999999
4 2 99999999
4 3 100000000
5 1 100000000
5 2 99999999
5 3 99999998
5 4 99999998
6 1 100000000
6 2 99999998
6 3 100000000
6 4 100000000
6 5 99999998
7 1 99999999
7 2 99999999
7 3 99999998
7 4 99999999
7 5 99999998
7 6 99999999
8 1 1000000...

output:

1000000000

result:

ok single line: '1000000000'

Test #14:

score: 0
Accepted
time: 293ms
memory: 10016kb

input:

200 300 7
158 4 19455984
49 17 41490257
164 20 34015263
165 81 59517833
100 43 9035359
95 87 65603323
21 4 93967028
188 100 27640444
155 30 23870278
5 4 9389586
146 143 17531415
173 24 96302901
120 38 67662324
180 74 31349370
159 80 90566938
157 94 17571038
179 60 3747316
184 159 88847169
148 143 46...

output:

512464840

result:

ok single line: '512464840'

Test #15:

score: 0
Accepted
time: 268ms
memory: 10012kb

input:

200 300 8
188 105 86013599
121 13 55936286
76 43 76278705
187 26 42682689
143 40 52350321
156 68 70873098
169 116 12698892
141 58 58624230
182 63 6586023
192 12 68122225
137 50 9382385
191 171 79286831
107 42 622389
106 76 77410692
176 114 6694022
58 10 86897486
199 114 15771321
167 3 78086780
142 7...

output:

648877821

result:

ok single line: '648877821'

Test #16:

score: -100
Wrong Answer
time: 547ms
memory: 14328kb

input:

200 300 9
123 96 20892370
124 39 68549390
159 141 71568919
183 161 2548981
119 68 28505625
30 6 4991336
157 62 46856836
185 34 65937618
150 46 23426344
57 42 95862023
130 84 83643725
133 99 89615659
199 162 6075876
112 75 42349110
9 7 66231672
121 12 93444775
184 177 8399358
175 46 19498531
156 6 40...

output:

689799370

result:

wrong answer 1st lines differ - expected: '675650318', found: '689799370'