Submission #1121049

#TimeUsernameProblemLanguageResultExecution timeMemory
1121049vjudge1KOVANICE (COI15_kovanice)C++17
Compilation error
0 ms0 KiB
1#include<bits/stdc++.h>

#define ll long long
#define pb push_back
#define in insert
#define fi first
#define se second
#define vl vector<ll>
#define all(v) v.begin(), v.end()
#define endl "\n"

using namespace std;
const int sz = 3e5 + 5; /// mind this
const int MAX = 2e6 + 123;
const int BS = 61;
const int mod = 998244353;
struct DSU
{
    vector<int> e;
    void init(int n)
    {
        e.assign(n + 1, -1);
    }
    int get(int x)
    {
        if (e[x] < 0) return x;
        return e[x] = get(e[x]);
    }
    bool unite(int x, int y)
    {
        x = get(x);
        y = get(y);
        if (x == y) return false;
        if (e[x] > e[y]) swap(x, y);
        e[x] += e[y];
        e[y] = x;
        return true;
    }
};
vl e[sz];
ll dp[sz], ans[sz], n;
void dfs(ll node){
    dp[node] = 1;
    for(auto to: e[node]){
        if(!dp[to]){
            dfs(to);
        }
        dp[node] = max(dp[node], dp[to] + 1);
    }
}
void dfs2(ll node){
    ans[node] = n - dp[node] + 1;
    for(auto to: e[node]){
        if((!ans[to]) && dp[to] == dp[node] - 1){
            dfs2(to);
        }
    }
}
void solve(){
    DSU dsu;
    ll m, v, i, j;
    cin >> n >> m >> v;
    vector<char> comp(v);
    vl x(v), y(v);
    dsu.init(m);
    for(i = 0; i < v; i++){
        cin >> x[i] >> comp[i] >> y[i];
        if(comp[i] == '='){
            dsu.unite(x[i], y[i]);
        }
    }
    for(i = 0; i < v; i++){
        if(comp[i] == '<'){
            e[dsu.get(x[i])].pb(dsu.get(y[i]));
        }
    }
    for(i = 1; i <= m; i++){
        if(!dp[i]){
            dfs(i);
        }
    }
    for(i = 1; i <= m; i++){
        if(dp[i] == n && dsu.e[i] < 0){
            dfs2(i);
        }
    }
    for(i = 1; i <= m; i++){
        if(!ans[dsu.get(i)]){
            cout << '?';
        }
        else{
            cout << 'K' << ans[dsu.get(i)];
        }
        cout << endl;
    }

}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}

/*
3 5 3
1<2
2<4
3=5
*/

Compilation message (stderr)

kovanice.cpp:1:2: error: stray '#' in program
    1 | 1#include<bits/stdc++.h>
      |  ^
kovanice.cpp:1:1: error: expected unqualified-id before numeric constant
    1 | 1#include<bits/stdc++.h>
      | ^
kovanice.cpp:19:5: error: 'vector' does not name a type
   19 |     vector<int> e;
      |     ^~~~~~
kovanice.cpp: In member function 'void DSU::init(int)':
kovanice.cpp:22:9: error: 'e' was not declared in this scope
   22 |         e.assign(n + 1, -1);
      |         ^
kovanice.cpp: In member function 'int DSU::get(int)':
kovanice.cpp:26:13: error: 'e' was not declared in this scope
   26 |         if (e[x] < 0) return x;
      |             ^
kovanice.cpp:27:16: error: 'e' was not declared in this scope
   27 |         return e[x] = get(e[x]);
      |                ^
kovanice.cpp: In member function 'bool DSU::unite(int, int)':
kovanice.cpp:34:13: error: 'e' was not declared in this scope
   34 |         if (e[x] > e[y]) swap(x, y);
      |             ^
kovanice.cpp:34:26: error: 'swap' was not declared in this scope
   34 |         if (e[x] > e[y]) swap(x, y);
      |                          ^~~~
kovanice.cpp:35:9: error: 'e' was not declared in this scope
   35 |         e[x] += e[y];
      |         ^
kovanice.cpp: At global scope:
kovanice.cpp:8:12: error: 'vector' does not name a type
    8 | #define vl vector<ll>
      |            ^~~~~~
kovanice.cpp:40:1: note: in expansion of macro 'vl'
   40 | vl e[sz];
      | ^~
kovanice.cpp: In function 'void dfs(long long int)':
kovanice.cpp:44:18: error: 'e' was not declared in this scope
   44 |     for(auto to: e[node]){
      |                  ^
kovanice.cpp:48:20: error: 'max' was not declared in this scope
   48 |         dp[node] = max(dp[node], dp[to] + 1);
      |                    ^~~
kovanice.cpp: In function 'void dfs2(long long int)':
kovanice.cpp:53:18: error: 'e' was not declared in this scope
   53 |     for(auto to: e[node]){
      |                  ^
kovanice.cpp: In function 'void solve()':
kovanice.cpp:62:5: error: 'cin' was not declared in this scope; did you mean 'in'?
   62 |     cin >> n >> m >> v;
      |     ^~~
      |     in
kovanice.cpp:63:5: error: 'vector' was not declared in this scope
   63 |     vector<char> comp(v);
      |     ^~~~~~
kovanice.cpp:63:12: error: expected primary-expression before 'char'
   63 |     vector<char> comp(v);
      |            ^~~~
kovanice.cpp:3:12: error: expected primary-expression before 'long'
    3 | #define ll long long
      |            ^~~~
kovanice.cpp:8:19: note: in expansion of macro 'll'
    8 | #define vl vector<ll>
      |                   ^~
kovanice.cpp:64:5: note: in expansion of macro 'vl'
   64 |     vl x(v), y(v);
      |     ^~
kovanice.cpp:67:16: error: 'x' was not declared in this scope
   67 |         cin >> x[i] >> comp[i] >> y[i];
      |                ^
kovanice.cpp:67:24: error: 'comp' was not declared in this scope
   67 |         cin >> x[i] >> comp[i] >> y[i];
      |                        ^~~~
kovanice.cpp:67:35: error: 'y' was not declared in this scope
   67 |         cin >> x[i] >> comp[i] >> y[i];
      |                                   ^
kovanice.cpp:73:12: error: 'comp' was not declared in this scope
   73 |         if(comp[i] == '<'){
      |            ^~~~
kovanice.cpp:74:13: error: 'e' was not declared in this scope
   74 |             e[dsu.get(x[i])].pb(dsu.get(y[i]));
      |             ^
kovanice.cpp:74:23: error: 'x' was not declared in this scope
   74 |             e[dsu.get(x[i])].pb(dsu.get(y[i]));
      |                       ^
kovanice.cpp:74:41: error: 'y' was not declared in this scope
   74 |             e[dsu.get(x[i])].pb(dsu.get(y[i]));
      |                                         ^
kovanice.cpp:83:30: error: 'struct DSU' has no member named 'e'
   83 |         if(dp[i] == n && dsu.e[i] < 0){
      |                              ^
kovanice.cpp:89:13: error: 'cout' was not declared in this scope
   89 |             cout << '?';
      |             ^~~~
kovanice.cpp:92:13: error: 'cout' was not declared in this scope
   92 |             cout << 'K' << ans[dsu.get(i)];
      |             ^~~~
kovanice.cpp:94:9: error: 'cout' was not declared in this scope
   94 |         cout << endl;
      |         ^~~~
kovanice.cpp:61:17: warning: unused variable 'j' [-Wunused-variable]
   61 |     ll m, v, i, j;
      |                 ^
kovanice.cpp: In function 'int main()':
kovanice.cpp:99:5: error: 'ios_base' has not been declared
   99 |     ios_base::sync_with_stdio(false);
      |     ^~~~~~~~
kovanice.cpp:100:5: error: 'cin' was not declared in this scope; did you mean 'in'?
  100 |     cin.tie(0);
      |     ^~~
      |     in
kovanice.cpp:101:5: error: 'cout' was not declared in this scope
  101 |     cout.tie(0);
      |     ^~~~