QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#348503 | #7860. Graph of Maximum Degree 3 | chenxinyang2006# | RE | 2ms | 9172kb | C++14 | 1.9kb | 2024-03-09 19:04:31 | 2024-03-09 19:04:31 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define eb emplace_back
#define SZ(S) (int)S.size()
//#define mod 998244353
//#define mod 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f
using namespace std;
template <class T>
void chkmax(T &x,T y){
if(x < y) x = y;
}
template <class T>
void chkmin(T &x,T y){
if(x > y) x = y;
}
inline int popcnt(int x){
return __builtin_popcount(x);
}
inline int ctz(int x){
return __builtin_ctz(x);
}
/*ll power(ll p,int k = mod - 2){
ll ans = 1;
while(k){
if(k % 2 == 1) ans = ans * p % mod;
p = p * p % mod;
k /= 2;
}
return ans;
}*/
int n,m;
vector <int> G[2][100005];
int _u[100005],_v[100005],_c[100005];
int chk(int c,int u,int v){
int pos = lower_bound(G[c][u].begin(),G[c][u].end(),v) - G[c][u].begin();
if(pos < SZ(G[c][u]) && G[c][u][pos] == v) return 1;
return 0;
}
int main(){
// freopen("test.in","r",stdin);
scanf("%d%d",&n,&m);
rep(i,1,m){
scanf("%d%d%d",&_u[i],&_v[i],&_c[i]);
G[_c[i]][_u[i]].eb(_v[i]);
G[_c[i]][_v[i]].eb(_u[i]);
}
rep(u,1,n){
sort(G[0][u].begin(),G[0][u].end());
sort(G[1][u].begin(),G[1][u].end());
}
int ans = 0;
rep(u,1,n){
for(int v:G[0][u]) if(v < u) ans += chk(1,u,v);
for(int v:G[0][u]){
for(int w:G[0][u]){
if(v >= w) continue;
ans += (chk(1,u,v) + chk(1,u,w) + chk(1,v,w) >= 2);
}
}
}
rep(i,1,m){
if(_c[i]) continue;
for(int u:G[0][_u[i]]){
for(int v:G[0][_v[i]]){
if(u == v || u == _v[i] || v == _u[i]) continue;
ans += (chk(1,u,v) + chk(1,u,_v[i]) + chk(1,_u[i],v) == 3);
}
}
}
printf("%d\n",ans + n);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 8628kb
input:
3 4 1 2 0 1 3 1 2 3 0 2 3 1
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: 0
Accepted
time: 1ms
memory: 8536kb
input:
4 6 1 2 0 2 3 0 3 4 0 1 4 1 2 4 1 1 3 1
output:
5
result:
ok 1 number(s): "5"
Test #3:
score: 0
Accepted
time: 1ms
memory: 9172kb
input:
20 28 9 6 1 9 6 0 3 8 0 8 4 0 3 8 1 3 4 1 2 13 0 13 1 0 19 1 0 2 1 1 2 19 1 13 19 1 14 15 1 14 15 0 7 12 0 12 17 0 20 17 0 7 17 1 7 20 1 12 20 1 16 18 0 18 10 0 5 10 0 16 10 1 16 5 1 18 5 1 4 6 0 9 11 0
output:
27
result:
ok 1 number(s): "27"
Test #4:
score: 0
Accepted
time: 0ms
memory: 8496kb
input:
100 150 93 23 0 23 81 0 76 81 0 93 81 1 93 76 1 23 76 1 100 65 0 65 56 0 19 56 0 100 56 1 100 19 1 65 19 1 2 98 0 2 98 1 26 63 0 63 90 0 26 63 1 26 90 1 6 11 0 11 67 0 6 11 1 6 67 1 37 89 0 89 64 0 25 64 0 37 64 1 37 25 1 89 25 1 84 10 0 10 29 0 75 29 0 84 29 1 84 75 1 10 75 1 7 70 1 7 70 0 28 92 0 ...
output:
141
result:
ok 1 number(s): "141"
Test #5:
score: -100
Runtime Error
input:
100000 133680 36843 86625 0 86625 63051 0 35524 63051 0 36843 63051 1 36843 35524 1 86625 35524 1 55797 82715 0 55797 82715 1 70147 35104 0 35104 91732 0 70147 35104 1 70147 91732 1 94917 70395 0 70395 68250 0 24100 68250 0 94917 68250 1 94917 24100 1 70395 24100 1 83033 18450 1 83033 18450 0 34462 ...