답안 #643111

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
643111 2022-09-21T08:37:12 Z mahatma_muhammad Love Polygon (BOI18_polygon) C++14
25 / 100
2000 ms 17696 KB
#include <bits/stdc++.h>
#include <math.h>
//in the name of god,aka allah
//**gray sety orz**
using namespace std;
#define pi pair<long long , long long>
#define pii pair<long long , pair<long long , long long>>
const int maxm = 5e5;
const long long mod = 1e9 + 7 ;
typedef long long ll;
ll l,r,mid;
ll n,m;
ll darage[maxm] , ss , mm;
queue<int> q;
bool vis[maxm];
ll pedaret[maxm];
set<string> st;
ll rp[maxm];
map<string,ll> mp;
inline void bfs(){
    mid = 0;
    while(!q.empty()){
        int u = q.front(); q.pop();
        mid++; vis[u] = 1;
        if(!vis[pedaret[u]]){           
            if(--darage[pedaret[pedaret[u]]] == 0 && !vis[pedaret[pedaret[u]]]) q.push(pedaret[pedaret[u]]);
            vis[pedaret[u]] = 1;
        }
    }
}
int pe(string s){
    if(st.find(s)==st.end()) mp.insert({s,mp.size()}) , st.insert(s);
    return mp[s];
}
int main() {
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n;
    if(n%2) return cout<<-1,0; 
    for(int i = 0; i<n; i++){
        string s,t;
        cin>>s>>t;
        l=pe(s);
        r=pe(t);
        pedaret[l]=r;
        darage[r]++;
    }
    for(int i=0; i<n; i++) if(pedaret[pedaret[i]]==i && pedaret[i]!=i) vis[i] = 1,vis[pedaret[i]] = 1;
    for(int i = 0; i<n; i++) if(darage[i]==0&&vis[i]==0) q.push(i);
    for(int i=0; i<n; i++){
        if(!vis[i]){
            r=1;
            vis[i]=1;
            int j = pedaret[i]; 
            while(j!=i){ vis[j] = 1, j = pedaret[j], r++;}
            mid+=(r+1)/2;
        }
    }
 
    cout<<mid;
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2083 ms 340 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 464 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 233 ms 17652 KB Output is correct
5 Correct 249 ms 17696 KB Output is correct
6 Correct 236 ms 17604 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2086 ms 17636 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2083 ms 340 KB Time limit exceeded
2 Halted 0 ms 0 KB -