fork download
  1. #include <bits/stdc++.h>
  2.  
  3. #define ll long long
  4. #define X first
  5. #define Y second
  6. #define MP make_pair
  7.  
  8. using namespace std;
  9.  
  10. const int N = 4e5, INF = 1e9 + 7, bl = 300;
  11.  
  12. int n, k, p[N], clr[N], was[N], ans[N], maxx;
  13. vector<int> g[N], gr[N], topsort, cmp, gg[N];
  14.  
  15. void dfs(int v){
  16. was[v] = 1;
  17. for(int u: g[v]){
  18. if(!was[u])
  19. dfs(u);
  20. }
  21. topsort.push_back(v);
  22. }
  23.  
  24. void rdfs(int v){
  25. was[v] = 1;
  26. for(int u: gr[v]){
  27. if(!was[u])
  28. rdfs(u);
  29. }
  30. cmp.push_back(v);
  31. }
  32.  
  33. void vdfs(int v, int cc = 26){
  34. maxx = max(maxx, 26 - cc + 1);
  35. was[v] = 1, ans[v] = cc;
  36. for(int u: gg[v]){
  37. if(!was[u]){
  38. vdfs(u, max(cc - 1, 1));
  39. }
  40. }
  41. }
  42.  
  43. int main () {
  44. ios::sync_with_stdio(0);
  45. cin.tie(0);
  46. cout.tie(0);
  47.  
  48. cin >> n >> k;
  49. for(int i = 1;i <= n;i++){
  50. cin >> p[i];
  51. if(i != 1){
  52. g[p[i]].push_back(p[i - 1]);
  53. gr[p[i - 1]].push_back(p[i]);
  54. }
  55. }
  56. for(int i = 1;i <= n;i++){
  57. cin >> p[i];
  58. if(i != 1){
  59. g[p[i]].push_back(p[i - 1]);
  60. gr[p[i - 1]].push_back(p[i]);
  61. }
  62. }
  63. for(int i = 1;i <= n;i++){
  64. if(!was[i])
  65. dfs(i);
  66. }
  67. vector<int> tt;
  68.  
  69. reverse(topsort.begin(), topsort.end());
  70. memset(was, 0, sizeof(was));
  71. for(int i = 0, j = 0;i < n;i++){
  72. int v = topsort[i];
  73. if(!was[v]){
  74. cmp.clear();
  75. rdfs(v);
  76. j += 1;
  77. for(int u: cmp){
  78. clr[u] = j;
  79. }
  80. tt.push_back(j);
  81. }
  82. }
  83. for(int i = 1;i <= n;i++){
  84. for(int u: g[i]){
  85. if(clr[i] != clr[u])
  86. gg[clr[i]].push_back(clr[u]);
  87. }
  88. }
  89. memset(was, 0, sizeof(was));
  90. for(int i = 0;i < tt.size();i++){
  91. int v = tt[i];
  92. if(!was[v]){
  93. vdfs(v);
  94. }
  95. }
  96.  
  97. if(maxx < k)
  98. return cout << "NO", 0;
  99. cout << "YES\n";
  100.  
  101. for(int i = 1;i <= n;i++){
  102. char c = ans[clr[i]] - 1 + 'a';
  103. cout << c;
  104. }
  105. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: illegal character: '#'
#include <bits/stdc++.h>
^
Main.java:1: error: class, interface, or enum expected
#include <bits/stdc++.h>
         ^
Main.java:2: error: illegal character: '\u00a0'
?
^
Main.java:3: error: illegal character: '#'
#define ll long long
^
Main.java:4: error: illegal character: '#'
#define X first
^
Main.java:5: error: illegal character: '#'
#define Y second
^
Main.java:6: error: illegal character: '#'
#define MP make_pair
^
Main.java:7: error: illegal character: '\u00a0'
?
^
Main.java:9: error: illegal character: '\u00a0'
?
^
Main.java:10: error: class, interface, or enum expected
const int N = 4e5, INF = 1e9 + 7, bl = 300;
      ^
Main.java:11: error: illegal character: '\u00a0'
?
^
Main.java:12: error: class, interface, or enum expected
int n, k, p[N], clr[N], was[N], ans[N], maxx;
    ^
Main.java:13: error: class, interface, or enum expected
vector<int> g[N], gr[N], topsort, cmp, gg[N];
^
Main.java:14: error: illegal character: '\u00a0'
?
^
Main.java:15: error: class, interface, or enum expected
void dfs(int v){
     ^
Main.java:17: error: class, interface, or enum expected
    for(int u: g[v]){
    ^
Main.java:20: error: class, interface, or enum expected
    }
    ^
Main.java:22: error: class, interface, or enum expected
}
^
Main.java:23: error: illegal character: '\u00a0'
?
^
Main.java:26: error: class, interface, or enum expected
    for(int u: gr[v]){
    ^
Main.java:29: error: class, interface, or enum expected
    }
    ^
Main.java:31: error: class, interface, or enum expected
}
^
Main.java:32: error: illegal character: '\u00a0'
?
^
Main.java:35: error: class, interface, or enum expected
    was[v] = 1, ans[v] = cc;
    ^
Main.java:36: error: class, interface, or enum expected
    for(int u: gg[v]){
    ^
Main.java:39: error: class, interface, or enum expected
        }
        ^
Main.java:42: error: illegal character: '\u00a0'
?
^
Main.java:45: error: class, interface, or enum expected
    cin.tie(0);
    ^
Main.java:46: error: class, interface, or enum expected
    cout.tie(0);
    ^
Main.java:48: error: class, interface, or enum expected
    cin >> n >> k;
    ^
Main.java:49: error: class, interface, or enum expected
    for(int i = 1;i <= n;i++){
    ^
Main.java:49: error: class, interface, or enum expected
    for(int i = 1;i <= n;i++){
                  ^
Main.java:49: error: class, interface, or enum expected
    for(int i = 1;i <= n;i++){
                         ^
Main.java:51: error: class, interface, or enum expected
        if(i != 1){
        ^
Main.java:53: error: class, interface, or enum expected
            gr[p[i - 1]].push_back(p[i]);
            ^
Main.java:54: error: class, interface, or enum expected
        }
        ^
Main.java:56: error: class, interface, or enum expected
    for(int i = 1;i <= n;i++){
                  ^
Main.java:56: error: class, interface, or enum expected
    for(int i = 1;i <= n;i++){
                         ^
Main.java:58: error: class, interface, or enum expected
        if(i != 1){
        ^
Main.java:60: error: class, interface, or enum expected
            gr[p[i - 1]].push_back(p[i]);
            ^
Main.java:61: error: class, interface, or enum expected
        }
        ^
Main.java:63: error: class, interface, or enum expected
    for(int i = 1;i <= n;i++){
                  ^
Main.java:63: error: class, interface, or enum expected
    for(int i = 1;i <= n;i++){
                         ^
Main.java:66: error: class, interface, or enum expected
    }
    ^
Main.java:69: error: class, interface, or enum expected
    reverse(topsort.begin(), topsort.end());
    ^
Main.java:70: error: class, interface, or enum expected
    memset(was, 0, sizeof(was));
    ^
Main.java:71: error: class, interface, or enum expected
    for(int i = 0, j = 0;i < n;i++){
    ^
Main.java:71: error: class, interface, or enum expected
    for(int i = 0, j = 0;i < n;i++){
                         ^
Main.java:71: error: class, interface, or enum expected
    for(int i = 0, j = 0;i < n;i++){
                               ^
Main.java:73: error: class, interface, or enum expected
        if(!was[v]){
        ^
Main.java:75: error: class, interface, or enum expected
            rdfs(v);
            ^
Main.java:76: error: class, interface, or enum expected
            j += 1;
            ^
Main.java:77: error: class, interface, or enum expected
            for(int u: cmp){
            ^
Main.java:79: error: class, interface, or enum expected
            }
            ^
Main.java:81: error: class, interface, or enum expected
        }
        ^
Main.java:83: error: class, interface, or enum expected
    for(int i = 1;i <= n;i++){
                  ^
Main.java:83: error: class, interface, or enum expected
    for(int i = 1;i <= n;i++){
                         ^
Main.java:87: error: class, interface, or enum expected
        }
        ^
Main.java:90: error: class, interface, or enum expected
    for(int i = 0;i < tt.size();i++){
    ^
Main.java:90: error: class, interface, or enum expected
    for(int i = 0;i < tt.size();i++){
                  ^
Main.java:90: error: class, interface, or enum expected
    for(int i = 0;i < tt.size();i++){
                                ^
Main.java:92: error: class, interface, or enum expected
        if(!was[v]){
        ^
Main.java:94: error: class, interface, or enum expected
        }
        ^
Main.java:99: error: class, interface, or enum expected
    cout << "YES\n";
    ^
Main.java:101: error: class, interface, or enum expected
    for(int i = 1;i <= n;i++){
    ^
Main.java:101: error: class, interface, or enum expected
    for(int i = 1;i <= n;i++){
                  ^
Main.java:101: error: class, interface, or enum expected
    for(int i = 1;i <= n;i++){
                         ^
Main.java:103: error: class, interface, or enum expected
        cout << c;
        ^
Main.java:104: error: class, interface, or enum expected
    }
    ^
69 errors
stdout
Standard output is empty