QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#122424#4635. Graph Operationtraining4usacoWA 1ms3400kbC++144.3kb2023-07-10 14:43:102023-07-10 14:43:13

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-10 14:43:13]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3400kb
  • [2023-07-10 14:43:10]
  • 提交

answer

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
 
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
 
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
 
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
 
#define int long long
using namespace std;

const int MAXN = 1e3 + 5;
const int INF = 1e18 + 7;

int n, m;
int indeg1[MAXN];
int indeg2[MAXN];
bitset<MAXN> adj1[MAXN], adj2[MAXN];
bitset<MAXN> bs;
vector<tuple<int, int, int, int>> ans;
vector<tuple<int, int, int, int>> ans2;

signed main() {
    cin >> n >> m;
    for(int i = 1; i <= m; ++i) {
        int a, b; cin >> a >> b;

        adj1[a][b] = adj1[b][a] = 1;
        ++indeg1[a]; ++indeg1[b];
    }
    for(int i = 1; i <= m; ++i) {
        int a, b; cin >> a >> b;
        
        adj2[a][b] = adj2[b][a] = 1;
        ++indeg2[a]; ++indeg2[b];
    }
    
    for(int i = 1; i <= n; ++i) {
        if(indeg1[i] != indeg2[i]) {
            cout << "-1\n"; return 0;
        }
    }
    
    // cout << "hello" << endl;
    
    for(int u = 1; u <= n; ++u) {
        if(adj1[u].count() == 0) continue;
        
        // find nodes that are adjacent in 1st but not 2nd
        vector<int> ina, inb; 
        ina.push_back(0); inb.push_back(0);
        for(int v = u + 1; v <= n; ++v) {
            if(adj1[u][v] && !adj2[u][v]) ina.push_back(v);
            if(!adj1[u][v] && adj2[u][v]) inb.push_back(v);
        }
        
        for(int i = 1; i <= ina.size(); ++i) {
            int v = ina[i], w = inb[i];
            adj1[v].flip();
            bs = adj1[v] & adj1[w];
            adj1[v].flip();
            bs[v] = 0;
            
            if(bs.count()) {
                int t = bs._Find_first();
                adj1[u][v] = adj1[v][u] = adj1[w][t] = adj1[t][w] = 0;
                adj1[u][w] = adj1[w][u] = adj1[v][t] = adj1[t][v] = 1;
                ans.push_back(tie(u, v, w, t));
            }
            else {
                adj2[w].flip();
                bs = adj2[v] & adj2[w];
                adj2[w].flip();
                bs[w] = 0;
                
                int t = bs._Find_first();
                adj2[u][w] = adj2[w][u] = adj2[v][t] = adj2[t][v] = 0;
                adj1[u][v] = adj1[v][u] = adj1[w][t] = adj1[t][w] = 1;
                ans2.push_back(tie(u, v, w, t));
            }
        }
        
        for(int v = u + 1; v <= n; ++v) {
            adj1[u][v] = adj1[v][u] = adj2[u][v] = adj2[v][u];
        }
    }
    
    cout << ans.size() + ans2.size() << endl;
    reverse(ans2.begin(), ans2.end());
    int a, b, c, d;
    for(auto v : ans) {
        tie(a, b, c, d) = v; cout << a << " " << b << " " << c << " " << d << endl;
    } 
    for(auto v : ans2) {
        tie(a, b, c, d) = v; cout << a << " " << b << " " << c << " " << d << endl;
    } 
    
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3400kb

input:

4 2
1 2
3 4
1 3
2 4

output:

5
1 2 3 4
1 0 0 1
2 0 0 2
3 0 0 3
4 0 0 4

result:

wrong answer Integer parameter [name=b] equals to 0, violates the range [1, 4]