QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#5045 | #460. Colored Graph | zombie462 | 0 | 455ms | 37268kb | C++ | 1.7kb | 2020-10-20 16:36:43 | 2021-12-19 05:48:16 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=500010;
map <pair <int,int>,int> mp;
set <int> S,T;
int A,B,C,f[N];
pair <int,int> ans[N];
bool check(int x,int y){
return (A*min(x,y)+B*max(x,y))%C>=f[x]+f[y];
}
int query(int x,int y){
if (x>y) swap(x,y);
return mp.count(make_pair(x,y))?mp[make_pair(x,y)]:check(x,y);
}
int getpre(int x){
set <int>::iterator itList=S.lower_bound(x);
if (itList==S.begin()) itList=S.end();
return *--itList;
}
int getnxt(int x){
set <int>::iterator itList=S.upper_bound(x);
if (itList==S.end()) itList=S.begin();
return *itList;
}
void modify(int x){
int pre=getpre(x),nxt=getnxt(x);
if (query(x,pre)!=query(x,nxt)) T.insert(x);
else if (T.find(x)!=T.end()) T.erase(x);
}
int read(){
int x=0,f=1;
char ch=getchar();
while (ch<'0' || ch>'9'){
if (ch=='-') f=-f;
ch=getchar();
}
while (ch>='0' && ch<='9'){
x=x*10+ch-48;
ch=getchar();
}
return x*f;
}
int solve(){
if (T.empty()){
set <int>::iterator itList1=S.begin(),itList2=itList1;
int col=query(*itList1,*++itList2);
for (;itList2!=S.end();itList1=itList2++){
printf("%lld %lld\n",*itList1,*itList2);
}
return col;
}
int x=*T.begin(),pre=getpre(x),nxt=getnxt(x);
int col=query(x,pre);
S.erase(x);T.erase(T.begin());modify(pre);modify(nxt);
int newcol=solve();
printf("%lld %lld\n",x,col=newcol?pre:nxt);
return newcol;
}
signed main(){
int n=read(),m=read();
for (int i=1;i<=m;++i){
int x=read(),y=read();
if (x>y) swap(x,y);
mp[make_pair(x,y)]=read();
}
A=read(),B=read(),C=read();
for (int i=1;i<=n;++i) f[i]=read();
for (int i=1;i<=n;++i) S.insert(i);
for (int i=1;i<=n;++i) modify(i);
solve();
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 455ms
memory: 37268kb
input:
439947 70564 261418 81226 0 391157 185738 1 291864 124280 1 224287 253065 0 254187 331805 1 93992 112583 0 3774 31281 1 413605 291199 1 123118 278877 0 383287 374927 0 219696 430048 1 374944 272292 0 156453 15904 0 13652 163529 1 291676 57172 1 268448 195409 0 242654 300684 1 174795 208807 1 216759 123623 1 254209 264578 1 407424 172906 0 21164 297845 1 111755 149875 1 203860 424465 1 275710 160996 0 365668 371841 0 429822 241152 0 275198 109336 1 66424 251337 0 113416 5400 0 297211 370277 1 169...
output:
1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 52 52 53 53 54 54 55 55 56 56 57 57 58 58 59 59 60 60 61 61 62 62 63 63 64 64 65 65 66 66 67 67 68 68 69 69 70 70 71 71 72 72 73 73 74 74 75 75 76 76 77 77 78 78 79 79 80 80 81 81 82 82 84 84 85 85 86 86 87 87 88 88 89 89 90 90 91 9...
result:
FAIL Your edges have different colors on #410358(439946, 439947)