답안 #1021868

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1021868 2024-07-13T06:31:06 Z guagua0407 Tug of War (BOI15_tug) C++17
23 / 100
16 ms 6952 KB
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};

void setIO(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}

vector<vector<int>> adj,adjr;
vector<bool> vis;
vector<int> ord;
vector<int> scc;

void dfs(int v){
    vis[v]=true;
    for(auto u:adj[v]){
        if(vis[u]) continue;
        dfs(u);
    }
    ord.push_back(v);
}

void dfs2(int v,int id){
    scc[v]=id;
    vis[v]=true;
    for(auto u:adjr[v]){
        if(vis[u]) continue;
        dfs2(u,id);
    }
}

void addedge(int a,int b){
    adj[a].push_back(b);
    adjr[b].push_back(a);
}

int main() {_
    int n,k;
    cin>>n>>k;
    vector<int> l(2*n),r(2*n),S(2*n);
    vector<vector<int>> ls(n),rs(n);
    for(int i=0;i<2*n;i++){
        cin>>l[i]>>r[i]>>S[i];
        l[i]--;
        r[i]--;
        ls[l[i]].push_back(i);
        rs[r[i]].push_back(i);
    }
    adj.resize(4*n),adjr.resize(4*n);
    vis.resize(4*n);
    scc.resize(4*n);
    for(int i=0;i<n;i++){
        if(ls[i].empty() or rs[i].empty()){
            cout<<"NO"<<'\n';
            return 0;
        }
        for(auto a:ls[i]){
            for(auto b:ls[i]){
                if(a!=b){
                    addedge(2*a,2*b+1);
                }
            }
        }
        for(auto a:rs[i]){
            for(auto b:rs[i]){
                if(a!=b){
                    addedge(2*a+1,2*b);
                }
            }
        }
    }
    for(int i=0;i<4*n;i++){
        if(!vis[i]){
            dfs(i);
        }
    }
    reverse(all(ord));
    fill(all(vis),false);
    int cnt=0;
    for(int i=0;i<4*n;i++){
        if(!vis[ord[i]]){
            dfs2(ord[i],cnt++);
        }
    }
    for(int i=0;i<2*n;i++){
        if(scc[i*2]==scc[i*2+1]){
            cout<<"NO"<<'\n';
            return 0;
        }
    }
    cout<<"YES"<<'\n';
    return 0;
}
//maybe its multiset not set
//yeeorz
//laborz

Compilation message

tug.cpp: In function 'void setIO(std::string)':
tug.cpp:15:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tug.cpp:16:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 6748 KB Output is correct
2 Correct 6 ms 4012 KB Output is correct
3 Correct 16 ms 6756 KB Output is correct
4 Correct 7 ms 3932 KB Output is correct
5 Correct 14 ms 6952 KB Output is correct
6 Correct 7 ms 3932 KB Output is correct
7 Correct 14 ms 6832 KB Output is correct
8 Correct 6 ms 3932 KB Output is correct
9 Correct 12 ms 6928 KB Output is correct
10 Correct 6 ms 3932 KB Output is correct
11 Correct 12 ms 6912 KB Output is correct
12 Correct 6 ms 3932 KB Output is correct
13 Correct 11 ms 6748 KB Output is correct
14 Correct 15 ms 6748 KB Output is correct
15 Correct 6 ms 3932 KB Output is correct
16 Correct 13 ms 6896 KB Output is correct
17 Correct 6 ms 3932 KB Output is correct
18 Correct 14 ms 6832 KB Output is correct
19 Correct 6 ms 3980 KB Output is correct
20 Correct 12 ms 6748 KB Output is correct
21 Correct 6 ms 3836 KB Output is correct
22 Correct 13 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -