QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#261554#7755. Game on a ForestSSHWA 8ms28784kbC++172.7kb2023-11-22 23:27:412023-11-22 23:27:42

Judging History

你现在查看的是最新测评结果

  • [2023-11-22 23:27:42]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:28784kb
  • [2023-11-22 23:27:41]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;
void solve();
signed main(){
    cin.sync_with_stdio(0);
    cin.tie(0);
    int T = 1;
    //cin >> T;
    while(T--){
        solve();
    }
    return 0;
}
#define N 1001000
vector<int> g[N];
int idx = 0, vis[N];
bool dfs(int u, int f){
    if(vis[u] == 1)return true;
    vis[u] = 1;
    for(int v:g[u]){
        if(v != f)
        if(dfs(v, u))return true;
    }
    return false;
}
void solve(){
    int n, m, k;
    cin >> n >> m >> k;
    swap(n, m);
    map<int,vector<pair<int,int>>> mp;
    for(int i = 0;i < k;i++){
        int x1, x2, y;
        cin >> x1 >> x2 >> y;
        mp[y].push_back({x1, x2});
    }
    if(n == 1 || m == 1){
        cout << "YES\n";
        return;
    }
    int ed = 0;
    for(auto& [y,v]:mp){
        if(y - ed > 2){
            cout << "NO\n";
            return;
        }
        ed = y;
        sort(v.begin(), v.end());
    }
    if(n + 1 - ed > 2){
        cout << "NO\n";
        return;
    }
    map<int,vector<array<int,4>>> mp2;
    for(int i = 1;i <= n;i++){
        if(mp.count(i) == false){
            mp2[i].push_back({1, m, i, ++idx});
        }
        else{
            int r = 1;
            for(auto [x1, x2]:mp[i]){
                if(x1 - 1 >= r){
                    mp2[i].push_back({r, x1 - 1, i, ++idx});
                }
                r = x2 + 1;
            }
            if(m >= r){
                mp2[i].push_back({r, m, i, ++idx});
            }
        }
    }
    for(auto [y, v1]:mp2){
        if(mp2.count(y + 1)){
            auto v2 = mp2[y + 1];
            int z1 = v1.size();
            int z2 = v2.size();
            int p1 = 0, p2 = 0;
            while(p1 < z1 && p2 < z2){
                int l = max(v1[p1][0], v2[p2][0]);
                int r = min(v1[p1][1], v2[p2][1]);
                if(l <= r){
                    g[v1[p1][3]].push_back(v2[p2][3]);
                    g[v2[p2][3]].push_back(v1[p1][3]);
                    //cout<< v1[p1][0] << " " << v1[p1][1] << " " << v1[p1][2] << " " << v1[p1][3] << "\n";
                    //cout<< v2[p2][0] << " " << v2[p2][1] << " " << v2[p2][2] << " " << v2[p2][3] << "\n";
                }
                if(l < r){
                    g[v1[p1][3]].push_back(v2[p2][3]);
                    g[v2[p2][3]].push_back(v1[p1][3]);
                    cout << "NO\n";
                    return;
                }
                if(v1[p1][1] < v2[p2][1]){
                    p1++;
                }
                else{
                    p2++;
                }
            }
        }
    }
    if(dfs(idx, 0)){
        cout << "NO\n";
    }
    else{
        cout << "YES\n";
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 8ms
memory: 28784kb

input:

3 1
1 2

output:

YES

result:

wrong output format Expected integer, but "YES" found