Submission #3423264
Source Code Expand
#include<cstdio> #include<iostream> #include<algorithm> #include<vector> #include<string> #include<cstdlib> #include<cmath> #include<cstring> #include<set> #include<map> #include<queue> using namespace std; #define rep(i,n) for(int (i)=0;(i)<(n);++i) #define rrep(i,n) for(int (i)=(n)-1;(i)>=0;--i) #define rep1(i,n) for(int (i)=1;(i)<=(n);++i) #define rrep1(i,n) for(int (i)=(n);(i)>=1;--i) #define pb push_back #define fr first #define sc second typedef long long ll; typedef pair<int,int> P; typedef pair<long long,long long> LP; typedef double db; using namespace std; ll N,M; ll A[100000],B[100000]; int X[100000]; vector<ll> vs[100000]; ll C[2]; bool dfs(int v,int p,int val){ if(X[v] == -1){ X[v]=val; C[val]++; rep(i,vs[v].size()){ if(p == vs[v][i]) continue; if( dfs(vs[v][i], v, !val ) ) return 1; } } else if(X[v] != val){ return 1; } return 0; } int main() { cin>>N>>M; rep(i,M){ cin>>A[i]>>B[i]; A[i]--; B[i]--; vs[A[i]].pb(B[i]); vs[B[i]].pb(A[i]); } memset(X,-1,sizeof(X)); if(dfs(0,-1,0)){ cout << (N*(N-1)/2)-M<<endl; } else{ cout<< C[0]*C[1]-M<<endl; } }
Submission Info
Submission Time | |
---|---|
Task | C - 3 Steps |
User | miyajiro |
Language | C++14 (GCC 5.4.1) |
Score | 500 |
Code Size | 1226 Byte |
Status | AC |
Exec Time | 78 ms |
Memory | 8704 KB |
Judge Result
Set Name | sample | all | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 500 / 500 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
sample | sample-01.txt, sample-02.txt |
all | sample-01.txt, sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, 02-10.txt, 02-11.txt, 02-12.txt, 02-13.txt, 02-14.txt, sample-01.txt, sample-02.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01-01.txt | AC | 2 ms | 4352 KB |
01-02.txt | AC | 3 ms | 4352 KB |
01-03.txt | AC | 2 ms | 4352 KB |
01-04.txt | AC | 2 ms | 4352 KB |
01-05.txt | AC | 2 ms | 4352 KB |
01-06.txt | AC | 3 ms | 4352 KB |
01-07.txt | AC | 2 ms | 4352 KB |
01-08.txt | AC | 2 ms | 4352 KB |
01-09.txt | AC | 3 ms | 4352 KB |
01-10.txt | AC | 4 ms | 4480 KB |
02-01.txt | AC | 72 ms | 8064 KB |
02-02.txt | AC | 75 ms | 8192 KB |
02-03.txt | AC | 75 ms | 8192 KB |
02-04.txt | AC | 78 ms | 8192 KB |
02-05.txt | AC | 78 ms | 8192 KB |
02-06.txt | AC | 75 ms | 8192 KB |
02-07.txt | AC | 72 ms | 7808 KB |
02-08.txt | AC | 73 ms | 8192 KB |
02-09.txt | AC | 74 ms | 8192 KB |
02-10.txt | AC | 46 ms | 7296 KB |
02-11.txt | AC | 59 ms | 7552 KB |
02-12.txt | AC | 74 ms | 8576 KB |
02-13.txt | AC | 73 ms | 8320 KB |
02-14.txt | AC | 77 ms | 8704 KB |
sample-01.txt | AC | 3 ms | 4352 KB |
sample-02.txt | AC | 3 ms | 4352 KB |