답안 #975666

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
975666 2024-05-05T17:08:25 Z Error404 Love Polygon (BOI18_polygon) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define f first
#define s second
#define pi pair<int,int>

const int MAX = 2e5; 
    
    
int n;
map<string,int>m;
vector<int>g[MAX];
int love[MAX];
int indegree[MAX];
int visited[MAX];

int main(){
    int n;
    cin>> n;
    string  from, to;
    int k = 1;
    if(n%2){
        cout << -1 << endl;
        return 0;
    }
    int a,b;
    for(int i = 0; i < n; i++){
        cin >> from >> to;
    
        if(m[from]==0) {
           // cout << from << " " << k << endl;
            m[from]=k++;
        }
        if(m[to]==0){
           // cout << to << " " << k << endl;
            m[to]=k++;
        } 
        a = m[from], b= m[to];
        love[a]=b;
        if(love[b]==a && a!=b){
            visited[a]= visited[b]=1;
        }
        g[a].pb(b);
        indegree[b]++;
    }
    
    
    queue<int>q;
    for(int i = 1; i <= n; i++){
        if(indegree[i]==0 && visited[i]==0){
            q.push(i);
        }
    }
    ll ans = 0;
    while(!q.empty()){
        int from = q.front();
        q.pop();
     //   cout << from << " " << ans<< endl;
        for(int to : g[from]){
            indegree[to]--;
            if(!visited[to]){
                q.push(to);
                if(visited[from])continue;
                love[from]=to;
                ans++;
                visited[from]= visited[to] =1;
                
            }
        }
    }
    
    // ans /=2;
     
     
     
     for(int i = 1; i <= n; i++){
         if(!visited[i] &&!visited[love[i]]&& love[i]!=i && love[i]!=0) {
             ans++;
                visited[i]=1
                visited[love[i]]=1;
             
         }
     }
     for(int i = 1; i <= n; i++){
         if(!visited[i]) {
             ans++;
            
         }
     }
     
     cout << ans << endl;
     
     
    
    
}

Compilation message

polygon.cpp: In function 'int main()':
polygon.cpp:81:29: error: expected ';' before 'visited'
   81 |                 visited[i]=1
      |                             ^
      |                             ;
   82 |                 visited[love[i]]=1;
      |                 ~~~~~~~