Submission #846226

#TimeUsernameProblemLanguageResultExecution timeMemory
846226vjudge1KOVANICE (COI15_kovanice)C++17
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> #define int long long int #define MP make_pair #define pb push_back #define REP(i,n) for(int (i) = 0; (i) < (n); (i)++) using namespace std; const double EPS = 0.00001; const int INF = 1e9+500; const int MOD = 1e9+7; const int N = 3e5+5; const int K = 1505; const int ALPH = 26; int n,m,q,v; vector<vector<int> > adj; vector<int> topo; vector<int> nodes, is_rep; vector<int> vis; vector<int> depths; vector<array<int,2> > dsrt; vector<int> res; void fastio() { ios_base::sync_with_stdio(false); cin.tie(NULL); } struct DSU { vector<int> p, sz; DSU(int num) { p.resize(num+1); sz.resize(num+1); } void make_set(int x) { p[x] = x; sz[x] = 1; } int find_set(int x) { if(p[x] == x) return x; return p[x] = find_set(p[x]); } void union_set(int x, int y) { x = find_set(x); y = find_set(y); if(x == y) return; if(sz[x] < sz[y]) swap(x,y); p[y] = x; sz[x] += sz[y]; } }; void dfs(int node) { vis[node] = 1; for(auto c : adj[node]) { if(vis[c]) continue; dfs(c); } topo.pb(node); } void topos() { vis.resize(m+1, 0); for(auto i : nodes) { if(vis[i]) continue; dfs(i); } reverse(topo.begin(), topo.end()); } void find_depths() { for(auto i : topo) { depths[i] = max(depths[i] , 0ll); for(auto c : adj[i]) { depths[c] = max(depths[c] , depths[i] + 1); } } for(int i = 1; i<m+1; i++) { if(depths[i] == -1) continue; dsrt.pb({depths[i], i}); } sort(dsrt.begin(), dsrt.end()); } vector<array<int,2> > eqs, ineqs; void solve() { cin>>n>>m>>v; for(int i = 0; i<v; i++) { int a,b; char op; cin>>a; cin>>op; cin>>b; if(op == '<') { ineqs.pb({a,b}); } else if(op == '=') { eqs.pb({a,b}); } else assert(0); } topo.resize(m+1); DSU ds(m+1); adj.resize(m+1); is_rep.resize(m+1, 0); for(int i = 1; i<=m; i++) { ds.make_set(i); } for(int i = 0; i<eqs.size(); i++) { ds.union_set(eqs[i][0], eqs[i][1]); } for(int i = 1; i<=m; i++) { is_rep[ds.find_set(i)] = 1; } for(int i = 1; i<=m; i++) { if(is_rep[i]) { nodes.pb(i); } } for(auto ind : ineqs) { adj[ds.find_set(ind[1])].pb(ds.find_set(ind[0])); } topos(); depths.resize(m+1, -1); find_depths(); res.resize(m+1,0); for(int i = dsrt.size() - 1; i >= 0; i--) { if(dsrt[i][0] == n-1) { res[dsrt[i][1]] = n; continue; } for(auto c : adj[dsrt[i][1]]) { if(res[c]) { res[dsrt[i][1]] = dsrt[i][0] + 1; } } } for(int i = 1; i<=m; i++) { int rep = ds.find_set(i); if(res[rep] == 0) { cout<<"?\n"; continue; } cout<<"K"<<n - res[rep] + 1<<"\n"; } } signed main() { assert(0); fastio(); int test = 1; //cin>>test; while(test--) { solve(); } }

Compilation message (stderr)

kovanice.cpp: In function 'void solve()':
kovanice.cpp:115:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  115 |     for(int i = 0; i<eqs.size(); i++) {
      |                    ~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...