Submission #1121043

#TimeUsernameProblemLanguageResultExecution timeMemory
1121043raul2008487KOVANICE (COI15_kovanice)C++17
50 / 100
2058 ms22856 KiB
#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(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: In function 'void solve()':
kovanice.cpp:61:17: warning: unused variable 'j' [-Wunused-variable]
   61 |     ll m, v, i, j;
      |                 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...