Submission #584394

#TimeUsernameProblemLanguageResultExecution timeMemory
584394FatihSolakKOVANICE (COI15_kovanice)C++17
10 / 100
2072 ms17520 KiB
#include <bits/stdc++.h> #define N 300005 using namespace std; int par[N]; int find(int a){ if(a == par[a])return a; return par[a] = find(par[a]); } bool merge(int a,int b){ a = find(a); b = find(b); if(a == b)return 0; par[a] = b; return 1; } vector<int> adj[N]; int a[N],b[N]; char c[N]; bool ok[N]; bool vis[N]; int ans[N]; vector<int> ord; void dfs(int v){ vis[v] = 1; for(auto u:adj[v]){ if(vis[u])continue; dfs(u); } ord.push_back(v); } void solve(){ int n,m,v; cin >> n >> m >> v; for(int i = 1;i<=m;i++){ par[i] = i; ok[i] = 1; ans[i] = -1; } for(int i = 1;i<=v;i++){ cin >> a[i] >> c[i] >> b[i]; if(c[i] == '=') merge(a[i],b[i]); } for(int i = 1;i<=v;i++){ a[i] = find(a[i]); b[i] = find(b[i]); if(c[i] == '<'){ ok[a[i]] = 0; adj[b[i]].push_back(a[i]); } } for(int i = 1;i<=m;i++){ if(ok[i] && i == find(i)){ ord.clear(); dfs(i); for(int j = 0;j<ord.size();j++){ vis[ord[j]] = 0; if(ord.size() == n){ ans[ord[j]] = j+1; } } } } for(int i = 1;i<=m;i++){ if(ans[find(i)] == -1){ cout << "?" << endl; } else cout << "K" << ans[find(i)] << endl; } } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); #ifdef Local freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif int t = 1; //cin >> t; while(t--){ solve(); } #ifdef Local cout << endl << fixed << setprecision(2) << 1000.0*clock()/CLOCKS_PER_SEC << " milliseconds."; #endif }

Compilation message (stderr)

kovanice.cpp: In function 'void solve()':
kovanice.cpp:56:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |             for(int j = 0;j<ord.size();j++){
      |                           ~^~~~~~~~~~~
kovanice.cpp:58:31: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   58 |                 if(ord.size() == n){
      |                    ~~~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...