QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#356620 | #6560. Broken Minimum Spanning Tree | kevinshan | Compile Error | / | / | C++17 | 2.4kb | 2024-03-18 05:01:31 | 2024-03-18 05:01:31 |
Judging History
answer
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define ps push
#define in insert
#define f first
#define s second
#define nl cout<<"\n"
#define ca(v) for(auto i:v) cout<<i<<" ";
#define cbit(x) __builtin_popcount(x)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a*b/gcd(a, b))
const int xm[4] = {-1, 1, 0, 0};
const int ym[4] = {0, 0, -1, 1};
const int MOD = 1e9 + 7;
const int MAXN = 2e3 + 5;
const ll POW = 9973;
struct ed {
int u, v, w, id;
friend bool operator<(ed a, ed b) {
return a.w < b.w;
}
};
vector<ed> adj[MAXN];
vector<ed> path;
bool dfs(int x, int p, int g) {
if(x == g) return 1;
for(auto e:adj[x]) {
int a = e.u;
if(a == x) a = e.v;
if(a == p) continue;
path.pb(e);
if(dfs(a,x,g)) return 1;
path.pop_back();
}
return 0;
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
if (fopen("input.in", "r")) {
freopen("input.in", "r", stdin);
freopen("output.out", "w", stdout);
}
int n, m;
cin>>n>>m;
vector<ed> eds;
vector<ed> ord;
set<int> active;
for(int i=0; i<m; i++) {
int u, v, w;
cin>>u>>v>>w;
u--; v--;
eds.pb({u,v,w,i});
ord.pb(eds.back());
}
for(int i=0; i<n-1; i++) active.in(i);
vector<pair<int, int>> res;
sort(all(ord));
for(auto e:ord) {
if(e.id < n-1) continue;
for(int i=0; i<m; i++){
if(active.find(i) != active.end()) {
adj[eds[i].v].pb(eds[i]);
adj[eds[i].u].pb(eds[i]);
}
}
dfs(e.u, -1, e.v);
sort(all(path));
if(path.back().w > e.w) {
res.pb({path.back().id, e.id});
if(active.find(path.back().id) == active.end()) return 0;
assert(active.find(path.back().id) != active.end());
active.erase(active.find(path.back().id));
active.insert(e.id);
}
for(int i=0; i<n; i++) adj[i].clear();
path.clear();
}
cout<<res.size()<<"\n";
for(auto p:res) cout<<p.f+1<<" "<<p.s+1<<"\n";
}
詳細信息
answer.code: In function ‘int main()’: answer.code:53:16: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 53 | freopen("input.in", "r", stdin); | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~ answer.code:54:16: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 54 | freopen("output.out", "w", stdout); | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/13/string:43, from /usr/include/c++/13/bitset:52, from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:52, from answer.code:4: /usr/include/c++/13/bits/allocator.h: In destructor ‘std::_Vector_base<ed, std::allocator<ed> >::_Vector_impl::~_Vector_impl()’: /usr/include/c++/13/bits/allocator.h:184:7: error: inlining failed in call to ‘always_inline’ ‘std::allocator< <template-parameter-1-1> >::~allocator() noexcept [with _Tp = ed]’: target specific option mismatch 184 | ~allocator() _GLIBCXX_NOTHROW { } | ^ In file included from /usr/include/c++/13/vector:66, from /usr/include/c++/13/functional:64, from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:53: /usr/include/c++/13/bits/stl_vector.h:133:14: note: called from here 133 | struct _Vector_impl | ^~~~~~~~~~~~