답안 #584393

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
584393 2022-06-27T10:28:07 Z FatihSolak KOVANICE (COI15_kovanice) C++17
10 / 100
471 ms 21836 KB
#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++){
                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

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:57:31: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   57 |                 if(ord.size() == n){
      |                    ~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 7380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 288 ms 13120 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 9692 KB Output is correct
2 Correct 20 ms 9684 KB Output is correct
3 Correct 24 ms 9636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 471 ms 21836 KB Output isn't correct
2 Halted 0 ms 0 KB -