QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#43574 | #4243. Good Coloring | Leven | TL | 394ms | 10804kb | C++ | 1.7kb | 2022-08-09 19:15:45 | 2022-08-09 19:15:48 |
Judging History
answer
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize("inline")
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
// #define getchar() (frS==frT&&(frT=(frS=frBB)+fread(frBB,1,1<<15,stdin),frS==frT)?EOF:*frS++)
char frBB[1<<15],*frS=frBB,*frT=frBB;
inline long read(){
long ans=0,f=1;char chr=getchar();
while(!isdigit(chr)){if(chr=='-')f=-1;chr=getchar();}
while(isdigit(chr)){ans=(ans<<3)+(ans<<1)+chr-48;chr=getchar();}
return ans*f;
}
inline void cmax(int &a,int b){a<b?a=b:0;}
inline void cmin(int &a,int b){a>b?a=b:0;}
const int M = 3e5+5;
int n,m,k,T,ans,col[M],dp[M];
vector<int>g[M],Ans;
// auto dfs = [=](int x){
// for(int y:g[x])
// dfs(y),cmax(dp[x],dp[y]+1);
// }
void dfs(int x){
for(int y:g[x])
dfs(y),cmax(dp[x],dp[y]+1);
}
void dfs1(int x){
Ans.emplace_back(x);
for(int y:g[x])
if(dp[y]==dp[x]-1){
dfs1(y);
break;
}
}
signed main(){
T=read();
while(T--){
n=read(),m=read(),k=read();Ans.clear();
for(int i=1;i<=n;i++)col[i]=read(),dp[i]=0,g[i].clear();
for(int i=1,x,y;i<=m;i++){
x=read(),y=read();
if(col[x]<col[y])swap(x,y);
g[x].push_back(y);
}
for(int i=1;i<=n;i++)
if(!dp[i])dfs(i);
int S,ans=0;
for(int i=1;i<=n;i++)
if(dp[i]>ans)
ans=dp[i],S=i;
dfs1(S);
cout<<ans+1<<" ";
for(int i=1;i<=n;i++)cout<<dp[i]+1<<" ";cout<<endl;
for(auto x:Ans)cout<<x<<" ";cout<<endl;
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 6ms
memory: 10636kb
input:
2 3 3 3 1 2 3 1 2 2 3 3 1 3 1 3 1 2 3 1 2
output:
3 1 2 3 3 2 1 2 1 2 1 2 1
result:
ok good job (2 test cases)
Test #2:
score: 0
Accepted
time: 58ms
memory: 10632kb
input:
50000 5 7 5 5 2 3 1 5 4 3 3 1 5 2 5 4 5 3 2 4 4 1 6 5 5 1 1 4 5 5 2 2 3 3 5 6 1 2 4 1 5 7 5 6 4 6 3 5 6 5 3 5 4 5 6 7 2 1 2 3 6 7 7 4 3 4 2 1 3 4 1 6 7 3 4 3 6 3 5 6 1 2 3 2 4 5 6 5 3 3 4 4 1 4 5 2 3 5 2 3 1 4 2 5 1 6 6 3 2 3 2 2 1 1 2 6 3 5 2 5 6 3 4 5 4 6 7 5 2 1 2 1 1 2 2 1 5 4 5 3 7 5 1 2 3 2 7 ...
output:
3 3 2 2 1 3 1 3 4 3 1 1 2 2 3 2 5 3 2 3 1 2 1 1 3 2 1 5 6 3 3 1 3 2 1 3 3 1 2 3 4 3 2 2 3 3 1 3 2 5 2 1 2 2 2 1 1 2 6 2 1 2 1 1 2 1 1 2 1 3 2 1 1 1 1 3 1 6 1 5 4 2 3 1 1 4 5 2 1 4 2 1 1 1 2 2 1 4 1 3 2 1 2 1 1 3 6 3 4 3 2 1 1 1 2 2 3 7 1 3 3 1 1 1 2 2 3 1 6 4 2 3 1 2 1 2 3 ...
result:
ok good job (50000 test cases)
Test #3:
score: 0
Accepted
time: 46ms
memory: 10616kb
input:
20000 14 17 2 1 2 1 2 1 1 1 2 1 1 1 2 2 2 9 4 13 1 1 12 2 11 14 5 6 12 1 14 12 9 13 11 14 9 13 9 11 14 10 8 2 3 2 6 13 3 5 13 14 11 4 1 3 1 4 3 2 2 3 1 2 4 1 4 3 14 4 14 13 11 10 9 10 1 7 9 7 12 7 12 13 2 6 11 2 10 13 14 17 2 2 1 1 1 2 2 2 2 1 2 1 2 2 1 1 2 10 14 4 7 10 2 8 3 14 13 11 7 13 9 12 4 1 ...
output:
2 1 2 1 2 1 1 1 2 1 1 1 2 2 2 2 11 3 1 2 1 2 1 1 2 1 1 2 3 1 3 1 11 10 9 2 2 1 1 1 2 2 2 2 1 2 1 2 2 1 1 2 3 2 2 1 2 3 3 3 3 1 2 1 1 2 1 5 1 9 5 3 4 1 1 1 2 3 3 2 2 1 5 12 2 8 9 5 2 2 1 1 1 1 2 1 1 1 2 1 2 1 1 1 14 5 3 2 1 2 5 3 1 1 5 2 4 2 1 3 5 11 1 4 13 3 1 1 1 2 1 3 2 2 2 1 2 1 1 1...
result:
ok good job (20000 test cases)
Test #4:
score: 0
Accepted
time: 53ms
memory: 10688kb
input:
25000 10 13 8 1 3 3 8 6 6 7 4 2 4 6 7 4 5 3 1 3 8 4 1 5 1 9 4 7 4 10 5 6 4 5 8 9 1 4 2 10 14 10 8 8 9 6 4 3 7 10 2 10 6 8 2 10 8 2 8 3 7 10 4 8 3 4 5 9 9 8 2 4 5 6 1 3 1 8 10 4 10 11 8 2 1 5 4 5 3 1 7 3 8 2 10 2 1 9 3 8 9 10 7 3 6 8 1 8 2 9 1 1 10 2 3 10 6 3 1 1 3 3 1 2 3 1 1 3 3 8 6 8 6 1 5 10 8 10...
output:
5 1 1 2 5 4 1 2 3 2 1 4 5 8 3 1 3 1 2 2 1 2 1 1 3 1 3 8 2 4 4 2 1 4 1 1 1 1 4 3 3 3 9 1 2 2 1 1 2 1 1 2 1 1 1 2 3 8 3 2 2 1 2 2 1 3 1 1 2 7 2 8 4 3 1 3 4 1 2 1 1 4 4 4 3 6 2 5 3 2 2 5 1 2 1 2 4 4 9 1 3 7 2 2 2 1 2 1 2 1 1 1 1 1 9 5 3 2 3 3 2 1 1 1 4 5 10 9 4 2 7 4 1 1 1 1 2 4 3 2 3...
result:
ok good job (25000 test cases)
Test #5:
score: 0
Accepted
time: 36ms
memory: 10648kb
input:
5000 61 7 19 2 15 8 12 12 11 14 4 19 3 18 14 1 9 18 10 18 3 17 8 9 9 16 13 16 17 6 19 13 4 16 13 19 11 18 13 8 13 15 10 17 9 4 4 4 18 2 12 5 7 16 5 7 5 9 3 8 5 12 2 14 43 23 2 10 54 12 48 23 24 49 24 4 17 54 63 81 25 21 4 12 16 2 24 9 17 25 24 9 1 4 24 24 25 20 4 14 25 18 19 3 4 17 7 13 19 14 6 14 1...
output:
2 1 2 1 1 1 1 1 1 1 1 1 2 1 1 1 1 2 1 1 1 1 1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 10 6 5 1 4 1 1 5 2 4 5 5 2 1 1 4 4 6 2 1 2 3 3 3 2 1 1 1 1 3 1 3 3 1 2 1 2 1 2 4 5 2 2 3 2 1 3 2 1 2 4 2 1 1 2 3 2 1 2 2 3 5 4 1 1 16 10 49 30 41 5 6 2 1 1 2 3 2 2 4 2 1 ...
result:
ok good job (5000 test cases)
Test #6:
score: 0
Accepted
time: 43ms
memory: 10652kb
input:
5000 55 12 40 14 23 25 2 29 16 19 33 15 33 30 38 28 33 7 32 21 9 6 29 13 12 17 12 27 9 35 27 7 16 38 7 15 39 11 14 31 13 23 27 2 20 21 29 37 12 9 25 31 21 3 3 24 37 37 46 10 42 54 48 33 53 13 24 14 9 17 25 34 52 6 6 46 35 17 50 18 36 3 53 37 17 10 9 14 15 10 16 10 12 16 12 6 3 9 17 15 15 13 10 5 11 ...
output:
2 1 1 2 1 1 2 1 1 1 2 1 1 2 2 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 2 1 3 36 4 2 1 1 1 1 2 2 2 1 1 1 1 2 4 1 2 3 2 1 2 1 1 2 2 3 1 3 1 2 1 1 4 3 1 1 2 1 1 2 1 1 3 1 3 1 2 1 1 4 1 2 2 1 14 25 39 31 4 1 3 2 1 1 1 2 1 1 1 1 1 1 1 3 1 2 3 1 1 1 1 4 1 1 1 1 1 1...
result:
ok good job (5000 test cases)
Test #7:
score: 0
Accepted
time: 47ms
memory: 10644kb
input:
5000 59 13 29 17 8 27 4 12 9 19 23 13 4 7 27 25 9 14 10 6 7 10 19 18 4 5 1 26 8 17 27 15 26 14 26 6 4 18 11 9 21 15 20 25 15 17 24 29 6 22 28 8 3 26 20 23 11 23 27 10 6 18 52 5 31 24 43 15 10 45 53 24 46 40 37 29 33 2 46 13 34 33 23 15 38 11 22 45 55 77 18 10 16 13 4 9 12 14 6 8 16 17 1 9 16 10 13 9...
output:
3 1 3 1 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 2 1 1 1 1 2 1 2 1 1 3 1 2 1 1 1 1 1 1 2 2 1 1 1 1 1 1 2 33 34 5 2 1 3 3 2 1 2 1 3 4 5 1 3 5 3 2 4 2 1 5 1 2 5 4 2 4 2 2 1 1 1 5 4 3 3 1 2 3 1 2 3 3 1 2 2 1 5 4 2 2 2 1 4 2 2 11 10 4 37 30 4 1 2 2 3 3 1 2 2 2 3 1 1 1 1 1 2 1 1 2 1 ...
result:
ok good job (5000 test cases)
Test #8:
score: 0
Accepted
time: 53ms
memory: 10580kb
input:
5000 44 77 32 19 2 23 24 9 28 23 19 7 8 19 32 18 17 2 32 18 27 10 20 18 3 26 13 16 8 21 11 30 26 7 15 14 30 22 21 4 30 31 32 22 17 31 15 24 11 26 38 36 33 41 27 41 36 24 17 27 14 2 7 18 8 28 43 18 41 26 2 31 16 35 42 12 14 31 43 5 42 22 17 37 20 32 33 23 33 27 26 19 18 3 13 19 23 3 39 14 35 5 18 14 ...
output:
7 1 1 5 5 3 6 5 4 2 1 3 6 1 2 1 3 3 5 1 2 3 1 2 2 3 2 3 1 7 3 2 2 1 6 5 2 1 3 7 5 4 4 7 2 29 6 35 42 5 26 2 6 1 3 1 1 1 5 2 3 4 4 2 1 1 2 3 3 1 5 1 1 2 2 4 2 2 5 1 6 1 2 3 1 1 1 1 1 1 2 1 3 2 1 1 2 28 26 10 31 22 32 7 1 4 1 1 1 2 1 7 5 5 3 2 2 1 1 1 2 3 3 1 3 1 4 5 5 2 2 4 1 4 3 7 2 1 6 3 2 2 1 ...
result:
ok good job (5000 test cases)
Test #9:
score: 0
Accepted
time: 39ms
memory: 10604kb
input:
1000 135 126 10 8 2 5 6 1 9 3 7 4 10 10 8 4 5 1 8 10 1 8 10 1 5 8 7 4 1 5 6 6 4 8 8 1 3 7 2 1 4 8 1 10 2 3 6 8 7 4 4 6 2 6 1 7 3 3 6 7 9 8 2 10 1 9 9 3 8 9 9 2 3 8 2 7 1 2 10 5 5 5 1 3 1 1 6 6 7 3 6 8 1 10 10 8 8 4 2 4 5 7 9 4 7 1 1 3 6 10 2 10 1 1 9 1 9 1 6 10 4 2 6 9 3 3 9 7 10 2 8 7 3 10 8 3 3 7 ...
output:
6 4 1 2 3 1 3 2 4 1 1 3 3 2 2 1 3 6 1 3 3 1 2 1 2 1 1 1 2 1 3 1 5 1 2 1 1 1 3 1 1 2 1 1 1 2 1 2 1 2 1 2 1 1 2 2 2 1 1 1 1 3 1 3 1 1 2 2 1 2 1 3 1 3 1 1 3 1 1 3 1 1 1 1 4 2 2 1 3 2 1 4 1 3 2 2 1 1 2 2 5 2 1 1 1 2 4 3 2 6 1 1 2 1 3 1 2 1 2 1 3 3 1 2 2 1 3 1 3 2 1 3 1 1 1 3 17 32 84 38 108 37 10 2 7 ...
result:
ok good job (1000 test cases)
Test #10:
score: 0
Accepted
time: 363ms
memory: 10804kb
input:
1000 134 703 112 69 50 79 65 63 89 61 25 28 104 81 110 96 18 93 105 63 35 56 22 25 39 84 43 34 4 90 24 75 98 37 21 42 98 42 61 17 84 108 95 46 6 35 22 109 5 39 54 18 105 104 96 27 87 100 14 80 44 21 43 62 94 60 85 106 85 89 5 70 37 76 24 71 73 26 68 51 36 12 38 74 95 91 106 83 76 32 90 58 87 69 111 ...
output:
16 11 6 12 10 11 11 10 2 4 13 11 13 14 3 13 15 6 5 8 4 3 8 12 5 5 1 14 4 12 12 6 3 7 12 1 9 2 12 14 15 9 1 1 3 15 2 1 9 2 14 13 13 2 12 16 3 6 8 3 8 7 15 10 11 14 13 13 1 11 4 10 5 11 10 2 10 6 6 2 7 10 15 14 14 13 12 6 13 9 12 9 16 10 2 7 6 8 5 15 16 2 10 3 14 10 5 1 3 11 6 2 7 12 5 1 15 3 7 4 8 1 ...
result:
ok good job (1000 test cases)
Test #11:
score: 0
Accepted
time: 394ms
memory: 10656kb
input:
1000 147 745 6 1 3 2 5 5 6 4 6 1 6 4 6 4 4 5 3 5 4 6 3 1 4 6 3 2 5 2 5 1 6 1 1 6 3 6 5 5 5 5 3 2 6 1 4 2 1 5 5 6 1 3 3 2 3 1 1 2 4 4 6 6 5 3 1 3 4 3 2 2 5 5 3 5 3 2 5 1 3 1 2 2 2 5 2 4 5 5 1 2 1 6 1 3 4 6 2 6 4 3 6 6 6 6 3 3 5 1 4 6 5 5 5 3 2 4 6 5 5 5 6 2 2 6 5 1 4 4 2 5 5 6 3 3 6 4 6 5 6 5 6 2 2 3...
output:
6 1 3 2 5 4 6 4 6 1 6 4 6 4 4 5 3 3 4 5 3 1 4 6 3 2 5 2 5 1 6 1 1 6 3 6 3 4 5 4 3 1 6 1 4 2 1 4 5 6 1 3 2 2 3 1 1 1 4 4 6 6 5 3 1 2 4 3 2 2 5 5 3 5 3 2 5 1 3 1 2 2 1 4 2 4 3 5 1 2 1 6 1 1 4 6 2 5 4 3 6 6 6 6 3 3 4 1 4 6 5 5 4 3 2 4 5 5 5 5 5 2 2 6 5 1 4 4 2 4 5 6 3 3 6 4 6 5 6 5 6 2 2 3 3 5 1 1 6 4...
result:
ok good job (1000 test cases)
Test #12:
score: 0
Accepted
time: 223ms
memory: 10664kb
input:
1000 156 669 112 107 25 100 2 63 43 81 60 14 54 83 91 73 21 74 49 81 17 71 60 66 72 96 57 51 60 78 19 30 49 87 23 55 62 43 26 53 80 76 10 66 76 81 7 49 10 99 101 35 99 86 17 80 38 23 24 92 77 2 9 13 110 76 17 48 63 106 79 110 44 4 40 42 9 29 54 98 58 52 89 83 26 103 75 87 9 36 84 96 1 111 27 84 75 1...
output:
14 12 5 11 1 8 4 8 8 3 7 7 10 10 1 7 6 10 2 8 6 9 7 9 6 7 6 7 3 4 6 11 2 7 8 6 4 7 8 7 1 8 10 9 2 3 2 9 12 4 11 11 1 7 5 4 1 11 9 1 1 2 13 7 4 6 7 12 9 13 5 1 5 5 1 5 8 13 7 5 10 8 2 11 6 12 2 4 9 12 1 13 2 10 10 12 2 8 10 2 6 9 6 11 3 11 1 6 4 4 7 7 3 1 11 6 5 6 6 11 9 3 5 8 11 9 4 10 9 8 3 1 2 5 1...
result:
ok good job (1000 test cases)
Test #13:
score: -100
Time Limit Exceeded
input:
100 745 3559 5 2 2 3 4 5 1 1 3 1 3 5 3 2 1 3 2 4 2 3 1 3 3 1 1 3 4 3 3 2 2 4 1 1 2 1 2 1 1 3 4 4 1 4 1 5 2 2 2 5 2 3 4 2 3 4 5 5 5 2 1 2 5 4 2 3 5 1 1 1 2 4 1 5 1 1 5 4 2 4 4 4 5 4 5 5 5 5 3 5 1 4 4 4 1 5 4 4 5 4 2 2 5 1 2 4 1 4 3 3 4 1 3 2 4 4 5 3 2 1 1 1 1 4 1 4 3 4 3 2 1 1 1 1 5 5 1 5 3 5 1 4 2 2...